Sunday, January 25, 2009

Why am I getting a SyntaxError when trying to start Apache after adding the PHP module?

This one was a killer to figure out and I can't believe I couldn't find the answer with Google. I just installed Apache 2.11 and PHP 5.2.8. Both worked independent of each other, but when I tried to add the PHP module to Apache, it wouldn't start. Specifically, I added:


LoadModule php5_module "c:/path/to/php/php5apache2.dll"
AddType application/x-httpd-php .php
AddType application/x-httpd-php-source .phps


to the httpd.conf file. This was what every set of setup instructions said to do. When I originally tried to fire up Apache as service, it couldn't start. To get some information about the error I tried to start it from the command line. This is probably obvious to most, but you can of course run the web server from the command line. Something like:


>>> c:\Program Files\Apache\bin\httpd.exe


ought to do the trick. Obviously, if you install it elsewhere, replace the relevant parts of the path.

Anyway, I ran it from the command line and got the terrific error message:


Syntax error in line 128 of C:/Program Files/Apache/conf/httpd.conf: Cannot load c:/path/to/php/php5apache2.dll in to server: The specified module could not be found.


It's a little misleading that it says "SyntaxError" because I then spent about 15 minutes trying to figure out if I had a typo somewhere. When I finally started Googling around, I quickly realized the important part of the error message was the last sentence.

To make a long story short, I finally was tipped off by the fact someone mentioned using Apache 2.0.x instead of Apache 2.2 to solve the problem. Ah ha! If you look in the PHP installation directory, there is a suspicious DLL named php5apache2_2.dll. I switched my httpd.conf to use that one instead, and bingo. We're in business.

Like my last post, hopefully this helps someone else stuck in this situation. I had a feeling there might be something about different versions of Apache when I was downloading it and my options were 2.11 and 2.0.63. I didn't notice any discussion of what the big differences were on the Apache site, but apparently there are some. Feel free to leave a comment about the main differences between the versions if you know.

No comments: