Download, compile, install and configure php 5.3.5 in Linux

by jagbir on March 17, 2011

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-” option or needs to enable them while compilation. You need to check how these modules can be included by checking help of configure script.

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
$ tar xzf php-5.3.5.tar.gz
$ cd php-5.3.5

RELATED: Upgrade PHP using yum upgrade instead of compiling.

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

  • Christian Kaps

    When you set expose_php to off then the security scanner cannot recognize the installed PHP version. So you mustn’t install any new PHP version.

  • Vaibhav Mishra

    Hello Christian,

    Wonderful article and steps that you have mentioned. Extremely helpful even when I am new in LINUX world.

    Just to add few queries in my this mail, could you be able to answer my few queires as below:

    1. I need to install configure PHP5.3.5 in RHEL 5.6 with the following statement:>

    “Compile php-5.3.5 from source with following options gd, pear, zlib, bcmath, sqlite-utf8, apxs2, png-dir, jpeg-dir, enable-sockets, gd-native-ttf, freetype-dir, xpm-dir, mbstring, gettext, session, json, ttf, xsl”

    So which step should I change as per your steps given in your fantastic solution above.

    2. Is it possible to install PHP via YUM?

    Many thanks for your time in reading my mail.



  • jagbir

    @Vaibhav, here are words from me about your points:
    1. I’ve given command to compile php from source code, you just to tweak it little to include modules required.
    2. Yes, you can install php via yum but you may have to install some repository first which will have latest php in it like CentALT. you can check here how to install yum repository:

  • VM

    Thanks Jagbir,

    First I am wondering what is a match between a Finance Expert and LINUX Expert…. :-)

    However, what it means when used as –enable and –prefix.

    I will try above steps and may bug you if any help needed incase any error reported or I completly stuck. Hope I must not.

    Take care,

  • jagbir

    @VM thanks for comment. In general a prefix specify directory where libraries/config/binaries etc should get installed and enable used to enable the mode/module/setting etc.

    Being good in finance and Linux is a killer combination I must say ;)

  • VM


    Also do I need to uninstall any previous PHP versions installed in in my RHEL box?


  • jagbir

    @VM I don’t think so, any earlier version will get upgraded/replaced by newer one.

  • VM


    Hope you are fine.

    I couple of warning and many of them are fixed however not sure about the one given below: Any inputs:

    Platform: RHEL 5.6

    configure: warning: You will need re2c 0.13.4 or later if you want to regenerate PHP parsers.
    configure: warning: bison versions supported for regeneration of the Zend/PHP parsers: 1.28 1.35 1.75 1.875 2.0 2.1 2.2 2.3 2.4 2.4.1 2.4.2 2.4.3 (found: none).

    Thanks in advance,

  • VM


    I have been through with BISON and re2c warning and problem which I was facing with. Here is the information can be useful for others to troubleshoot similar issue:

    If facing re2c warning as well,
    Please download the lastest RPM from opensource available on internet.
    May be wget should work as well.

    Ignore BISON warning (if this is the only warning which you might be facing)
    Do “make” and then “make test” (without quote). If all is well here,
    Go for “make install” (will take just a few seconds)
    Check your PHP version installed PHP -v

    Many thanks to you and everyone helped me get this done successful.

  • jagbir

    Hi VM, Glad to know that you’ve overcome the issues. Keep up the spirit of trying again and again, its one of the vital quality of any Admin.

  • Rafiq

    Many thanks. Keep it up.

  • jagbir

    Thanks Rafiq for your comment.

  • Pingback: bored

  • Shiro


    I had done your step, my PHP is run smoothly with your code.
    However, I would like to add more PHP extension. What step should I do?

    I tried, and my step as follow
    $ /etc/init.d/httpd stop
    $ yum install freetype-devel.x86_64
    $ ./configuration –with-freetype-dir=/usr
    $ make clean
    $ make
    $ make install
    $ /etc/init.d/httpd start

    I also remove the semicolon in php.ini

    However, I went to phpinfo(). It still did not included the extension. Anything I miss?

Previous post:

Next post: