Debugging PHP on Apache HTTP Server on Windows Server 2008

In my recent attempt to install Apache HTTP Server, MySQL database server and PHP on Windows Server 2008, I spent quite some time figuring out why my Apache HTTP Server couldn't start. In this post, I will share how I had managed to solve the problem.

After installing everything that I had wanted, the error message The requested operation had failed appeared when I start my Apache HTTP Server:

Error message when Apache HTTP Server tries to start up

This gave me only one clue; Something went wrong when my Apache HTTP server try to start.

As a start, I try to recall the installation procedure.

  1. First, I installed Apache HTTP server.
  2. Then, PHP.
  3. Finally, I installed MySQL database server.

I recalled that after installing Apache HTTP server, no error messages was shown and the green arrow appeared on the Apache Monitor at the system tray. To isolate the problem, I uninstalled PHP. This time, the Apache HTTP Server was able to start and it greeted me with the It works! web page.

It works webpage

The cause of failure became apparent - it had to be due to the PHP installation. Hence, the next step would be to test whether it was PHP installation or the linkage between Apache and PHP that broke.

Check if my PHP installation was working

PHP resides in the computer as an executable and can be accessed via the command prompt. By default, the PHP installer will update the path variable to point to its installation directory. Hence, I wrote a simple script and named it as phpinfo.php:

<?php
    phpinfo();
?>

Then I execute the following command in my command prompt:

php phpinfo.php 

I was able to see the following screen:

Output from executing phpinfo.php in command prompt.

With that, I concluded that my PHP was installed properly. The next step would then be to check whether Apache was linked to PHP properly.

Check if my Apache was linked to PHP properly

The PHP installer will write into the httpd.conf file to link the Apache HTTP Server with the PHP executable. Opening up my httpd.conf file, I saw the following lines at the very end of the file:

 #BEGIN PHP INSTALLER EDITS - REMOVE ONLY ON UNINSTALL
PHPIniDir ""
LoadModule php5_module "php5apache2_2.dll"
#END PHP INSTALLER EDITS - REMOVE ONLY ON UNINSTALL

With that, I knew that the PHP installer had not done a proper job in writing the configuration codes into the httpd.conf file. This is because a properly configured httpd.conf file should contain codes that resemble the following:

#BEGIN PHP INSTALLER EDITS - REMOVE ONLY ON UNINSTALL
PHPIniDir "D:/Program Files (x86)/PHP/"
LoadModule php5_module "D:/Program Files (x86)/PHP/php5apache2_2.dll"
#END PHP INSTALLER EDITS - REMOVE ONLY ON UNINSTALL

Indeed, after I had edited the httpd.conf file with the proper linkage configuration, my Apache HTTP Server managed to run.

About Clivant

Clivant a.k.a Chai Heng enjoys composing software and building systems to serve people. He owns techcoil.com and hopes that whatever he had written and built so far had benefited people. All views expressed belongs to him and are not representative of the company that he works/worked for.