How to update and install php 5.3 and php 5.2 CentOS webtatic repo
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
1 |
rpm -Uvh http://repo.webtatic.com/yum/centos/5/latest.rpm |
- Centos 6
1 |
rpm -Uvh http://repo.webtatic.com/yum/centos/6/latest.rpm |
Next we run the normal installation procedure, but first enable the repository by using the parameter –enablerepo=webtatic.
1 |
yum --enablerepo=webtatic install php |
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:
1 |
yum --enablerepo=webtatic update php |
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:
1 |
error_reporting = E_ALL |
to:
1 |
error_reporting = E_ALL & ~E_DEPRECATED |
Do not forget, after making changes to your php.ini file, you need to restart your web server.
1 |
service httpd restart |
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:
1 |
yum --enablerepo=webtatic --exclude=php*5.3* update php |
Or we can just add that parameter directly to the repository file:
1 |
/etc/yum.repos.d/webtatic.repo |
on a new line:
1 |
exclude=php*5.3* |
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:
1 |
yum install gcc make 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 |
Then we start by downloading the package php-5.2.17.tar.gz :
1 2 3 |
wget http://museum.php.net/php5/php-5.2.17.tar.gz tar -zxvf php-5.2.17.tar.gz cd php-5.2.17 |
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.
1 |
./configure --prefix=/usr/local/php52 --with-apxs2=/usr/sbin/apxs --with-config-file-path=/usr/local/lib/php52/ --disable-posix --enable-bcmath --enable-calendar --enable-exif --enable-fastcgi --enable-ftp --enable-gd-native-ttf --enable-libxml --enable-magic-quotes --enable-mbstring --enable-pdo --enable-soap --enable-sockets --enable-wddx --enable-zip --with-bz2 --with-curl --with-curlwrappers --with-freetype-dir --with-gd --with-gettext --with-imap --with-imap-ssl --with-jpeg-dir --with-kerberos --with-libexpat-dir --with-libxml-dir --with-libxml-dir --with-mcrypt --with-mhash --with-mime-magic --with-mysql --with-mysqli --with-openssl --with-openssl-dir --with-pcre-regex --with-pdo-mysql --with-pdo-sqlite --with-pic --with-png-dir --with-pspell --with-sqlite --with-ttf --with-xmlrpc --with-xpm-dir --with-xsl --with-zlib --with-zlib-dir |
The result should be similar to:
1 2 3 4 5 6 7 8 9 10 |
+--------------------------------------------------------------------+ | License: | | This software is subject to the PHP License, available in this | | distribution in the file LICENSE. By continuing this installation | | process, you are bound by the terms of this license agreement. | | If you do not agree with the terms of this license, you must abort | | the installation process at this point. | +--------------------------------------------------------------------+ Thank you for using PHP. |
Then run the make and make install to compile it and install php on your system.
1 2 3 |
make clean make -j 2 make install |
The end result would have php working on your server, bellow is a phpinfo() page:
That’s it for now, if you like it, don’t forget to share it and comment.