Setup CentOS 6.4 to run PHP 5.5

I always use the PHP mysql native driver aka mysqlnd when I develop something serious in PHP. Because of many reasons, both of performance and software design nature.

I’ve learned the hard way that the trio mysqlnd – CentOS 6 – PHP 5.3 is never a happy story, unless you have a system administrator sitting around to compile PHP 5.3 with the mysqlnd option in configure command every time you setup another web server. I don’t want to go further to other implications, to be honest I hate being logged in as root and I try to make my visits as short as possible. Sometimes I wonder how sysadmins can like their job.

So, I took a leap of faith, I upgraded all my servers to CentOS 6.4 and I installed PHP 5.5 which ships with mysqlnd and did all the management with yum. Sweet.

It is a bit trickier than it seems though. The default PHP that ships with CentOS 6.4 is PHP 5.3.

So, to make a long story short, from this point I will assume that you are logged in as root or you have root privileges (you are in the sudoers file, call it whatever you want).

By running the following commands:

rpm -Uvh http://download.fedoraproject.org/pub/epel/6/i386/epel-release-6-8.noarch.rpm
rpm -Uvh http://rpms.famillecollet.com/enterprise/remi-release-6.rpm

you solve all dependency issues with epel and remi on CentOS 6.

Then, by running the following command, you install PHP 5.5.

yum --enablerepo=remi,remi-test install httpd php php-common

For extra goodies, you can run the following command:

yum --enablerepo=remi,remi-test install php-pecl-apc php-cli php-pear php-pdo php-mysqlnd php-pgsql php-pecl-mongo php-sqlite php-pecl-memcache php-pecl-memcached php-gd php-mbstring php-mcrypt php-xml

EDIT:

It seems that something changed with the remi repo since I installed PHP 5.5 last time. The command that installs PHP 5.5 currently is the following:

yum --enablerepo=remi,remi-php55 install php-pecl-apc php-cli php-pear php-pdo php-mysqlnd php-pgsql php-pecl-mongo php-sqlite php-pecl-memcache php-pecl-memcached php-gd php-mbstring php-mcrypt php-xml

Now, restart your httpd service and set it to boot automatically:

service httpd restart
chkconfig --levels 235 httpd on

Now run:

php --version

to see whether the correct version of PHP was installed.

Also, go ahead and create a phpinfo(); file in the root of your webserver to see whether mysqlnd is now activated along with other features.

Don’t forget to add a rule to your firewall if this is missing.

iptables -I INPUT -p tcp --dport 80 -j ACCEPT

Hope this helps. It helped me having it written down.

Leave a Reply