Quickly Upgrading or Re-configuring a Source-Based PHP Installation


Several times in the past I've had to upgrade or reconfigure a PHP installation that was originally compiled from source on a GNU/Linux server. The compile-time configure options that PHP was originally built with are readily available in the 'php -i' output, but the output format does not lend itself well for use in the actual configuration step. Below I'll show you how to perform the upgrade, with a trick I came up with to use the 'php -i' output in the configure command.

First, make a backup of your original installation - this will usually be under your main Apache root and is given by the --prefix argument in the 'php -i' output. In a recent upgrade, it was in /opt/apache2.

tar czpf ~/apache-php-backup.tgz /opt/apache2

Next, take a look at the output of 'php -i'. Make sure to run the version your webserver is using, in my case '/opt/apache2/bin/php -i'. At the top, you'll see a line like this:

Configure Command => './configure' '--with-apxs2=/opt/apache2/bin/apxs' '--prefix=/opt/apache2' '--with-zlib=/opt/oss' '--with-openssl=/opt/oss' '--with-mysql=/opt/oss' '--with-mysqli=/opt/oss/bin/mysql_config' '--with-libxml-dir=/opt/oss' '--with-gd' '--enable-gd-native-ttf' '--with-jpeg-dir=/opt/oss' '--with-png-dir=/opt/oss' '--enable-zip' '--enable-soap' '--with-pear'

This is great, but doesn't lend itself to copy-n-paste, with the extra quotes and characters present. A simple text filter using grep and sed will do nicely. The exact configure command to use as a base can be extracted with this:

php -i | grep Configure | sed -e "s/'//g" -e "s/^Conf.*=> //g"

Note that there are two spaces after the '=>'. Here is what the output looks like:

./configure --with-apxs2=/opt/apache2/bin/apxs --prefix=/opt/apache2 --with-zlib=/opt/oss --with-openssl=/opt/oss --with-mysql=/opt/oss --with-mysqli=/opt/oss/bin/mysql_config --with-libxml-dir=/opt/oss --with-gd --enable-gd-native-ttf --with-jpeg-dir=/opt/oss --with-png-dir=/opt/oss --enable-zip --enable-soap --with-pear

At this point, just copy-n-paste the line output by the filter to a command prompt. Make any changes or add any extensions you want to the end of the list, then hit enter to start the configuration process. Next type 'make' - if there are no errors, type 'make install' and the upgraded PHP is now installed. Restart apache with 'apachectl graceful'. The updated PHP should now be active and in use.