PHP is very well documented, and I suggest you browse through the manual at http://www.php.net/manual/en/index.php to get familiar with the language before diving right in to the preparation and installation. The steps I list below are for IIS 7, on Windows Vista SP1, Windows 7, or Windows 8, and are based on the instructions in the manual I linked to above.
- Assuming you already have IIS 7 installed ( go do that, if you don’t), we need to enable FastCGI on IIS. To do this, open Control Panel, and select Programs and Features. In the column on the left side, click “Turn Windows features on or off”. In the Windows Features dialog, expand Internet Information Services, then expand World Wide Web Services, Application Development Features, and select the check box next to CGI. You should see something like this…..
- Click Ok, and Windows will do the installation.
The actual process of installing PHP requires a bit of reading, because you have to set up the config file once you’ve downloaded and extracted the correct build of PHP. Here is a link to the full process… http://www.php.net/manual/en/install.windows.manual.php . Once you download and extract PHP, and get your config file set up, we’ll need to tell IIS how to process PHP requests.
Configuring IIS to Process PHP
These last steps will guide you through using the IIS Manager UI to create a handler mapping for PHP, and, again are based on the steps in http://www.php.net/manual/en/install.windows.iis7.php . I recommend you take a look at their manual after doing this simple UI setup, as they have detailed information on how to use the command line tool, and information about impersonation and file system access.
- Open Control Panel, select Administrative Tools, and double click IIS Manager.
- Select the Server node in the tree view on the left side, and then double click the Handler Mappings icon in the IIS section of the Features View. It should look similar to this…
- In the Actions pane on the right, click “Add Module Mapping…”
- Enter the following information in the “Add Module Mapping” dialog…
- Request path: *.php
- Module: FastCgiModule
- Executable: C:\[Path to PHP installation]\php-cgi.exe
- Name: PHP_via_FastCGI
5. Click “Request Restrictions” button and then configure the mapping to invoke handler only if request is mapped to a file or a folder;
6. Click OK on all the dialogs to save the configuration.
If everything went according to plan, your default website is now configured to process PHP requests. Here’s how we test it…
- Open up Notepad and enter the following line of text, without the quotation marks surrounding it…”<?php echo ‘Hello World’; ?> “
- Click File, Save As…, and save the file as Test.php ( be sure to set the file type to All Files) in your My Documents folder.
- Copy the Test.php file to C:\inetpub\wwwroot.
- Finally, open a web browser and browse to localhost/test.php. You should see your Hello World output.
Conclusion / Now What?
This walkthrough covered the very basics of getting PHP installed, and setting up IIS to process PHP requests. It didn’t begin to touch on the actual language, syntax, or usage of PHP, but there is great documentation and plenty of walkthroughs at php.net to get you started on using PHP. My next blogs will be about setting up MySQL ( Spoiler: it was infinitely easier than my first attempts at installing and configuring Microsoft SQL Server ) and connecting to it from PHP, and how to use browser detection to detect mobile devices and load appropriate css sheets.