How to install PHP5 on Windows

This article is a quick guide to getting PHP 5 running on your Windows machine (be it Windows 98/Me or Windows NT/2000/XP/2003). Note! I advise you remove all files like php.ini and PHP related DLLs from the Windows SYSTEM folder before moving on with a new PHP installation.

1. Download the PHP binaries

PHP is free and comes complete with the source code. If you are not interested in hacking the PHP source code, you can simply download the Windows binaries. Both the binaries and the source code can be found at the PHP website. At the time I wrote this, the relevant PHP binary to download comes in a zip file (PHP 5.1.3 zip package). The Windows installer version does not include the binaries to run PHP5 as an Apache module.

2. Installing/Upgrading PHP5

Installation is actually trivial.

  • If you are upgrading stop the Apache windows service before you continue and rename your current php5 dir to something like php5_backup, just in case something goes wrong.
  • Create a directory for PHP5 on your computer. For the purposes of this article, I will assume that you created C:\php5.
  • Extract all the files to this directory, sometimes they’ll be placed in a subdir called php-5.x.x-Win32 (when using WinRAR). Move all the files in this subdir to php5 and delete subdir php-5.x.x-Win32

3. Configuring PHP5

Inside the php5 directory you’ll find to files called php.ini-dist and php.ini-recommended. Open the last one in a text-editor (Notepad) and search for and replace (where needed) the following:

  • short_open_tag set to short_open_tag = On if you have tags on the form <? …
  • error_reporting set to error_reporting = E_ALL & ~E_NOTICE
  • register_globals set to register_globals = On if your scripts doesn’t work as intended, else leave off.
  • register_argc_argv set to register_argc_argv = On if your scripts passes information in strings (index.php?var1=value1&var2=value2)
  • doc_root set to the path to your Apache web directory, e.g. doc_root = C:\Apache2\htdocs (normally htdocs)
  • extension_dir set to extension_dir = “C:\php5\ext” (More info about useful extensions will follow)
  • SMTP set to SMTP = smtp.yourISP.com
  • All done – Save your new ini file as php.ini to the main directory C:\php5

4. Configure Your Apache Web Server

If you want PHP to work with your Apache server, you will need to modify your Apache configuration file to load it. Naturally, you will need to have already installed Apache on your machine and configured it. Please read our tutorial on how to install Apache on Windows if you haven’t already.

To configure Apache to load PHP5 as a module to parse your PHP scripts, use a text editor to open the Apache configuration file, httpd.conf, typically found in C:\Apache2\conf.

Next, add the following lines at the bottom of this file:

# For PHP 5 do something like this:
LoadModule php5_module "c:/php5/php5apache2.dll"
AddType application/x-httpd-php .php .php3 .phps

# configure the path to php.ini
PHPIniDir "c:/php5"

To configure Apache to load PHP5 as a CGI-Binary to parse your PHP scripts add this instead:

# For PHP 5 do something like this:
ScriptAlias /php/ "c:/php5/"
AddType application/x-httpd-php .php .php3 .phps
Action application/x-httpd-php "/php/php-cgi.exe"

Note! By using the CGI setup, your server is open to several possible attacks. Please read PHP’s CGI security section to learn how to defend yourself from those attacks.

Now all that remains is to add some variations of index files to the DirectoryIndex. Replace the DirectoryIndex line with the following:

DirectoryIndex index.htm index.html index.php index.html.var

Note! By changing the order you can make your server parse index.php before index.htm like this:

DirectoryIndex index.php index.html index.htm index.html.var

You may off course add more filetypes/extensions as well, e.g. index.phtml, index.shtml, index.php3 or whatever you use.

5. Testing Your PHP5 Installation/Upgrade

Create a PHP file with the following line:

<?php echo phpinfo() ?>

Save the file as phpinfo.php (or any other name that you fancy, but with the “.php” extension) into your Apache htdocs directory.

Next, restart your Apache server so that it can read the new configuration directives you placed into httpd.conf. Open your browser, and access the file you just created by typing http://localhost/phpinfo.php into your browser’s location bar. You should see an entire pageful of information about your PHP setup.

Congratulations – you have successfully installed PHP and configured Apache to work with it. You can also use this same file, phpinfo.php, to find out more about how your web host has set up his php.ini so that you can duplicate it on your local machine.

About Author

12 Comments on “How to install PHP5 on Windows”

  1. Hello! Help solve the problem.
    Very often try to enter the site, but says that the password is not correct.
    Regrettably use of remembering. Give like to be?
    Thank you!

  2. If your comment is an attempt to drive visitors to your site you should focus on your spelling, especially since you appear to be offering translation services…

    If you actually need help setting up a local server – please be more specific.

  3. I make… Check out the download section if you would like to try it on your own blog (if you have any)…

  4. Hi

    As a fresh blog.evaria.com user i only wanted to say hello to everyone else who uses this site 😎

Comments are closed.