Frames Modems Help Home Page Chipsets Search No Frames
Diary Entries See also Site Info & Diary.
2 April 2004 The pain of installing PHP 4.3.5 on Red Hat 8...
 

7 days ago I thought to write a little routine to let me see a graph of the last 100 days hits on my sites. It would only take a day or so. A week later, and still it isn’t finished. The first requirement was for routines to calculate the Date and Time, then--because the SQL for the page hits was slow & couldn’t be optimised further--a cache routine. Next, on to the graph; I test out “simple1.php” and:

   Warning: imagecreatetruecolor(): requires GD 2.0 or later in
   /usr/share/pear/Image/Graph.php on line 1111

Red Hat 8 provides PHP 4.2.2 and, whilst this has gd, it doesn’t have gd2. There is also no method of obtaining an updated .rpm with the latest php inside it (although there is an unofficial php-4.3.3 rpm for RH7-8). Cue soundtrack of background wailing, gnashing of teeth, etc. etc..

Red Hat 8 & later provide Apache 2. On the PHP Installation : Servers-Apache 2.0 page it says with emphasis at the top:

   Warning:
   Do not use Apache 2.0 and PHP in a production environment neither on Unix nor on Windows.

A little lower down it says:

   ... the recommended setup is to use PHP 4.3.0 or later
   with the most recent version of Apache2.

(It also says: “PHP 4.2.3 works with Apache 2.0.39, don't use any other version of Apache with PHP 4.2.3.” Mine is 2.0.40, so this does not affect Olivia.) The Home page also proudly announced the release of PHP 4.3.5, “by far the most stable release of PHP to date and it is recommended that all users upgrade to this release where possible”. I was sold! I would do it!! That was 3 days ago.

 

I ftp-ed php-4.3.5.tar.gz onto the server from my own machine - there are better ways to do this on a server, but this was the quickest for me at the time. Pages that I found particularly useful in what follows are Compiling Apache 2 and PHP (mod_php) on Linux and Apache Compile HOWTO - mod_php and its prerequisites plus the PHP Installation page : Apache 2 - documentation. There was also a very good page at root0.net but it has gone, so I dropped the page extracted from the Google cache on to my free web-space (PHP compilation on RH7); bear in mind that some links on that page will not work.

One of the things that was useful was the original configure command for PHP. This is at the top of the <?php phpinfo() ?> page. My (RH8 default) command is ludicrously long: “./configure '--host=i386-redhat-linux' '--build=i386-redhat-linux' '--target=i386-redhat-linux-gnu' '--program-prefix=' '--prefix=/usr' '--exec-prefix=/usr' '--bindir=/usr/bin' '--sbindir=/usr/sbin' '--sysconfdir=/etc' '--datadir=/usr/share' '--includedir=/usr/include' '--libdir=/usr/lib' '--libexecdir=/usr/libexec' '--localstatedir=/var' '--sharedstatedir=/usr/com' '--mandir=/usr/share/man' '--infodir=/usr/share/info' '--prefix=/usr' '--with-config-file-path=/etc' '--enable-force-cgi-redirect' '--disable-debug' '--enable-pic' '--disable-rpath' '--enable-inline-optimization' '--with-bz2' '--with-db3' '--with-curl' '--with-dom=/usr' '--with-exec-dir=/usr/bin' '--with-freetype-dir=/usr' '--with-png-dir=/usr' '--with-gd' '--enable-gd-native-ttf' '--with-ttf' '--with-gdbm' '--with-gettext' '--with-ncurses' '--with-gmp' '--with-iconv' '--with-jpeg-dir=/usr' '--with-openssl' '--with-png' '--with-pspell' '--with-regex=system' '--with-xml' '--with-expat-dir=/usr' '--with-zlib' '--with-layout=GNU' '--enable-bcmath' '--enable-exif' '--enable-ftp' '--enable-magic-quotes' '--enable-safe-mode' '--enable-sockets' '--enable-sysvsem' '--enable-sysvshm' '--enable-discard-path' '--enable-track-vars' '--enable-trans-sid' '--enable-yp' '--enable-wddx' '--without-oci8' '--with-pear=/usr/share/pear' '--with-imap=shared' '--with-imap-ssl' '--with-kerberos=/usr/kerberos' '--with-ldap=shared' '--with-mysql=shared,/usr' '--with-pgsql=shared' '--with-snmp=shared,/usr' '--with-snmp=shared' '--enable-ucd-snmp-hack' '--with-unixODBC=shared' '--enable-memory-limit' '--enable-bcmath' '--enable-shmop' '--enable-versioning' '--enable-calendar' '--enable-dbx' '--enable-dio' '--enable-mcal' '--with-apxs2=/usr/sbin/apxs'” and also incorrect! Apache2 has moved the configuration for PHP from httpd.conf into php.conf, and has changed the text from AddType application/x-httpd-php .php to (this is the config file as it currently exists):

   # cat /etc/httpd/conf.d/php.conf
   #
   # PHP is an HTML-embedded scripting language which attempts to make it
   # easy for developers to write dynamically generated web pages.
   #

   LoadModule php4_module modules/libphp4.so

   #
   # Cause the PHP interpreter handle files with a .php extension.
   #
   <Files *.php>
       SetOutputFilter PHP
       SetInputFilter PHP
       LimitRequestBody 524288
   </Files>

   #
   # Add index.php to the list of files that will be served as directory
   # indexes.
   #
   DirectoryIndex index.php

This also means that the switch in the configure command ('--with-apxs2=/usr/sbin/apxs') is wrong, since it refers to the Apache 1.3 AddType configuration, whereas Apache 2 uses Filters & the command should be: '--with-apxs2filter=/usr/sbin/apxs'. It only took me half a day to sort that out. I made sure that httpd.conf, php.conf + php.ini were backed up beforehand. The following are all useful commands to get info on Apache before beginning (and to check after if you compile Apache as well):

   # /usr/sbin/httpd -t
   # /usr/sbin/httpd -v
   # /usr/sbin/httpd -l
   # /usr/sbin/httpd -V
 

The first steps were to get the php-file into position, unzip then extract the tar-ball (it creates it’s own directory structure), then change to the root of that tree:

   # cp php-4.3.5.tar.gz /usr/src/
   # cd /usr/src
   # gunzip php-4.3.5.tar.gz     ==> php-4.3.5.tar
   # tar -xvf php-4.3.5.tar      ==> dir php-4.3.5 in location where unzipped
   # cd php-4.3.5

Now run the huge (better small - hindsight reflection) configure command:

   # ./configure ... '--with-apxs2filter'
   Configuring SAPI modules
   checking for AOLserver support... no
   checking for Apache 1.x module support via DSO through APXS... no
   checking for Apache 1.x module support... no
   checking for member fd in BUFF *... no
   checking for mod_charset compatibility option... no
   checking for Apache 2.0 filter-module support via DSO through APXS...

   Sorry, I cannot run apxs.  Possible reasons follow:

   1. Perl is not installed
   2. apxs was not found. Try to pass the path using --with-apxs2filter=/path/to/apxs
   3. Apache was not built using --enable-so (the apxs usage page is displayed)

   The output of apxs follows:
   ./configure: line 4344: apxs: command not found
   configure: error: Aborting

Bummer. Using locate apx (# find / -name apx* is a good alternative if the file has been recently added) it was clear that--in spite of a working Apache plus the pre-existence of the configure switch--apxs was not on the system.

I did find my precise problem via Google and the necessary rpm is here BUT DO NOT GO THERE! It led me down a side alley which was a dead-end and I got mugged:

   # rpm -Fvh -v httpd-devel-2.0.40-11.9.i386.rpm
   ...
   warning: httpd-devel-2.0.40-11.9.i386.rpm: V3 DSA signature: NOKEY, key ID db42a60e
   D: opening  db index       /var/lib/rpm/Name rdonly mode=0x0
   D: found 0 source and 0 binary packages
   ...

...and I rebuilt the rpm database, and the server fell over, and a fire in Manchester meant that Lance did not have any phones and could not restart it, and... I went to bed after 2 days effort, shattered, getting nowhere.

If your system is built from RED Hat RPMs and you have yum the solution is as simple as can be.

 

These are the 2 paragraphs that will save you 3 or more days of head-banging frustration:

Part 1: The necessary overview in compiling programs such as PHP on Red Hat is that it is necessary to have installed devel rpms rather than the bog-standard rpms. As one good example, httpd-2.0.40-11.9.i386.rpm had already been used to update Apache on the server, but what was needed was httpd-devel-2.0.40-11.9.i386.rpm in order to have access to the apxs script. This example applies to another 14 packages that needed to be installed. Installing from the devel rpm gives access to the header & other files which php needs in order to be able to compile.

Part 2: The very best way to install these RPMs on Red Hat is using YUM (Yellowdog Updater Modified):

   # yum install unixODBC-devel
   Gathering package information from servers
   Getting headers from: Red Hat Linux 8.0 base
   Getting headers from: Fedora Legacy utilities for Red Hat Linux 8.0
   Getting headers from: Red Hat Linux 8.0 updates
   Finding updated packages
   Downloading needed headers
   Resolving dependencies
   ...Dependencies resolved
   I will do the following:
   [install: unixODBC-devel.i386]
   I will install/upgrade these to satisfy the depedencies:
   [deps: unixODBC.i386]
   [deps: cups-libs.i386]
   [deps: XFree86-Mesa-libGLU.i386]
   [deps: Xft.i386]
   [deps: qt.i386]
   Is this ok [y/N]: y
   Getting unixODBC-devel-2.2.2-3.i386.rpm
   Getting unixODBC-2.2.2-3.i386.rpm
   Getting cups-libs-1.1.17-0.9.i386.rpm
   Getting XFree86-Mesa-libGLU-4.2.1-23.i386.rpm
   Getting qt-3.0.5-17.i386.rpm
   Calculating available disk space - this could take a bit
   cups-libs 100 % done
   XFree86-Mesa-libGLU 100 % done
   Xft 100 % done
   qt 100 % done
   unixODBC 100 % done
   unixODBC-devel 100 % done
   Installed:  unixODBC-devel.i386
   Updated:  unixODBC.i386 cups-libs.i386 XFree86-Mesa-libGLU.i386 Xft.i386 qt.i386
   Transaction(s) Complete

Easy-peasy, honest. Look at the lines above: one install instruction (yum install unixODBC-devel) then 6 RPMs downloaded and installed, all dependencies sorted. I also had problems with snmp & db3 (there is an astonishing fix for php-4.3.4 on amd64 and for compiling in BerkeleyDB support on FreeBSD) but I did not need them, so here are the packages that eventually were installed:

   # yum install httpd-devel          ===>httpd-devel-2.0.40-11.9.i386.rpm
   # yum install bzip2-devel          ===>bzip2-devel-1.0.2-5.i386.rpm
   # yum install libjpeg-devel        ===>libjpeg-devel-6b-21.i386.rpm
   # yum install libpng-devel         ===>libpng-devel-1.2.2-8.i386.rpm
   # yum install freetype-devel       ===>freetype-devel-2.1.2-7.i386.rpm
   # yum install imap-devel           ===>imap-devel-2001a-15.i386.rpm
   # yum install mysql-devel          ===>mysql-devel-3.23.58-1.80.i386.rpm
   # yum install postgresql-devel     ===>postgresql-devel-7.2.4-5.80.i386.rpm
   # yum install pspell-devel         ===>pspell-devel-0.12.2-14.i386.rpm
   # yum install net-snmp-devel       ===>net-snmp-devel-5.0.9-2.80.1.i386.rpm
   # yum install unixODBC-devel       ===>unixODBC-devel-2.2.2-3.i386.rpm
                                      ===>unixODBC-2.2.2-3.i386.rpm
                                      ===>cups-libs-1.1.17-0.9.i386.rpm
                                      ===>XFree86-Mesa-libGLU-4.2.1-23.i386.rpm
                                      ===>qt-3.0.5-17.i386.rpm

All of these--except for unixODBC--were already installed on the system, but not the devel version. These are the error messages that initiated installation; they all appeared during configure except for the last, which appeared during make:

   Configuring extensions
   ...
   checking for BZip2 support... yes
   checking for BZip2 in default path... not found
   configure: error: Please reinstall the BZip2 distribution

   (then)
   configure: error: libjpeg.(a|so) not found.

   (then)
   configure: error: libpng.(a|so) not found.

   (then)
   If configure fails try --with-xpm-dir=<DIR>
   configure: error: freetype2 not found!

   (this changed to:)
   If configure fails try --with-xpm-dir=<DIR>
   no - FreeType 2.x is to be used instead
   ...
   configure: error: Cannot find rfc822.h. Please check your IMAP installation.

   (then)
   configure: error: Cannot find MySQL header files under /usr

   (then)
   checking for PostgreSQL support... yes, shared
   configure: error: Cannot find libpq-fe.h. Please specify correct PostgreSQL installation path

   (then)
   checking for PSPELL support... yes
   configure: error: Cannot find pspell

   (then)
   ...
   Generating files
   updating cache ./config.cache
   creating ./config.status
   creating php4.spec
   creating main/build-defs.h
   creating scripts/phpize
   creating scripts/php-config
   creating sapi/cli/php.1
   creating main/php_config.h
   creating main/internal_functions.c
   creating main/internal_functions_cli.c
   +--------------------------------------------------------------------+
   | License:                                                           |
   | This software is subject to the PHP License, available in this     |
   | distribution in the file LICENSE.  By continuing this installation |
   | process, you are bound by the terms of this license agreement.     |
   | If you do not agree with the terms of this license, you must abort |
   | the installation process at this point.                            |
   +--------------------------------------------------------------------+
   |                          *** NOTE ***                              |
   |            The default for register_globals is now OFF!            |
   |                                                                    |
   | If your application relies on register_globals being ON, you       |
   | should explicitly set it to on in your php.ini file.               |
   | Note that you are strongly encouraged to read                      |
   | http://www.php.net/manual/en/security.registerglobals.php          |
   | about the implications of having register_globals set to on, and   |
   | avoid using it if possible.                                        |
   +--------------------------------------------------------------------+

   Thank you for using PHP.

   (Wee-hah! but make gave:)
   # make
   ...
   In file included from /usr/src/php-4.3.5/ext/odbc/php_odbc.c:37:
   /usr/src/php-4.3.5/ext/odbc/php_odbc_includes.h:118:17: sql.h: No such file or directory
   /usr/src/php-4.3.5/ext/odbc/php_odbc_includes.h:119:20: sqlext.h: No such file or directory
   ...
   /usr/src/php-4.3.5/ext/odbc/php_odbc_includes.h:255: confused by earlier errors, bailing out
   make: *** [ext/odbc/php_odbc.lo] Error 1

   (then, after install unixODBC-devel:)
   # make
   ...
   Build complete.
   (It is safe to ignore warnings about tempnam and tmpnam).

Phew! The final configure command used was: “./configure '--host=i386-redhat-linux' '--build=i386-redhat-linux' '--target=i386-redhat-linux-gnu' '--program-prefix=' '--prefix=/usr' '--exec-prefix=/usr' '--bindir=/usr/bin' '--sbindir=/usr/sbin' '--sysconfdir=/etc' '--datadir=/usr/share' '--includedir=/usr/include' '--libdir=/usr/lib' '--libexecdir=/usr/libexec' '--localstatedir=/var' '--sharedstatedir=/usr/com' '--mandir=/usr/share/man' '--infodir=/usr/share/info' '--prefix=/usr' '--with-config-file-path=/etc' '--enable-force-cgi-redirect' '--disable-debug' '--enable-pic' '--disable-rpath' '--enable-inline-optimization' '--with-bz2' '--with-curl' '--with-dom=/usr' '--with-exec-dir=/usr/bin' '--with-freetype-dir=/usr' '--with-png-dir=/usr' '--with-gd' '--enable-gd-native-ttf' '--with-ttf' '--with-gdbm' '--with-gettext' '--with-ncurses' '--with-gmp' '--with-iconv' '--with-jpeg-dir=/usr' '--with-openssl' '--with-png' '--with-pspell' '--with-regex=system' '--with-xml' '--with-expat-dir=/usr' '--with-zlib' '--with-layout=GNU' '--enable-bcmath' '--enable-exif' '--enable-ftp' '--enable-magic-quotes' '--enable-safe-mode' '--enable-sockets' '--enable-sysvsem' '--enable-sysvshm' '--enable-discard-path' '--enable-track-vars' '--enable-trans-sid' '--enable-yp' '--enable-wddx' '--without-oci8' '--with-pear=/usr/share/pear' '--with-imap=shared' '--with-imap-ssl' '--with-kerberos=/usr/kerberos' '--with-ldap=shared' '--with-mysql=shared,/usr' '--with-pgsql=shared' '--with-unixODBC=shared' '--enable-memory-limit' '--enable-bcmath' '--enable-shmop' '--enable-versioning' '--enable-calendar' '--enable-dbx' '--enable-dio' '--enable-mcal' '--with-apxs2filter=/usr/sbin/apxs'”.

It was about 4 am in the morning, and a perfect time to do the make install that would be the final act (apart from modifications to the various config files, plus an apachectl graceful to restart Apache). I was torn between doing it straightaway & waiting for the weekend (quieter), but for some reason had another look at the PHP home page. At the top it said: “PHP 4.3.6RC1 released: This release addresses 2 major bugs introduced in the 4.3.5 release ... thread-safe (ZTS) builds ... incorrect handling of daylight savings time”. What! I download “by far the most stable release of PHP to date”, spend 3 days learning how to install the brute, and 7 days after release it has “2 major bugs”!!!

I hope that something in the above has helped you. Personally, I am going to get on with another urgent issue, and leave PHP as it is at the moment. After reading the above, I slunk off to bed, and in the morning began to write this little article.