Tech Journal Back to Tech Journal

How can I compile a new version of PHP, to upgrade my existing installation?

First off, a little trick: You can get the options used to compile PHP by running:

php -i

We're interested in one of the first lines, the one called Configure Command. In my current setup, I get this output:

PHP Version => 5.2.8

System => Linux #3 Tue Jul 25 11:35:24 IDT 2006 i686
Build Date => Oct 14 2009 14:05:37
Configure Command =>  './configure'  '--build=i686-redhat-linux-gnu' '--host=i686-redhat-linux-gnu' '--target=i386-redhat-lin
ux-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' '--cache-file=../config.cache' '--with-libdi
r=lib' '--with-config-file-path=/etc' '--with-config-file-scan-dir=/etc/php.d' '--disable-debug' '--with-pic' '--disable-rpat
h' '--without-pear' '--with-bz2' '--with-curl' '--with-exec-dir=/usr/bin' '--with-freetype-dir=/usr' '--with-png-dir=/usr' '-
-enable-gd-native-ttf' '--without-gdbm' '--with-gettext' '--with-gmp' '--with-iconv' '--with-jpeg-dir=/usr' '--with-openssl'
'--without-pspell' '--with-expat-dir=/usr' '--with-pcre-regex=/usr' '--with-zlib' '--with-layout=GNU' '--enable-exif' '--enab
le-ftp' '--enable-magic-quotes' '--enable-sockets' '--enable-sysvsem' '--enable-sysvshm' '--enable-sysvmsg' '--enable-track-v
ars' '--enable-trans-sid' '--enable-yp' '--enable-wddx' '--with-kerberos' '--enable-ucd-snmp-hack' '--with-unixODBC=shared,/u
sr' '--enable-memory-limit' '--enable-shmop' '--enable-calendar' '--enable-dbx' '--enable-dio' '--with-mime-magic=/etc/httpd/
conf/magic' '--with-sqlite' '--with-libxml-dir=/usr' '--with-apxs2=/usr/sbin/apxs' '--with-mysql' '--with-gd' '--without-odbc
' '--enable-dom' '--disable-dba' '--without-unixODBC' '--enable-pdo'
Server API => Command Line Interface
Virtual Directory Support => disabled
Configuration File (php.ini) Path => /etc
Loaded Configuration File => /etc/php.ini
Scan this dir for additional .ini files => /etc/php.d
additional .ini files parsed => (none)
PHP API => 20041225
PHP Extension => 20060613
Zend Extension => 220060519
Debug Build => no

You can see from the Configure Command that the command-line used to run the configure script was:

'./configure'  '--build=i686-redhat-linux-gnu' '--host=i686-redhat-linux-gnu' 
'--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' '--cache-file=../config.cache' '--with-libdir=lib' 
'--with-config-file-path=/etc' '--with-config-file-scan-dir=/etc/php.d' '--disable-debug' 
'--with-pic' '--disable-rpath' '--without-pear' '--with-bz2' '--with-curl' '--with-exec-dir=/usr/bin' 
'--with-freetype-dir=/usr' '--with-png-dir=/usr' '--enable-gd-native-ttf' '--without-gdbm' 
'--with-gettext' '--with-gmp' '--with-iconv' '--with-jpeg-dir=/usr' '--with-openssl' 
'--without-pspell' '--with-expat-dir=/usr' '--with-pcre-regex=/usr' '--with-zlib' 
'--with-layout=GNU' '--enable-exif' '--enable-ftp' '--enable-magic-quotes' 
'--enable-sockets' '--enable-sysvsem' '--enable-sysvshm' '--enable-sysvmsg' 
'--enable-track-vars' '--enable-trans-sid' '--enable-yp' '--enable-wddx' 
'--with-kerberos' '--enable-ucd-snmp-hack' '--with-unixODBC=shared,/usr' 
'--enable-memory-limit' '--enable-shmop' '--enable-calendar' '--enable-dbx' '--enable-dio' 
'--with-mime-magic=/etc/httpd/conf/magic' '--with-sqlite' '--with-libxml-dir=/usr' 
'--with-apxs2=/usr/sbin/apxs' '--with-mysql' '--with-gd' '--without-odbc' '--enable-dom' 
'--disable-dba' '--without-unixODBC' '--enable-pdo'

(If you don't have access to a shell, you can create a .php page and call the phpinfo() function, which will output the same information.)

Now that we have the command-line used to call configure, we can use the usual mantra:

./configure insert options here make make test make install

About compiling the extensions: it's simpler to compile the extensions directly into the php executable and apache-module. But if you want to do it manually, enter the ext subdirectory within the php source directory, and do the following:

cp -v modules/$ /usr/lib/php/modules/

Replace $EXTNAME with the name of the extension, and change /usr/lib/php/modules/ to whereever you want to store the extentions.

Last updated on 2009-10-21 07:18:03 -0700, by Shalom Craimer

Back to Tech Journal