Running PHP to Test Websites on Windows PCs
PHP is a programming language that is popular for for adding powerful features to websites. What does PHP mean? PHP originally stood for Personal Home Page (after its inventor, Rasmus Lerdorf, wanted more features for his personal website), but now it stands for PHP Hypertext Preprocessor (creating a recursive acronym, which programmers like). PHP is easy to set-up and run on a Windows PC using the free Microsoft WebMatrix, an Integrated Development Environment (IDE) for building websites.
With the free WebMatrix package PHP on Windows is a single click install and allows website testing using IIS Express (the version of Microsoft Internet Information Server for Windows clients). This tutorial assumes that WebMatrix is installed and running on your Windows 7 or higher PC. If not see our article Develop a Website on Windows Using Microsoft WebMatrix to set it up and get a basic website going.
With WebMatrix running and a website loaded the first step is to add a new file, a PHP file. Select New from the WebMatrix toolbar (or use the File then New and File menu options). Select the PHP option and in the Name box enter a relevant file name, here php-test.php is used.
This tutorial is simply going to test for PHP being active and running on the Windows PHP. PHP has a function that will output its configuration information. This function is called phpinfo(). By calling this function from a PHP file you can check to see that PHP is configured and working, ready for any other PHP code to be used in the website. (Once PHP is known to be working the call to phpinfo() can be removed for security reasons, i.e. do not give out technical details of your websites).
All PHP code is placed between special mark-up tags <?php and ?>. For the phpinfo() function all that is need in the whole file is <?php phpinfo(); ?> as the function itself outputs all the relevant HTML mark-up. Add phpinfo() to the second line of the new file, followed by a semi-colon (;), which is used to end all PHP code lines. Delete all other lines as they are not needed in this code file. The file should look like this:
Next a link to the new PHP file is added in the index.html file (you could also rename index.html to index.php and put the code in there). A link uses the HTML <a> tag, for anchor but commonly referred to as a hyper-link or just link. The Hypermedia Reference attribute, href, points to the item being linked to, in this case php-test.php. In this example the link is added after the Hello World! message using the code:
<a href=“php-test.php”>PHP Info</a>
Here’s it in our basic example web page:
If the web site is now Run it is likely to display a HTTP Error 404.3 message because of the extension configuration, i.e. the web server, here IIS Express, does not recognise the PHP file. IIS Express is not configured for PHP.
To fix this problem click on the Site option at the bottom left of WebMatrix and then the Settings icon at top left. In the PHP Settings section click the Enable PHP check box.
If there is no PHP on Windows then WebMatrix will install it. The Install Product dialog appears. Follow the instructions clicking the Next button and accepting the license.
You will need to accept a User Account Control (UAC) dialog. After PHP has installed click OK to return to the files and run the website.
Click on the PHP Info link to run the PHP file and display the PHP configuration information.
PHP is now installed and running on the Windows machine. Where is PHP installed on Windows? There will be a sub-directory under C:\Program Files (x86)\IIS Express\PHP for each version of PHP installed. Each version has it’s own configuration file called php.ini, for example the phi.ini for PHP v5.5 on Windows is in C:\Program Files (x86)\IIS Express\PHP\v5.5.
PHP is a good templating language for web sites. The PHP code generates HTML that is sent to the users browser. The browser only gets the generate HTML and none of the code running at the server. This makes PHP useful for serving up feature rich web sites. To learn more about PHP there is a free online book available from Wikibooks.