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:
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.
- First, I installed Apache HTTP server.
- Then, PHP.
- 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.
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:
I was able to see the following screen:
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.