- Configure PHP 5.2.5 to run with Apache Server 2.0.46 as a web server module.
Despite the availability of an installation manual, most people would opt to do the much-dreaded complicated installation of PHP as packed in those all-in-one installers found over the internet. None of those are endorsed by PHP.net, makers of PHP, as they believe that the manual installation is still the best choice to have your system secure and optimised. What makes the installation so complicated is PHP's flexibility, the availability of path choices presented in the manual together with the text-based configuration involved to load the PHP module properly. What we have here is a single installation path for you to follow to get PHP 5.2.5 to run on Windows XP coupled with the Apache 2.0.46 web server.
- Download the PHP 5.2.5 zip package under Windows Binaries from PHP.net. The advantage here is the smaller download size, compared to the installer package which is about twice bigger.
- Extract the zip package contents to C:\php or whichever drive your Windows is installed in. D:\php if Windows is installed in drive D.
- Go to your php directory and duplicate file php.ini-recommended. Rename the copy to php.ini.
- Open php.ini with Notepad or Wordpad. Find (Ctrl+F) “extension_dir” and change the value as shown:
extension_dir = "C:\php\ext"This directs PHP to load extensions, including MySQL and GD support, disabled by default in this version of PHP, from the C:\php\ext directory. If you wish to enable an extension, uncomment the corresponding extension=php_*.dll line for that extension by deleting the leading ; from the extension you want to load. Find (Ctrl+F) “Windows Extensions” and find below an extension dll you wish to enable. The following enables MySQL and GD support required by some PHP applications such as phpBB3:
- We have to make sure that php5ts.dll in the PHP installation directory can be found during server startup. Let's add its location to the Windows PATH environment variable. Press Windows+Pause Break keys to invoke System Properties. Go to the Advanced Tab and click on Environment Variables. Double-click Path under System Variables and append your PHP directory at the end, including ; before it as shown in the example:
- Click OK and restart your computer.
Configure Apache Server
We're basically done with PHP installation. Let's now configure Apache to load PHP as a module.
- Open your Apache configuration file with Notepad or Wordpad. The easiest way to access it is through the Apache program group: Start > All Programs > Apache HTTP Server 2.0.46 > Configure Apache Server > Edit the Apache httpd.conf Configuration File.
- Find (Ctrl+F) “LoadModule”. In the LoadModule section, insert the following line:
LoadModule php5_module "C:/php/php5apache2.dll"This loads PHP as an Apache module during web server startup.
- Find (Ctrl+F) “AddType”. In the AddType section, insert the following line:
AddType application/x-httpd-php .phpThis will execute .php and .phps files in your web server directory as php applications.
# For syntax highlighted .phps files
AddType application/x-httpd-php-source .phps
- Add the following as well:
# configure the path to php.iniThis will load the php.ini configuration file that we have earlier created. Make sure you have set the correct path drive.
- Find (Ctrl+F) “DirectoryIndex”. In the DirectoryIndex directive, add index.php to the list of default files as shown in this example:
DirectoryIndex index.php index.html index.htm index.html.var default.htm default.htmlIndex.php files will be loaded if only the directory is specified in the browser url such as a website's beginning page.
- Save the configuration file.
- Restart Apache server. The recommended way is through the Apache program group: Start > All Programs > Apache HTTP Server 2.0.46 > Control Apache Server > Monitor Apache Servers. R-click the Apache icon in the system tray > Open Apache Monitor. Click Restart button.
If the log says:
The Apache2 service has restarted.Your Apache configuration file was set correctly. Otherwise, check your configuration file for typo errors specially lines with quotation marks. Make sure to replace them with the keyboard quotation mark key.
Let's now test if PHP is running correctly.
- Create an html file named phpinfo.html in your web server directory and insert this code within the ‹body› tags:
- Access phpinfo.html in your browser. A status information table for PHP should display the following:
- Loaded Configuration File