How to Install PHP on Windows 7

var vglnk = { api_url: ‘//’, key: ‘1e2c002c3eea302c51c880500274a4e7’ }; (function(d, t) { var s = d.createElement(t); s.type = ‘text/javascript’; s.async = true; s.src = vglnk.api_url + ‘/vglnk.js?key=’ + vglnk.key; var r = d.getElementsByTagName(t)[0]; r.parentNode.insertBefore(s, r); }(document, ‘script’));

var _gaq = _gaq || []; _gaq.push([‘_setAccount’, ‘UA-7066727-2’]); _gaq.push([‘_trackPageview’]); (function() { var ga = document.createElement(‘script’); ga.type = ‘text/javascript’; ga.async = true; ga.src = (‘https:’ == document.location.protocol ? ‘https://ssl’ : ‘http://www’) + ‘’; var s = document.getElementsByTagName(‘script’)[0]; s.parentNode.insertBefore(ga, s); })();

Installing PHP on Windows 7 is quite a simple affair. However, as the more experienced developers would know, you need to have a web server running first. I suggest using the world’s most popular web server – get instructions on how to install Apache on Windows 7 operating system. And if you are a budding PHP programmer, you would very soon like to use it with MySQL database. So once you have finished with PHP installation, read the steps to install MySQL on Windows 7.
Assuming you have successfully been able to install Apache on Windows 7 and have seen the “It works” page, download the PHP file from Though I am on a 64 bit Windows 7 system, I downloaded because PHP doesn’t come in 64 bit flavour.
Create a folder to install PHP
This tutorial will tell you how to install PHP from the zip archive and not from the installer file – [Slide 1]. Somehow, I’ve found this is a little simpler. So the first thing is to create a folder where you would like to unzip the PHP files. I like to keep things segregated and yet accessible. Giving PHP its own directory under the C: drive is what I generally do. So go ahead and create a folder called PHP in the C drive on your hard disk. Now unzip the contents of the downloaded PHP zip file into this folder – [Slide 2].
In this C:/PHP folder, you’ll see a file called php.ini-recommended. Right-click on this file and choose Copy – [Slide 3]. Now paste the file in the same directory – [Slide 4].
Very important: Rename this file to
php.ini. Windows will tell you that changing the extension will make it unusable – Ignore the message and continue – [Slide 5].
Configuration Apache 2.2 web server for PHP installation
Though you have been able to put PHP on your computer, it’s still not “installed” in the true sense of the word. We have to help the Apache web server communicate with PHP. This is done by editing the Apache configuration file, httpd.conf. Go to All Programs -> Apache HTTP Server 2.2 -> Configure Apache Server -> Edit the Apache httpd.conf Configuration File. This opens httpd.conf file in Notepad – [Slide 6].
Gear up to make some changes to this file- check the screenshots from the slideshow as you go along.
  • Locate the “LoadModule section” (Tip: use the Find feature or the Ctrl-F key combination). Add the following line – [Slide 7]LoadModule php5_module “c:/PHP/php5apache2_2.dll”

    Note: If you have chosen to install PHP is a different folder and not C:/PHP, you have to change the path in the above line.

  • Find the “AddType” section and put in the line below – [Slide 8].AddType application/x-httpd-php .php

    Note: You can also use other file extensions for PHP like .php3 or .php4 – simply add them at the end of the above line separated by a blank space.

  • Move to the end of the httpd.conf file and add the line below – [Slide 9]PHPIniDir “C:/PHP”

    Note: This tells the Apache web server the location of the PHP configuration file – php.ini.

  • If you’ve read my instructions on installing Apache on Windows7 know that all web site files are to be kept in the htdocs folder located under the Apache install directory. This means when you load http://localhost, Apache checks the htdocs folder – the “It works” file that’s displayed the first time you test Apache installation is actually the index.html file in this folder.
    In accordance to my habit of having things organized, I like to keep web site files in their own folder away from Apache program and configuration files… something like
    C:/websites. The good news is that Apache allows you to make such a change pretty easily and to do this, you need to specify this new directory path as the document root.
    First create a folder for your web site files –
    C:/websites is what I use and is a nice choice. Find the DocumentRoot “C:/Apache/htdocs” in the Apache configuration file and change it to DocumentRoot “C:/websites” – [Slide 10].
  • Lastly, change <Directory “C:/Apache/htdocs”> to <Directory “C:/websites”> – [Slide 11].
Testing the PHP installation
Save the httpd.conf file – “File” -> “Save” [Slide 12] and restart your computer. You actually don’t need to restart the machine; stopping and starting the Apache service would have probably worked but I needed a cup of tea.
It’s now time to test whether PHP was properly installed on Windows 7. Open a Notepad window and type in the line below exactly as it appears – you can copy-paste if you want.
<?php phpinfo(); ?>
Save this file as phpinfo.php in the document root folder which should be C:/websites if you have followed by instructions above.

IMPORTANT: By default, Notepad will save the file as
.txt. So you need to select “All Files” from the “Save as type” drop down and enter the full file name in the “File name” field. Confused? Check the screenshot – [Slide 13].
Open a browser window and load http://localhost/phpinfo.php. A long page with details of the installed PHP version should display – please refer the screenshot in the slideshow – [Slide 14]. If you don’t get this and see the PHP code instead, you’ve probably not saved the file with a .php extension.
This completes the instructions on how to install PHP on Windows 7. I also advice going through the PHP configuration file (php.ini) and making modifications as required.

Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s