Page 1 of 1

Can't get PHP module compiled for Apache 2.0

Posted: Sun Oct 08, 2006 11:43 pm
by jonheese
Hello all.

I'm having trouble compiling PHP 5 (I've tried 5.0.4, 5.1.2 and 5.1.6) for Apache 2.0.53.

Here is my configure script:

Code: Select all

./configure --with-apxs2=/usr/local/apache/bin/apxs --prefix=/usr/local --with-xml \
--with-config-file-path=/usr/local --with-pear --enable-sockets --enable-track-vars \
--enable-versioning --enable-force-cgi-redirect --disable-cgi --with-gettext --with-mysql \
--with-gd --with-zlib-dir=/usr
It compiles fine and I do a 'make install' to drop the 'libphp5.so' module into my Apache 2.0 modules dir, and when I try to start Apache, I get the error message:

Code: Select all

Starting httpd: Syntax error on line 190 of /etc/httpd/conf/httpd.conf:
API module structure `php5_module' in file /usr/lib/httpd/modules/libphp5.so is garbled -
perhaps this is not an Apache module DSO?
Which I've read means that apparently I'm compiling the Apache module for the wrong version of Apache (presumably 1.3x). I can't for the life of me figure out why it thinks I want an Apache 1.3 PHP module...

It's certainly worth noting that this server did previously have Apache 1.3something and it was recently upgraded to 2.0 in order to support PHP5. After struggling through quite a bit of trouble building and installing Apache, I'm now stuck on the PHP module.

I see a very real possibility that something (eg. the path to apxs) is still pointing to an old Apache 1.3 version of some binary, but it looks to check out to me, and I'm not sure how the machinery of the make script determines what version of Apache to build the module for...

Anyone? TIA.

Regards,
Jon Heese

Posted: Mon Oct 09, 2006 3:12 pm
by volka
In your php source directory (where you ran ./configure and make install) there should be a directory libs containing libphp5.so
Is readelf present on your linux system? If so run

Code: Select all

readelf -s libphp5.so | grep apache
does the output contain
apache2_sapi_module
?
Do the same with the module file apache is loading, ie
API module structure `php5_module' in file /usr/lib/httpd/modules/libphp5.so is garbled

Posted: Mon Oct 09, 2006 4:10 pm
by jonheese
I did a 'readelf' on both files and they both show 'apache2_sapi_module'.

If I'm interpreting this correctly, shouldn't that mean that this php module is properly built for Apache2?

What next?

Regards,
Jon Heese

Posted: Mon Oct 09, 2006 4:50 pm
by volka
If I'm interpreting this correctly, shouldn't that mean that this php module is properly built for Apache2?
I thought so, too.
How did you install apache2? Did this include any development packages, headers, whatever?
Was the old apche1 removed? How?

Posted: Mon Oct 09, 2006 5:14 pm
by jonheese
It was about 6 months ago, and it took a lot of trial and error to get it all working right, so I don't quite remember all of the specifics of the Apache2 install.

I think I tried to build it from source a few times, but ended up having problems with the PHP install after that, so I ended up installing it from the RPM (it's running Fedora Core 3), and that worked. I actually got PHP5 built and running then, but forgot to turn on the '--with-gd' switch when compiling and now I need it, which is why I'm trying to do this again.

I'm now using the same PHP source tree as I used before, with the same ./configure line, with the addition of '--with-gd'. I did a 'make clean' to be sure that nothing was still around from the previous build, and now I'm having the problem with the PHP5 module.

As a side note, the CLI is being built and installed fine, and shows the build date of today, so I know it's building successfully...

Any other ideas or things to check?

Regards,
Jon Heese

Posted: Mon Oct 09, 2006 6:32 pm
by volka
only speculations.
Did you change/update your gcc (configuration) between the compilation of the apache and php?

Posted: Mon Oct 09, 2006 7:59 pm
by jonheese
Nope, no changes to gcc in the lifetime of this machine.

However, I did figure out the problem (this is a little long, but bear with me):

Here's the configure line I used before and got a working PHP module:

Code: Select all

./configure --with-apxs2=/usr/sbin/apxs --prefix=/usr/local --with-xml \
--with-config-file-path=/usr/local --with-pear --enable-sockets --enable-track-vars \
--enable-versioning --enable-force-cgi-redirect --disable-cgi --with-gettext --with-mysql
Then, I added '--with-gd', because I needed GD support:

Code: Select all

./configure --with-apxs2=/usr/sbin/apxs --prefix=/usr/local --with-xml \
--with-config-file-path=/usr/local --with-pear --enable-sockets --enable-track-vars \
--enable-versioning --enable-force-cgi-redirect --disable-cgi --with-gettext --with-mysql \
--with-gd
This produced an error in the 'configure' script that looked like this:

Code: Select all

...
checking for floorf... (cached) yes
If configure fails try --with-jpeg-dir=<DIR>
configure: error: PNG support requires ZLIB. Use --with-zlib-dir=<DIR>
So, I tried adding '--with-zlib-dir=/usr':

Code: Select all

./configure --with-apxs2=/usr/sbin/apxs --prefix=/usr/local --with-xml \
--with-config-file-path=/usr/local --with-pear --enable-sockets --enable-track-vars \
--enable-versioning --enable-force-cgi-redirect --disable-cgi --with-gettext --with-mysql \
--with-gd --with-zlib-dir=/usr
and that 'configure'd fine, so I built it and ended up with the broken PHP module that has plagued me for days now.

So, on a hunch, I tried taking out the '--with-gd' and '--with-zlib-dir=/usr' parts, built it, and dropped it into my Apache modules. Restart httpd, no errors... hm. So the GD stuff was breaking it.

On another hunch, I added back the '--with-gd' part, this time with '--with-zlib' and '--with-jpeg':

Code: Select all

./configure --with-apxs2=/usr/sbin/apxs --prefix=/usr/local --with-xml \
--with-config-file-path=/usr/local --with-pear --enable-sockets --enable-track-vars \
--enable-versioning --enable-force-cgi-redirect --disable-cgi --with-gettext --with-mysql \
--with-gd --with-zlib --with-jpeg
Voila! I now have a working, GD-supporting Apache2 PHP5 module. Apparently, if you specify with-gd but don't add with-zlib *AND* with-jpeg, you get no error messages, but you end up with a broken, useless PHP module.

In the end, I should have paid more attention to the original configure script error, but it was a bit misleading.

Anyway, thanks for all your help!

Regards,
Jon Heese