Chủ Nhật, 23 tháng 8, 2009

Configuring PHP to run on IIS6 (Manually).(Windows Server 2003)

About PHP.
PHP is an "Open Source" scripting language and provides very similar functionality to Microsoft's ASP. Obviously, both have their advantages and a comparison of the two technologies is outside the scope of this tutorial. However, a common misconception is that PHP is "Linux only" and not compatible with Microsoft systems.

To find out more about PHP, visit the following site:
http://www.php.net

1. Getting started - Choosing which package to download.
A visit to the www.php.net downloads page reveals a choice of two downloads in the "Windows Binaries" section:

  • PHP 4.3.6 zip package [7,201Kb]
  • PHP 4.3.6 installer [1,047Kb]

(Please note that later versions may be available as you read this)

The "installer" is the easier of the two to install but not without it's bugs. If you prefer this method please visit the "CONFIGURING PHP TO RUN ON IIS6 (INSTALLER)" page to learn how to successfully install and configure it.

The ZIP package is the preferred option simply because it includes greater functionality and extensions. However, this should be obvious from the much greater download size.

THIS TUTORIAL FOCUSES ON THE CONFIGURATION OF THE "ZIP PACKAGE".
Both packages can be downloaded from the following page:

http://www.php.net/downloads.php

You will also need to download the FastCGI ISAPI/NSAPI binaries from http://www.caraveo.com/fastcgi/.


2. Extracting the files:

Figure 1 - Extracting the files
Figure 1 - Extracting the files

Unzip the PHP archive to C:\PHP then copy "php4ts.dll" (highlighted in Figure 1 above) into C:\Windows\System32\

Next, unzip the FastCGI binary and copy isapi_fcgi.dll into C:\PHP\


3. Configuring Internet Information Services (IIS) Manager:

Figure 2 - Accessing the "Web Sites Properties" dialogue box in IIS
Figure 2 - Accessing the "Web Sites Properties" dialogue box in IIS

If you are using the new style Start menu, you can reach the Internet Information Services console by clicking “Start”, “Administrative Tools” and selecting “Internet Information Services (IIS) Manager” from the list.

If you are using the “Classic” style Start Menu, you can reach the console by clicking “Start”, “Programs”, “Administrative Tools” and select “Internet Information Services (IIS) Manager” from the list.

The first thing we need to do is tell IIS how it should process PHP files. To do this, first right-click on "Web Sites" in the left-hand menu and select "Properties" from the list that appears (as shown in Figure 2 above).

Figure 3 - Application Configuration
Figure 3 - Application Configuration

Once open, select the "Home Directory" tab and click on "Configuration". A similar window to figure 3 (above) will appear. Click on "Add".

Figure 4 - PHP Application Mappings
Figure 4 - PHP Application Mappings

Complete the box shown in Figure 4 (above) as shown then press "OK". If you see a message appear with a list of "Child Nodes" you should click on "Select all" and then press "OK" as this will ensure that all web sites on your server have PHP capability.

IIS now knows how to process PHP files. However, it's "Web Service Extensions" rules still restrict it from doing this.

Figure 5 - Web Service Extensions
Figure 5 - Web Service Extensions

We now need to configure "Web Service Extensions" so right-click on "Web Service Extensions" in the menu on the left. Then select "Add a new Web service extension..." from the list (as shown in Figure 5 above)

Figure 6 - Creating a PHP web service extention
Figure 6 - Creating a PHP web service extension

Complete the dialogue box as shown in Figure 6 above. Make sure you check the "Set extension status to Allowed" checkbox. The "Extension name:" is only a reference and hence can be anything - PHP makes it easy to identify in future though.

Figure 7 - The completed Web Service Extensions window
Figure 7 - The completed Web Service Extensions window

The completed "Web Service Extensions" window should now look like figure 7 above.IIS now knows to process PHP files and our "Web Service Extensions" have made it possible for PHP scripts to run freely.


4. Allowing index.php files to run as a directory default:

Figure 8 - Configuring your default PHP content page
Figure 8 - Configuring your default PHP content page

Returning to "Web Sites Properties" dialogue shown in Figure 2 we need to select the "Documents" tab and click on "Add".

To ensure that index.php documents open as a default they should be added as a "Content Page" as shown in Figure 8. You can, of course, change the importance of PHP over ASP and HTML documents to suit your site based on which document type should take preference.


5. The Final Step:

Figure 9 - Creating the required registry keys and values
Figure 9 - Creating the required registry keys and values.

Open the Registry Editor by clicking “Start”, “Run”, typing “regedit” and pressing “OK”. Perform the following procedure (illustrated by Fig. 9 above):

  • Locate and expand “HKEY_LOCAL_MACHINE”, right-click on “Software” and select “New”, “Key” and type “FASTCGI”.
  • Right-click on your new “FASTCGI” key and select “New”, “Key” and type “.php”.
  • Right-click on “.php”, select “New”, “String Value” and type “AppPath”. Double-click on this new value and type “c:\PHP\php.exe”.
  • Right-click on “.php”, select “New”, “String Value” and type “BindPath”. Double-click on this new value and type “php-fcgi”.

You can now close the Registry editior.

The last task is to move the configuration file from C:\PHP to the correct location:

  • Rename C:\PHP\php.ini-recommended to php.ini and move to C:\Windows\


TESTING...


Figure 10 - Creating the required registry keys and values.

Create a new text file and rename it "index.php". This file should contain one line that reads:

<? phpinfo(); ?>

Simply copy this file to your web server and open it via your favourite web browser. You should be presented with a page similar to Fig. 10 above.

Không có nhận xét nào: