In a CentOS 5.2 Server, there PHP 5.2.4 and due to which PCI complaince test failed. We were in requirement to upgrade PHP to latest stable version. While writing this article, we found 5.3.5 as latest stable release of PHP. Describing here the steps taken to download, install PHP 5.3.5.
Step 1. Check existing PHP modules and Install pre-requisites libraries/apps
As the first step, you should get list of installed PHP modules so that you can incude them with newer PHP as well otherwise functionality of your site/application can break.
Get list of all PHP module installed in Server:
$ cd /usr/src $ php -m | grep -v -e Modules] -e ^$ > php-installed-modules
here, the file php-installed-modules will contain all php modules present in Server at this moment, some are prebuilt in PHP while othere needs to be included with a ‘–with-
On a fully functional production Server, to compile newer version of PHP, you need to have source library or other required header/files of your modules/packages to include their support. This can vary from Server to Server, here I’m pasting command I used to install required libraries etc:
$ yum install mcrypt libmcrypt mhash libmhash libxml2-devel openssl-devel openldap openldap-devel bzip2-devel curl-devel libjpeg-devel libpng-devel gmp-devel mysql-devel aspell-devel readline readline-devel httpd-devel zlib zlib-devel
Step 2. Download and uncompress PHP source code
$ wget http://us3.php.net/distributions/php-5.3.5.tar.gz $ tar xzf php-5.3.5.tar.gz $ cd php-5.3.5
Step 3. Configure source, compile and install PHP
Make list of modules you need to install along with PHP and check help of configure script to know how to include/enable them.
$ ./configure --help > /tmp/phelp
Now you can browse /tmp/phelp file and check syntax of all required modules you need.
After making list of modules you need with PHP and figuring out what to put in configure command to enable them, start configure script to generate configuration files:
$ ./configure --prefix=/usr --with-apxs2=/usr/sbin/apxs --with-curl --enable-exif --enable-ftp --with-gd --with-gettext --with-gmp --with-mhash --with-ldap --enable-mbstring --with-mysql=/usr/include/mysql/ --with-mysqli --with-openssl --enable-pcntl --with-pdo-mysql --with-zlib-dir --with-pspell --with-readline --enable-shmop --enable-sockets --enable-sysvmsg --enable-sysvsem --enable-sysvshm --enable-wddx --with-xmlrpc --enable-zip --with-zlib
You need to be vigilent as it may fail due to some requirement not met. You have to install required library or provide path to requested file/library and start this configure again until it completed successfully.
After successful configuration, its easy to proceed, start compilation and installation
$ make $ make install
Step 4. Verify php installation
Verify that you have latest PHP through command line:
$ php -v PHP 5.3.5 (cli) (built: Mar 17 2011 09:12:54) Copyright (c) 1997-2010 The PHP Group Zend Engine v2.3.0, Copyright (c) 1998-2010 Zend Technologies
You need to restart Apache service to make it recognise new installed PHP:
$ service httpd restart
You can now verify PHP version thorugh browser also. Let me know if you run into an issue by posting comment here.
Similar articles on this site that you may found useful:
* Upgrade PHP to latest using yum upgrade instead of compiling.
* Install html2pspdf library to create PDF files using PHP
* Detect directory or file changes in Linux
* Ensuring secure access to production Linux Servers