Home » Developer Tips » CentOS 6 and PHP 5.4

php-logo

CentOS 6 and PHP 5.4

on October 10 | by | in Developer Tips , Linux

One of the things that makes CentOS awesome is its stability but it is also one of the drawbacks due to outdated PHP packages. Generally speaking most of the packages are clean, stable and have a limited amount of bugs in them. RedHAT Enterprise team does a good job at ensuring this, and the CentOS team makes it even better. The problem is this takes time it is really easy to have packages like PHP evolving faster than the CentOS team can handle. Lets fix that using remi and repoforge.

 

Remi Repository for CentOS 6 and PHP 5.4

The Remi repo is a project to maintain the latest version of LAMP stack (Linux Apache Mysql PHP) for rpm based distros like CentOS, Redhat, Fedora, etc. We need to tell our CentOS install about this repo as CentOS only ships with the “offical” repos. SSH to your server and download the repo file to your repositories directory.

cd /etc/yum.repos.d/
wget http://rpms.famillecollet.com/enterprise/remi.repo

 

CentOS 6 and PHP 5.4 Yum install

Now that we have the repo file available, we just need to enable and install the php packages. That is all done in one yum command.

yum --enablerepo=remi install php php-bcmath php-cli php-common php-dba php-devel php-embedded php-enchant php-gd php-imap php-intl php-ldap php-mbstring php-mysqlnd php-odbc php-pdo php-pear php-pecl-apc php-pecl-apc-devel php-pecl-memcache php-pgsql php-process php-pspell php-recode php-snmp php-soap php-tidy php-xml php-xmlrpc

Now you have PHP installed, restart your apache service “/etc/init.d/apache restart” and your scripts will now run with PHP 5.4. There is some extra functionality I like to install on most of my web boxes: php-mcrypt , php-json (public functions) , and mongodb library for example, those are covered next and are optional.
 

PHP-Mcrypt

I still do not really understand why this package is not included by default because its the interface to a lot of the encryption methods that a lot of open source is built on, but its easy to install using repoforge and remi.

yum install http://pkgs.repoforge.org/libmcrypt/libmcrypt-2.5.7-1.2.el6.rf.`uname -m`.rpm
yum --enablerepo=remi install php-mcrypt

 

PHP-JSON

Some modules you may use in the future require direct access to the php-json module (couchbase for example) but by default this is not available. It is an easy fix however!

echo "; Enable json extension module" > /etc/php.d/json.ini
echo extension=json.so >> /etc/php.d/json.ini

 

Mongo DB

Mongo DB is a popular NoSQL datastore. In order to connect to a MongoDB server you need to install the module from pecl.

pecl install --alldeps mongo
echo "; Enable mongo extension module" > /etc/php.d/mongo.ini
echo extension=mongo.so >> /etc/php.d/mongo.ini

 

PHP-FPM

If you are using nginx instead of apache you need to use php-fpm instead of the default install. Never fear, there is a remi package for this!

yum --enablerepo=remi install php-fpm

 
 
Well, thats all folks. You now have CentOS 6 and PHP 5.4 configured and ready to go. Any questions or comments, please let us know in the comments section below!

«

Scroll to top