Sunday, March 12, 2006

Quickly Re-configuring a Source-Based PHP Installation

I recently had the experience of having to add several extensions to an installed version of PHP (v4) that was originally compiled from source on a Red Hat Linux box. The procedure below I came up with to save me the time and hassle of re-typing the long "configure" command, with all the options.

First, make a backup of your original php shared library - this will usually be in the "libexec" directory under your main Apache root. In my case, it was in /usr/local/apache/libexec/ This will be replaced by the install process.

Next, I had to figure out what options the original PHP was compiled with. This wasn't too hard. To start, cd into your PHP build directory (this should be where you originally unpacked the PHP source code), and take a look at the output of 'php -i'. At the top, you'll see a line like this:

Configure Command => './configure'

'--with-apxs=/usr/local/apache/bin/apxs' '--with-xml' '--with-mm' '--enable-bcmath' '--enable-calendar' '--enable-ftp' '--with-gd' '--with-jpeg-dir=/usr/local' '--with-png-dir=/usr' '--with-xpm-dir=/usr/X11R6' '--enable-magic-quotes' '--with-mm' '--with-mysql=/usr' '--enable-discard-path' '--with-pear' '--enable-sockets' '--enable-track-vars' '--with-ttf' '--with-freetype-dir=/usr' '--enable-gd-native-ttf' '--enable-versioning' '--with-zip' '--with-zlib' '--with-mime-magic'

This is great, but doesn't lend itself to copy-n-paste, with the extra quotes and characters present. A simple text filter 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:

root@server [~/]# php -i | grep Configure | sed -e "s/'//g" -e "s/^Conf.*=> //g"

./configure --with-apxs=/usr/local/apache/bin/apxs --with-xml --with-mm --enable-bcmath --enable-calendar --enable-ftp --with-gd --with-jpeg-dir=/usr/local --with-png-dir=/usr --with-xpm-dir=/usr/X11R6 --enable-magic-quotes --with-mm --with-mysql=/usr --enable-discard-path --with-pear --enable-sockets --enable-track-vars --with-ttf --with-freetype-dir=/usr --enable-gd-native-ttf --enable-versioning --with-zip --with-zlib --with-mime-magic

At this point, just copy-n-paste the line output by the filter to a command prompt, and just add the extensions you want to the end of the list, then hit enter (in this case, I added ' --with-curl --with-mcrypt' to the end of the list). Then type 'make' - if there are no errors, type 'make install' and the new php shared library is now installed.

Type 'apachectl graceful', or reload your Apache config some other way (this Apache was also installed from source, the binary packaged version of Apache can have its configuration reloaded on Red Hat with 'service httpd reload'), the new PHP modules should now be active and ready for use.

Technorati Tags: , ,

No comments: