Monday, March 3, 2008

Installing PHP on Windows

PHP is in many ways like ASP or JSP. In this blog entry I will share some of the things I ran into while installing PHP on Windows and IIS 5 (IIS that comes with Windows XP Professional). First download the software: http://us2.php.net/get/php-5.2.5-Win32.zip/from/a/mirror/php-5.2.5-Win32.zip Run the installer. I recommend installing PHP at C:\PHP instead of C:\Program Files\PHP. Do NOT select all extensions as some of them have other prerequisites that can make your installation not work. Installing more extensions than needed complicates troubleshooting. You can always to go Add/Remove Programs again and add more extensions after you know the basic installation works fine.
After you run the installer, there are some things you may need to do to get things to work properly.
You will want to set some environment variables in Windows. 1. Append C:\PHP; to the Path Windows Environment Variable. 2. Create a new Windows Environment Variable called PHPRC and set it to c:\PHP\php.ini assuming you installed PHP at c:\PHP. This will tell Windows where the php.ini file is should it get confused. You can verify that PHP knows were your php.ini file is by using the test page shown later in this blog. On the test page, verify that the line labeled "Loaded Configuration File" should be c:\PHP\php.ini. You will probably need to restart IIS for it to see the new environment variable. You will want to make sure that PHP is properly configured in IIS. Get Properties on Start Menu | Admin Tools | Internet Information Services | <machine> | Web Sites. On the Home Directory tab, click the Configuration button. In the Application Configuration dialog click the line with .php as the extension, then click the Edit button. On the "Add/Edit Application Extension Mapping" make sure the fields have the values: .php, C:\PHP\php5isapi.dll, All Verbs, Script Engine checkbox is checked, and Check that files exists checkbox is checked. The installer will put a DOS style path instead of C:\PHP\php5isapi.dll. This is probably ok, but if you have problems try the full win32 path as noted here. To verify that the installation was successful, all you have to do is use your favorite text editor to create a .php file and access it. I recommend the contents of the file be the following as it will prove several things: 1. That IIS is handing off the request to Php5isapi.dll 2. That PHP tags are being interpreted properly by PHP 3. Give you lots of information related to how PHP is configured. <html><head><title>Test PHP Page</title></head> <body> Success for PHP <?php echo "Hello PHP Scripting"; ?> </body> </html>

If you have any trouble I suggest that you read this article on how to manually install PHP. It will give you a better understanding of what the installer does, and how PHP works.

http://www.iis-aid.com/articles/how_to_guides/installing_php_5_on_iis_in_5_simple_steps?page=0%2C0

For more information on doing development in an IDE with a debugger, check out my other blog entry titled "PHP Development Environment."

No comments: