Home
Archives
About us...
Advertising
Contacts
Site Map
 

ruby in steel

 

INSTALL PHP FOR WINDOWS

Many web hosts are run on Linux. With the appropriate software installed, you can develop many compatible applications on a PC running Windows.

 

If you are developing web applications such as Blogs and Content Management Systems (CMS), it is useful to install the software on your PC for local development. Many of the most popular web applications are written in PHP and make use of the MySQL database. For local development, you will need PHP, MySQL and a server. Many web hosts - including those running Linux - will have PHP, MySQL and the Apache Server installed. Here we explain how to install PHP on a Windows-based PC. Before doing this, you may want to follow our guide to installing the Apache Server. Optionally, you may also want to follow our guide to installing MySQL.

The good news is that PHP can be installed simply using a Windows installation program. The bad news is that this performs a restricted installation and the PHP web site warns that “the installer isn't the preferred method for installing PHP.”

…which is why I decided to do the slightly more long-winded, but compete, installation of PHP by downloading the ZIP file. This can be found on the PHP web site: http://www.php.net/

You will find that several alternative versions of PHP are available. You may choose to download an old release in order to be assured of running the same version of PHP as your web host. However, here I shall assume that you want to download the latest stable release. At the time of writing this is version 5.05. This is available from the downloads page: http://www.php.net/downloads.php. The file I downloaded is called php-5.0.5-Win32.zip though the name will change in time as new versions are released.

Note: Built-in support for MySQL is no longer provided with PHP 5 (as it was with PHP 4). Moreover, some versions of PHP 5 omit a necessary file, libmysqli.dll. PHP 5.0.2 includes this file. For use with MySQL, therefore, you may either want to use PHP 4, 5.0.2 or, alternatively, you can download the latest release and extract the missing file from the 5.0.2 release. See our guide to installing MySQL for more information.

Download this file and decompress it into a directory of your choice using XP’s Windows unzipping tool or a third party tool such as the StuffIt Expander. On my PC, I’ve unzipped into the directory F:\windev\php though you could simply extract to C:\php if you wish.

Note: It is possible to run PHP with servers other than Apache. For the sake of clarity, however, we assume that you have installed the Apache Server onto your PC as explained HERE.

All you have to do now is to let the Apache Server know where PHP can be found on your hard disk. Do this by editing the Apache configuration file httpd.conf. This can be done direct from the Configure Apache Server item in the Apache group on the Windows Start menu.


You can edit httpd.confby selecting an item from the Apache group on the Start Menu

Alternatively, you can find the file in the configuration subdirectory beneath your Apache directory using Windows Explorer. By default this will be: C:\Program Files\Apache Group\Apache2\conf unless you have installed it into some other directory. In this directory, you will find httpd.conf. Open this file in Notepad.

At the end of the file you will need to add two lines to tell Apache to load the PHP module. Note that the first line specifies the PHP installation directory and you should edit this to the actual directory path into which you unzipped PHP. Be sure to use the / character in the directory path rather than the more usual Windows \ character:

LoadModule php5_module c:/php/php5apache2.dll
AddType application/x-httpd-php .php

These lines tell Apache to load PHP and treat files ending with the extension ‘.php’ as PHP files – which, obviously, is something that we wish it to do! Note that the version number in the module and dll name specified above assume php 5 and this may need to be changed with other versions.

You can test that your changes are valid by selecting Test Configuration from the Configure Apache Server group in the Windows Start menu (see above). If there are any errors – for example, if the directory you specified does not exist – it will inform you. If there is an error, you may need to correct it by editing the two lines you just entered into httpd.conf.

All being well, you are now ready to restart the Apache server. Do this by selecting Restart from the Control Apache Server submenu in the Windows Start menu. When Apache restarts it should install PHP ready for use. To test it, type this text into Windows Notepad:

<?php
  phpinfo();
?>

This is a PHP command which calls the phpinfo() function. Save this file with the name test.php into the \htdocs subdirectory beneath your Apache installation directory (e.g. if you installed Apache into the default location on the C:\ drive the full path to your new file will be C:\Program Files\Apache Group\Apache2\htdocs\test.php).

Assuming you set up the Apache server with the name localhost (as explained in our Apache installation instructions), you can now use the name ‘localhost’ to access the \htdocs directory. To verify this, start up your web browser and enter http://localhost/test.php into its address bar:


Assuming you have set up Apache Server to use the name localhost and you have saved the PHP test file, test.php into the \htdocs dubdirectory as explained above, you should be able to test PHP by entering this address in your browser

You should see something similar to the following appear in your browser window:


Your first sign that PHP is alive!!!

And that’s it. You now have Apache and PHP installed.

As a final step, it is a good idea to add an INI file to configure PHP. You will find one named php.ini-recommended in your PHP directory. You can copy this to your \Windows directory and rename it php.ini. It is recommended that you change the doc_root entry in php.ini to the path to the \htdocs folder (assuming you are using Apache Server). e.g.

doc_root = "G:\Apache Group\Apache2\htdocs"

You may also want to change the extension_dir entry to the PHP extension subdirectory's path (typically this is the \ext subdirectory beneath the PHP directory itself). e.g.

extension_dir = G:\php5\ext

More detailed advice can be found in the PHP online manual.

Click HERE for help with installing MySQL…

See also, our Guide To WAMP - Windows-Apache-MySQL-PHP

 

October 2005

 


Home | Archives | Contacts

Copyright © 2006 Dark Neon Ltd. :: not to be reproduced without permission