Installing PHP5 from Source on Apache2/RH9 (IWorx) + ZO

Hello Chris and Interworx users,

One of our common clients had come to me for assistance with the compilation of PHP5 on his IWorx machine with the hope of using Auracle Support Engine, our helpdesk (which forces the PHP5 requirement) in conjunction with whois.cart(). Being that I always advocate source compilation, the steps that follow describe the steps taken to successfully compile PHP5 from source.

1. CONFIG :The first step usually involves lifting a compilation command from the phpinfo output. Usually, this config directive is re-usable (since one assumes that it figures in the PHP info directive because it was successful in the first place). Unfortunately, with the PHP config installed by Interworx RPM, this isn’t the case. Some doctoring is at hand. The final result:

(file phpcompile)

./configure --with-apxs2=/usr/sbin/apxs --prefix=/usr --bindir=/usr/bin --mandir=/usr/share/man --disable-debug --disable-rpath --with-bz2 --with-db4=/usr --with-curl --with-exec-dir=/usr/bin --with-freetype-dir=/usr --with-png-dir=/usr --with-gd --with-gdbm --with-gettext --with-ncurses=shared --with-gmp --with-iconv --with-jpeg-dir=/usr --with-openssl --with-png --with-xml --with-expat-dir=/usr --with-dom --with-dom-xslt --with-dom-exslt --with-xmlrpc --with-readline --with-pcre=/usr --with-zlib  --with-pear=/usr/share/pear --with-mhash --with-ldap --with-mcrypt --with-mysql=/usr --with-unixODBC=/usr --with-pgsql --without-oci8 --with-snmp=/usr --enable-ucd-snmp-hack --enable-bcmath --enable-exif --enable-ftp --enable-magic-quotes --enable-safe-mode --enable-sockets --enable-sysvsem --enable-sysvshm --enable-discard-path --enable-yp --enable-wddx --enable-memory-limit --enable-bcmath --enable-shmop --enable-calendar --enable-dbx --enable-dio --enable-mcal --enable-mbstring --enable-mbstr-enc-trans --enable-mbregex --enable-inline-optimization --enable-gd-native-ttf --enable-pic

Note that these directives must exist on a single line. These aren’t my settings of choice, but simply a replication of the environment that was specified by the Interworx PHP4 build that was operational at the time.

2. PREP: Set up a home base, I usually mkdir /devel and work from there. Save your phpcompile file into that folder, and cd /devel

3. APR: One of the problems on the box in particular was that the php compilation would fail with a missing apu-config command (which is commonly installed alongside httpd-devel in my experience). It appears that it was dissociated in this case, so the installation of apr was necessary. Let me interject, I hate RPMs, but gave them a try this time…disastrous failure - the dependencies trickle down into db4 which is required by too manythings. If I can offer any timesaving advice, go get the source instead; which bides the steps that follow:

3a. wget
3b. tar -zxf apr-0.9.7.tar.gz
3c. cd apr-0.9.7
3d. ./configure
3e. make && make install
3f. cd …

3f. wget
3g. tar -zxf apr-util-0.9.7.tar.gz
3h. cd apr-util-0.9.7
3i. ./configure --with-apr=/usr/local/apr/bin/apu-config
3j. make && make install
3k. cd …

3l. create a symlink to apu-config on your system to /usr/bin:
ln -s /usr/local/apr/bin/apu-config /usr/bin/apu-config

4. PHP SOURCE: Time to get the PHP source from, from your /devel:

4a. wget
4b. tar -zxf php-5.1.2.tar.gz
4c. cp phpcompile ./php-5.1.2/phpcompile
4d. cd php-5.1.2
4e. chmod 700 phpcompile
4f. ./phpcompile

The system will attempt to configure your php compilation using the flags in the phpcompile file above. Note that this varies on a per-system basis, if you run into problems, make sure that the options in your phpcompile flag can be ‘backed’. That is if you have --with-mysql in there, make sure that your mysql is actually installed! You can get away with stripping options whose components are missing - just make sure you don’t strip anything that interworx needs. Sometimes it’s just a game of specifying the right path to the component, see the config file directives section at for more info.

4g. If the compile command is successful, issue: make && make install

5. Preparing HTTPD: There seems to be a BSD-style config file system going on on these IWorx machines. When running make install on the PHP source, it’ll automagically add the LoadModule directive to your /etc/httpd/conf/httpd.conf. Thus,

5a. pico /etc/httpd/conf.d/php.conf and comment out:
#LoadModule php4_module modules/

5b. pico /etc/httpd/conf/httpd.conf and make sure that the only “LoadModule phpX” module that’s there, is the one that loads PHP5. I prefer to leave it in httpd.conf - otherwise, PHP will continuously add that line upon recompilation. One could argue that I could have specified the config-file path in the config directive. In defense, where one’s fingers are already overworked, all this extra typing seems…unsurmountable…defaults are good.

Download Zend Optimizer from - it’s a free download. Unpack, and access its directory to issue: ./ Follow the steps prescribed, it’s pretty painless. The ZO installer will ask you for the default location for php.ini, on this machine, it was in /etc/php.ini. ZO’s installer usually figures out the rest on its own (presents the options as default values).

6a. Not sure if this is an Interworx requirement, but I didn’t change it to be on the safe side - PHP apparently expected php.ini to be in /usr/bin. Thus, symlink it:

ln -s /usr/local/Zend/etc/php.ini /usr/lib/php.ini

7. PHP.INI CLEANUP : pico /usr/local/Zend/etc/php.ini. Few strange things I saw, not sure if these are Interworx required/related…but perhaps worth mention:

-consider setting extension_dir to the standard /usr/lib/php/extensions/ instead of local values (.) which could permit your users to load .so objects from their home directories!

-consider turning mysql persistent links OFF. These are a waste - the resources required to spawn a thread on mySQL are FAR less than the resources used to maintain persistent links.

7a. For use with Auracle, which requires mailparse, add the line:

extension =

To the dynamic module section

Save your php.ini

If you specified Mailparse should be loaded, issue:
pecl install mailparse

Then copy from /usr/lib/php/extensions/no-debug… to /usr/lib/php/extensions/

service httpd restart

In this case, everything worked.

There are great benefits to installing from source, when PHP 5.1.3 comes out for example, all you’ll need to do is unpack the archive, copy your phpcompile file from your 5.1.2 directory to the 5.1.3 source directory and issue ./phpcompile, make && make install, and then restart apache. Easy 123!

In any case, I hope this helps a few of you, I saw some many conjectural comments circumambulating the topic of upgrading to PHP5 on your boxes in these forums whilst investigating for int - hopefully this’ll demystify the issue. I’d add that PHP5 is leaner, faster and much more powerful than PHP4, and that “well-written” PHP4 code (ie. no self-assignment of $this variables etc.) will not break on the crossover. IMHO, code that does break, breaks because it needs a rewrite. Now armed with your new setup, your Apache and PHP5 can rule the galaxy as Luke and Darth might have done had he accepted. Hope this helps!


(diagnostics pack to help out, at

ps. not sure if this was the right forum, please do move it at your discretion.

Nice guide… Works pretty much apart from i receive the following errors:

/usr/lib/apr/build/libtool --mode=install cp /usr/lib/httpd/modules/
libtool: install: error: cannot install `’ to a directory not ending in /root/php5/php-5.1.2/libs
apxs:Error: Command failed with rc=65536

Which it seems that NO ONE on like any forums has a fix for.

It shouldn’t attempt to copy a .la file to your httpd modules dir, only the .so. What’s the config command that you used?

Using the following configure inside phpcompile

./configure --with-apxs2=/usr/sbin/apxs --prefix=/usr --bindir=/usr/bin --mandir=/usr/share/man --disable-debug --disable-rpath --with-bz2 --with-db4=/usr --with-curl --with-exec-dir=/usr/bin --with-freetype-dir=/usr --with-png-dir=/usr --with-gd --with-gdbm --with-gettext --with-ncurses=shared --with-gmp --with-iconv --with-jpeg-dir=/usr --with-openssl --with-png --with-xml --with-expat-dir=/usr --with-dom --with-dom-xslt --with-dom-exslt --with-xmlrpc --with-readline --with-pcre=/usr --with-zlib --with-mhash --with-ldap --with-mcrypt --with-mysql=/usr --with-unixODBC=/usr --with-pgsql --without-oci8 --with-snmp=/usr --enable-ucd-snmp-hack --enable-bcmath --enable-exif --enable-ftp --enable-magic-quotes --enable-safe-mode --enable-sockets --enable-sysvsem --enable-sysvshm --enable-discard-path --enable-yp --enable-wddx --enable-memory-limit --enable-bcmath --enable-shmop --enable-calendar --enable-dbx --enable-dio --enable-mcal --enable-mbstring --enable-mbstr-enc-trans --enable-mbregex --enable-inline-optimization --enable-gd-native-ttf --enable-pic

I am using CentOS 3.6 but that really shouldnt matter should it since i get no errors apart from the ‘make install’ one thats above.

It could be some odd setting on your system. Try the following:

  1. make clean

  2. ./phpcompile

  3. pico libtool inside your PHP source directory and search for these lines (line 5937 on mine):

if test "$inst_prefix_dir" = "$destdir"; then
  $echo "$modename: error: cannot install \`$file' to a directory not$

Comment them out by adding # in front of them.

  1. make
  2. make install

See how that goes

Even though ive commented it, it still spits out that error.

if test “$inst_prefix_dir” = “$destdir”; then

     #   $echo "$modename: error: cannot install \`$file' to a directory not ending in $libdir" 1>&2
      #  exit $EXIT_FAILURE

The full error is:

Installing PHP SAPI module:       apache2handler
/usr/lib/httpd/build/ SH_LIBTOOL='/usr/lib/apr/build/libtool' /usr/lib/httpd/modules
/usr/lib/apr/build/libtool --mode=install cp /usr/lib/httpd/modules/
libtool: install: error: cannot install `' to a directory not ending in /root/php5/php-5.1.2/libs
apxs:Error: Command failed with rc=65536
make: *** [install-sapi] Error 1

After making those changes to the APR LIBTOOL it appears to work… But im just getting what appears to be CLI output everywhere. my phpinfo page returns the php config but only as raw text like you would see in the CLI. That and other webpages are blank.

That’s good news then :slight_smile:

Any ideas why i cant get anything from the web? i try to get phpinfo from interworx and just get raw output. But anything from the web just tries to download and yes i have got the:

AddType application/x-httpd-php .php
lines etc. So close but yet so far :slight_smile:

Actually its working fine, just my dodgy site not wanting to work. Cheers for your help

What was wrong? Loadmodule line absent? Or needed to restart apache post-install?

I dont quite know but the module line had several whitespaces before the path:

LoadModule phpX <these should be whitespaces but vbulletin takes them away> /usr/lib/what/ever/directory/it/was