Installing PHP and MySQL on Windows IIS 6
Getting PHP and MySQL installed under Windows IIS takes more effort than your average Windows server install. While Microsoft has made IIS installation relatively effortless in recent years, these F/OSS components can be a bit challenging to work with. The MySQL installation is easy enough but it leaves you with a bare database service that requires the command line to do any database functions. Here's what I had to do in order to get all the components working properly under Windows 2003:
- Install IIS 6 by going into Add/Remove Programs (under the Control Panel) and then select Add/Remove Windows Components from the left side of the menu.
- The Windows Components Wizard will open. Double-click the Application Server line. Click the checkbox to install Internet Information Services (IIS), which installs the Common Files, Internet Information Services Manager, and World Wide Web Service. If you require SMTP or NNTP, click the Details... button to add them. Hit OK until you return to the Wizard.
- Click Next to begin the installation (which requires either the Windows CD or a path to the i386 directory).
- Once IIS is installed, download and install MySQL. I used the Windows MSI installer with the Essentials Package. Choosing the Custom Install option gives you the opportunity to choose the destination folder. I recommend using a folder structure that has no spaces (such as C:\MySQL) since spaces can result in configuration issues. Once you've chosen your folder, you can skip the MySQL.com account creation and finish the install.
- MySQL's installer will give you the opportunity to configure the server. You can get away with using the Standard Configuration but the Detailed Configuration does give you the opportunity to choose the server roles, including database type. The defaults are fine for most options. Just make sure that you add the install directory to the PATH when given the option. Add a root password and the following screen will complete the configuration.
- Download the latest zipped version of PHP. The installer seems to introduce problems so the archived file is recommended. Uncompress the folder to your hard drive; again, the easiest configuration is to use a folder structure without spaces (like C:\PHP5).
- Open the directory and locate the file named "php.ini-recommended" remove the "-recommended" part from the filename so it becomes "php.ini". Open this file in a text editor.
- Search for "doc_root" and type in the path to the home directory listed under the default web site in IIS Manager. (Right-click your website, click Properties, and then go to the Home Directory tab.)
- Search for "cgi.force_redirect" and make sure it's uncommented (delete the semicolon) and make it equal to 0 (zero).
- To use PHP sessions (which is optional), first create a directory (for instance C:\PHP5\sessions) and then key that path into the "session.save_path" line in php.ini.
- Now to get PHP extensions working, as is required for MySQL support, you will need to first find the "extension_dir" line and enter the path to PHP's extensions subdirectory (such as C:\PHP5\extensions). Then uncomment out the line "extension=php_mysql.dll" in the php.ini file. Any other extensions you require should also be uncommented.
- Save the php.ini file and exit out of the text editor.
- Add PHP's folder into the PATH environment variable. Right-click My Computer and select Properties. Under the Advanced tab click the Environment Variables button at the bottom. Then scroll the System variables section to find Path. Double-click it and enter your PHP path at the line's end appending a semicolon (such as c:\PHP5; in my example). You should not have to restart in order for this to take effect.
- Now in order to have Windows read the php.ini file you created earlier, you must either copy the php.ini file into C:\Windows (supposedly hard coded into PHP) or you can point to the ini file's location with the Registry. To do that, create a text file someplace on the server and paste the following into it and save it as phpini.reg:
Windows Registry Editor Version 5.00
Note the above assumes C:\PHP5 is your directory. Substitute as needed, but remember that any backslash in the path needs to use the escape code of double backslash. After this is saved, double-click phpini.reg to add the information to the registry.
[HKEY_LOCAL_MACHINE\SOFTWARE\PHP]
"IniFilePath"="C:\\PHP5" - Now launch IIS Manager for more configuration fun. First thing is to add PHP as a web service extension and allow it to run on the server. In IIS Manager, expand the local system and then right-click the "Web Service Extensions" folder and click "Add a new web service extension".
- Under the Extension name you can enter PHP and then click the "Add..." button. Browse to your PHP directory, double-click the "php5isapi.dll" file, and then hit OK. Then click the checkbox "Set extension status to Allowed" and then click OK.
- Now right-click Web Sites and click on Properties. Under the Home Directory tab, click the Configuration button. Click the Add... button to create the PHP extension. Browse to the PHP directory and double-click the same "php5isapi.dll" file from the last step. Type ".php" as the extension and then under the Verbs section select "Limit to:" and enter "GET,POST,HEAD" on the line. Click OK to return to the Web Sites Properties.
- This next step is optional but recommended. Click the Documents tab in the properties page and click the Add... button under the default content page. Call it "index.php" and then hit OK. Select this and move it to the top of the list. Click OK to close the properties page which will then prompt you to make those changes on each website listed (should just be 2 prompts if you have the Default Web Site only).
- Then expand "Web Sites" folder on the left pane, right-click the Default Web Site (or any other site(s) that need PHP) and select Properties.
- Under the Home Directory tab verify that the Execute permissions: line is set to "Scripts Only" and then click OK.
- Finally the configuration is complete. In IIS Manager, right-click the local computer, go to All-Tasks, and then select Restart IIS... Hit OK and PHP should be configured.
<? phpinfo(); ?>This page gives all the basic information of your PHP install. Spot check and verify the configuration for things like the Configuration File (php.ini) Path, doc_root, and extension_dir. Also you should see a table belonging to mysql that will provide the API version number. Your PHP and MySQL webserving platform should now be ready to go. Thanks goes out to Pete's Place for an excellent guide; unfortunately I happened upon it late into my own install headaches! But that guide still worked well for working around doing needless server restarts and providing extra functionality (like adding support for sessions).