Quickie how-to for getting PHP upgraded on CentOS 5

Today I had to get PHP upgraded from 5.1 to 5.2.X on someone else’s server and didn’t have time to screw around. I have a PHP configuration that I’ve used in the past but it frankly can take too long to get set up, if time is of the essence. So here are my “quickie steps” (tested for the current release, 5.2.11 on CentOS 32- and 64-bit). Follow these and you can be running in 20 minutes (if you type fast!):

Download the latest stable PHP build from http://php.net and extract.

# back stuff up, just in case
cp -rv /usr/lib/php/modules /usr/lib/php/modules-bak
cp -v /usr/lib/httpd/modules/libphp5.so  /usr/lib/httpd/modules/libphp5.so.bak
# or, if you're on 64-bit:
mv /usr/lib64/php/modules /usr/lib64/php/modules-bak
ln -s /usr/local/lib/20090626/ /usr/lib/php64/modules
cp -v /usr/lib64/httpd/modules/libphp5.so  /usr/lib64/httpd/modules/libphp5.so.bak
# the ones after mysql-devel might be optional if you're pressed for time, but they're needed by phpmyadmin etc.
yum install httpd-devel mysql-devel libmcrypt-devel libxml2-devel zlib-devel libmhash curl-devel
# you may need to do the following, if compiling on 64-bit
export LDFLAGS=-L/usr/lib64/mysql
./configure --with-apxs2 --with-mysql=shared --with-mcrypt --enable-mbstring --with-curl --with-zlib
make clean && make install
# if the build fails, you may need to recompile libmcrypt as per http://marc.info/?l=php-install&m=108030891925096&w=2
wget http://sourceforge.net/projects/mhash/files/mhash/
make clean && make install
wget http://sourceforge.net/projects/mcrypt/files/Libmcrypt/2.5.8/libmcrypt-2.5.8.tar.gz/download
./configure --disable-posix-threads
make clean && make install
cd libltdl
./configure --enable-ltdl-install
make clean && make install
# now for some reason by default PHP might be looking in /usr/local/lib for the php.ini, so symlink to it
cd /usr/local/lib
ln –s /etc/php.ini

Also add the following to /etc/php.ini (in case it doesn’t know to scan /etc/php.d by default):

; Allow or prevent persistent links.
mysql.allow_persistent = On

You’ll need to add the same for mbstring.so, etc. if you built them as well.

Got a few minutes left? If so install eaccelerator:

make install
cp /usr/local/lib/php/extensions/no-debug-non-zts-20060613/eaccelerator.so  /usr/lib/php/modules
mkdir /tmp/eaccelerator
chmod 777 /tmp/eaccelerator

and add the following to /etc/php.ini:
eaccelerator.cache_dir = "/tmp/eaccelerator"
eaccelerator.enable = "1"
eaccelerator.debug = "0"
eaccelerator.optimizer = "1"

Update 12/12/2010: To build a more sophisticated 32-bit version of PHP 5.3.4, do the following:

yum install httpd-devel mysql-devel libmcrypt-devel libxml2-devel zlib-devel libmhash curl-devel libtidy-devel pcre-devel libjpeg-devel libpng-devel freetype-devel gmp-devel
'./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-config-file-path=/etc' '--with-config-file-scan-dir=/etc/php.d' '--disable-debug' '--with-pic' \
'--disable-rpath' '--with-pear' '--with-curl' '--with-exec-dir=/usr/bin' \
'--enable-gd-native-ttf' '--without-gdbm' '--with-gettext' '--with-gmp' '--with-kerberos' \
'--with-iconv' '--with-openssl' '--with-zlib' '--with-layout=GNU' \
'--enable-magic-quotes' '--enable-sockets' '--enable-sysvsem' '--enable-sysvshm' '--enable-sysvmsg'  \
'--enable-ucd-snmp-hack'  '--without-sqlite' \
'--with-libxml-dir=/usr' '--enable-pcntl' \
'--enable-mbstring=shared' '--enable-mbregex'  \
'--with-gd=shared' '--enable-dba=shared' '--with-xmlrpc=shared' '--with-ldap=shared' \
'--with-mysql=shared,/usr' '--with-mysqli=mysqlnd' '--enable-dom=shared'  \
'--enable-soap=shared' '--enable-xmlreader=shared' '--enable-xmlwriter=shared' '--with-mcrypt'  '--with-mhash'  \
'--with-freetype-dir=/usr/lib' \
'--with-apxs2=/usr/sbin/apxs' \
'--disable-pdo' '--without-pdo-sqlite' '--with-tidy' '--with-pcre-dir' '--with-jpeg-dir' '--enable-zip'

Leave a comment

Your email address will not be published. Required fields are marked *