Authentication for your PHP App using ASP.Net – Part 1

January 5, 2010 16:05 by nahas

First off, let me start off wishing you all a fabulous year ahead in 2010.  I wish you all prosperity and success in the coming year.

We had travelled across 3 cities (Chennai, Pune and Bangalore), in December 09 on a road show titled “Microsoft Interop Days”. We were quite overwhelmed with the response we had received and we look forward to seeing you all in our next trip. If some of you could not make it to the event, please do register with us on Area91.in so that we can inform you about our future events and Webcasts. 

On the sessions we had showcased at the event, was the capability of integrating ASP.Net authentication / Authorization for your existing PHP app hosted on IIS. We’ve seen a a lot of interest around this topic and have received numerous requests asking details around this. So I thought I’d share a step-by-step instruction, in a series of blog posts, as it might be too daunting to cover the whole thing in a single post.

To start with lets chart out a task list with the set of activities we need to do to achieve the above

1. Setup the platform

To begin with, we will need to setup the environment with IIS and configure it to host PHP apps. There are multiple ways to achieve this. However, the simplest way to achieve this is through a tool called the Web Platform Installer (WebPI) – a free tool that makes getting the latest components of the Microsoft Web Platform - Internet Information Services (IIS), PHP Support, SQL Server Express, .NET Framework, easy. The Web PI also makes it easy to install and run the most popular free web applications for blogging, content management and more with the built-in Windows Web Application Gallery.

2. Setup Authentication model

a. The next step would be to setup an Authentication model for your application where you would define authentication mode (Basic authentication / Form authentication etc.)

b. You will then define access rules so as to Allow / Deny access to various areas within your website.

3. Setup Authorization rules

a. Now that your authentication model is defined for your site, you will need to create / manage user accounts.

b. You will then need to setup a login page and authenticate the user against the credentials provided, to provide access to the app.

c. In most cases, you will also need to define roles in your application so that you can manage access privileges based on roles.

d. We will also add a feature for self-registration on our application, where visitors to the app can register on the site and create a user account for themselves. 

4. Control access (Optional)

a. The final stage would be to provide access to a specific section of the application based on the role that the user belongs to. The key objective of this is to show the ease of using the membership APIs to similar tasks.

I will target to address one of theses in each blog post.. so in about 4 posts I think I should get done :-)

 

Setup the platform

There are multiple ways to setup you platform to configure your windows environment to be able to host PHP applications. The simplest approach is to use Web Platform Installer (WebPI) available on the Microsoft site. I have attempted to make this very detailed and so please expect a long post. Some of you might already be familiar with some of the steps, in which case, just jump the section of your interest :-). The assumption here is that you are starting off with a base machine with none of the components installed and your machine is connected to the internet.

We will need to start off with the WebPI tool and so download the free tool from the above site and when you run it, you will be presented with the following screen below.

WPI1

Click on the Web Platform Tab and select Customize from the Frameworks and Runtime section

WPI2

WPI4

In this exercise, since we are leveraging some features of of ASP.Net with PHP apps, we will require ASP.Net components as well as the PHP runtime to be installed on the server. Select these two check boxes and click on Install. The installation process will connect to the internet and download the necessary bits to configure your machine with Internet Information Server (IIS), PHP runtime and ASP.Net.

To test if the IIS server is configured for PHP app, you could create a website and host a .php file. Open the IIS console – or just run inetmgr in the Start –> Run window. Expand the folder structure, right-click on Sites and click Add New Site

iis2

 

Enter a name for your website which will be accessed in the URL (http://localhost/<wesbite name> followed by the physical location on your HDD where you will store the application files and then the port to use for this website.

iis4

 

There you go. Now that your website is created, you can now host your PHP application on IIS Server. To test this out, you could place a .php file in the above mentioned folder and access the site (http://locahost/<your website name>:<port number>). In the example screen shot below, the index.php file contains the popular phpinfo() function.

 

iis5

 

With the steps described above, you have now configured windows IIS to host your PHP App.

in the next post i will cover the steps involved to setup authentication for your PHP app on IIS. So stat tuned. Look forward to you feedback / suggestions.


Add comment


 

Enter the word
captcha word
(hear it spoken)


  Country flag

biuquote
  • Comment
  • Preview
Loading