Install latest PHP 5 on your CentOS server from source.

Today we will show you how to install PHP 5.3.8 on a CentOS 5.6 server from source code. At the time of writing this article 5.8.3 is the newest stable release of PHP 5. First you will need to make sure you do not have PHP installed from your CentOS package manager. You can run:

php -v

If you get a “command not found” error, then you’re good to go. If the output is version information from PHP, you should check yum for the installed packages and remove them.

PHP has a few prerequisite applications that must be installed in order to complete our build. These applications are easily installed through yum. If you’re making a custom build with your own configuration then some of these may not be required for your personal custom installation. If you’re not building your own custom PHP configuration go ahead and run this long multi-line command:

yum -y install perl-DBI mysql mysql-devel libxml2-devel \ 
openssl-devel bzip2-devel curl-devel libjpeg-devel \
libpng-devel freetype-devel libc-client-devel krb5-devel \
libmcrypt-devel libmhash-devel mysql-devel ncurses-devel \
pspell-devel readline-devel libtool-ltdl libtool-ltdl-devel \
http httpd-devel

Now we need to download the latest php source code tarball via wget. You can check their site for the latest version here: php.net and get the updated download link. Otherwise you can use the link provided here if you want version 5.3.8:

cd ~
mkdir src
cd src
wget http://us.php.net/get/php-5.3.8.tar.bz2/from/this/mirror
tar xvjpf php-5*.tar.bz2
cd php-5*

Now we are ready to build. You will need a PHP configuration to build against. We recommend using ours, especially if you installed all of the dependencies per our recommendation above. Our configuration includes all of the basics you would want; bz2, curl, exif, ftp, gettext, mbstring, mcrypt, mhash, ncurses, openssl, pspell, soap, sockets, zip, zlib, freetype, jpeg, png, gd, imap, imap-ssl, mysql, readline and kerberos can be found in our config. Changes to this configuration may require other prerequisites.

For 32-bit systems please run:

'./configure' '--build=i686-redhat-linux-gnu' \
'--host=i686-redhat-linux-gnu' \
'--target=i686-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' \
'--with-apxs2=/usr/sbin/apxs' '--with-bz2' '--with-curl' \
'--enable-exif' '--enable-ftp' '--with-gettext' \
'--enable-mbstring' '--with-mcrypt' '--with-mhash' \
'--with-ncurses' '--with-openssl' '--with-openssl-dir=/usr' \
'--with-pspell' '--enable-soap' '--enable-sockets' \
'--enable-zip' '--with-zlib' '--with-freetype-dir=/usr' \
'--with-jpeg-dir=/usr' '--with-png-dir=/usr' '--with-gd' \
'--with-imap' '--with-imap-ssl' '--with-mysql=/usr' \
'--with-mysqli=/usr/bin/mysql_config' '--with-readline' \
'--with-kerberos=/usr'

For 64-bit systems please run:

'./configure' '--build=x86_64-redhat-linux-gnu' \
'--host=x86_64-redhat-linux-gnu' \
'--target=x86_64-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/lib64' '--libexecdir=/usr/libexec' \
'--localstatedir=/var' '--sharedstatedir=/usr/com' \
'--mandir=/usr/share/man' '--infodir=/usr/share/info' \
'--cache-file=../config.cache' '--with-libdir=lib64' \
'--with-config-file-path=/etc' \
'--with-config-file-scan-dir=/etc/php.d' \
'--with-apxs2=/usr/sbin/apxs' '--with-bz2' '--with-curl' \
'--enable-exif' '--enable-ftp' '--with-gettext' \
'--enable-mbstring' '--with-mcrypt' '--with-mhash' \
'--with-ncurses' '--with-openssl' '--with-openssl-dir=/usr' \
'--with-pspell' '--enable-soap' '--enable-sockets' \
'--enable-zip' '--with-zlib' '--with-freetype-dir=/usr' \
'--with-jpeg-dir=/usr' '--with-png-dir=/usr' '--with-gd' \
'--with-imap' '--with-imap-ssl' '--with-mysql=/usr' \
'--with-mysqli=/usr/bin/mysql_config' '--with-readline' \
'--with-kerberos=/usr'

If there were no errors while making the configuration then you’re ready to build. If there were errors you will need to research them or submit a comment and I’ll suggest something! Let’s go ahead and make/install this PHP 5 build:

make -j4
make install

If you’re running out of memory (VPS users!) you can remove the “-j4” from the “make” command to reduce the amount of threads used.

If there were no errors you should be able to check that PHP works now:

php -v

You should see the latest version of PHP.

Add a Comment