How to update and install php 5.3 and php 5.2 CentOS webtatic repo

→ Are you a new visitor? Please visit the page guidance for new visitors ←

How to install php 5.3 and php 5.2

A few weeks ago I had a client that needed an old php version updated, normally you can easily update or install php 5.3 directly from repository, but unfortunately there are a few scripts that require an older version of php installed, this is tricky when there aren’t any sources available. Luckily I have here a source or repository, whatever you wish to call it, that can be used in such situations. In this article I’m going to show you a direct and simple way to install php 5.3 and php 5.2 directly using yum package installer.

For starters we need to install the rpm from webtatic.com so that we are able to install packages directly from them. For this we can run the bellow command:

  • Centos 5

  • Centos 6

Next we run the normal installation procedure, but first enable the repository by using the parameter –enablerepo=webtatic.

Of course, if we already have php already installed and we want to update its version to the latest version, we can do this in the same way:

Do keep in mind that for php 5.3 you will need to specify that you do not wish to view deprecated errors in your logs. This helps in removing the annoying errors that are usually more for informing us that the function specific is deprecated. We can do this by editing the php.ini file and changing the value:

to:

Do not forget, after making changes to your php.ini file, you need to restart your web server.

Update PHP 5.2.17 on CentOS 5

For specially updating the php version 5.2 on centos 5 we can use the –exclude=php*5.3* parameter like so:

Or we can just add that parameter directly to the repository file:

on a new line:

Compiling PHP 5.2.17 on CentOS 6

Unfortunately the php 5.2.17 version can no longer be installed from repos, sad but that’s how it is with old versions. Well the only way here is to manually compile php. First make sure you have gcc, make and httpd-devel libxml2-devel bzip2-devel openssl-devel curl-devel gd-devel libc-client-devel libmcrypt-devel libmhash-devel mysql55-devel aspell-devel libxslt-devel installed as these are needed:

Then we start by downloading the package php-5.2.17.tar.gz :

We will now need to configure it, I’ve added –with-apxs2=/usr/sbin/apxs to add mod_php directly to apache. It should then work with your normal apache installation as long as you are only using mod_php.

The result should be similar to:

Then run the make and make install to compile it and install php on your system.

The end result would have php working on your server, bellow is a phpinfo() page:

Apache 2 and phpinfo page

Apache 2 and phpinfo page

That’s it for now, if you like it, don’t forget to share it and comment.

  • akki

    Getting error while compiling checking for xml2-config path…
    configure: error: xml2-config not found. Please check your libxml2 installation.

    • http://www.yourhowto.net Bogdan

      Thank you for letting me know. I had a bare installation of CentOS and tested this. It was missing some dependencies that were needed for compiling, I’ve tested it, completed the installation ( this time on a bare installation ) and it should work properly:
      Use the bellow command to install the dependencies first, before running compile:

  • evgeny

    thanks !

  • Gigiel Duru

    Hi. i cannot compile php 5.2.17. The error is bellow. Would you be so kind to help me with a hint?

    Thank you

    No targets specified and no makefile found. Stop.

    • http://www.yourhowto.net/ Raica Bogdan

      Well that error means that you are basically missing the Makefile.
      Have you follow the steps above? You need to run the configure command first for the Makefile to be generated.

  • Gigiel Duru

    Yes, I followed the stepts, but I have an error for ./configure: libjpg is missing

    • http://www.yourhowto.net/ Raica Bogdan

      Ok, well that’s strange, GD should have that when installing dependencies, try installing libjpg-devel then:

      Then run again ./configure and then make and make install.
      Please let me know if that fixes the issue and I’ll add it to the dependencies list.

  • Alessandro Cipriani

    Well! this wiki worked fine on Centos 6.5, but i add on ./configure command this:

    –with-libdir=lib64

    Thx

    alex

    • http://www.yourhowto.net/ Raica Bogdan

      Thank you, will leave it here in the comment for others to see.

  • Poorya

    Thank you for this help but I receive the following error after I run make -j 2

    /usr/bin/ld: cannot find -lltdl

    • http://www.yourhowto.net/ Raica Bogdan

      Try installing libtool-ltdl-devel , this should however be installed already.

      yum install libtool-ltdl-devel

      • Poorya

        Thanks the installation has been completed but I cannot now run phpinfo function with httpd, also when I enter php -i in command shell it give me “command not found”. is there anything else I should do?

        • http://www.yourhowto.net/ Raica Bogdan

          Well that’s normal, this is a manual compiled php version. It will install CLI binaries if you look closer in the folder:

          Installing PHP CLI binary: /usr/local/php52/bin/

          so to use it from command line, you can use:
          /usr/local/php52/bin/php -i

          or add the path to your shell paths:
          export PATH=$PATH:/usr/local/php52/bin/

          then it will work from cli:
          [root@sv1 php]# php -v
          PHP 5.2.17 (cli) (built: Oct 8 2013 16:27:23)
          Copyright (c) 1997-2010 The PHP Group
          Zend Engine v2.2.0, Copyright (c) 1998-2010 Zend Technologies

Request an article ←