How to Upgrade PHP 5.3.x to 5.4.x or 5.5.x on CentOS
A guide to successfully upgrade PHP version from 5.3.x to 5.4.x or 5.5.x on CentOS using yum command (CLI). Tutorial with pics suitable for beginners. For your information, many default LAMP stack installations come with PHP v5.3.x as it’s known as most stable version (and it has reached end of life after getting last update). But recently, many want to upgrade to 5.4 which is known as newest stable version (with minimal memory footprint) or 5.5 which is known as bleeding-edge newest version.
Should I Upgrade to Latest PHP Version?
Newer is not always better (or faster) but newer version always offers new features, improvements and enhancements which are not always available in its old version. But again, even loaded with all those new stuff, it is not always better than its old one. So, which one is you?
I want to experience with latest newest features? Upgrade to 5.5.x
I want the most stable performance? Upgrade to 5.4.x
I want the stable version that’s always compatible with many PHP scripts? Stick with 5.3.x
According to this blog, PHP 5.3 is a bit faster than 5.4 and 5.5 (approximately 7% faster than 5.4). But, from version 5.4 and upwards, the memory consumption has dropped significantly. The benchmark was done with a conclusion that PHP version 5.4 and 5.5 are practically the same with regards to speed and memory consumption. So the decision is yours.
How to install or upgrade to PHP 7 – An extremely fast PHP version
How to Upgrade on CentOS?
This tutorial was performed on CentOS 6.5 x86 (32-bit) vps.
What you’ll need:
- Proper knowledge to use Putty or Terminal
- Basic SSH command ability
- LAMP Stack (or at least Apache and PHP 5.3 are installed)
Step 1 – Login to your server via Command Line (Putty or Terminal)
Step 2 – Add EPEL and Remi repositories onto your system:
On CentOS 6.x 32-bit
wget http://dl.fedoraproject.org/pub/epel/6/i386/epel-release-6-8.noarch.rpm wget http://rpms.famillecollet.com/enterprise/remi-release-6.rpm rpm -Uvh remi-release-6*.rpm epel-release-6*.rpm
On CentOS 6.x x86_64 (64-bit)
wget http://dl.fedoraproject.org/pub/epel/6/x86_64/epel-release-6-8.noarch.rpm wget http://rpms.famillecollet.com/enterprise/remi-release-6.rpm rpm -Uvh remi-release-6*.rpm epel-release-6*.rpm
Step 3 – Now enable your newly added Remi repo. Open the /etc/yum.repos.d/remi.repo repository file using a text editor of your choice – I use Nano:
Step 4 – Edit enabled=0 line to enabled=1:
4.a – Update to PHP 5.4, in [remi] section:
4.b – Update to PHP 5.5, in [remi-php55] section:
4.c – Bonus – Update to PHP 5.6 (beta version), in [remi-php56] section:
once done, Save changes (Control+O) and exit (Control+X)
Step 5 – Now update yum:
yum update -y
Step 6 – Done. Now you can check using this command:
In this example I got:
PHP 5.6.0 Beta 2
Now you can test your PHP script on your browser and hope everything still runs smoothly.
Preventing The Mess
You may have to edit old httpd.conf and php.conf (if your srcipt went messed up).
Step 1 – Make backup of php.conf file:
mv /etc/httpd/conf.d/php.conf /etc/httpd/conf.d/php.conf.bak
Step 2 – Then edit httpd.conf file:
Step 3 – You have to find every line with php_ in it, and remove it (or simply add #). If you have found out that there is at least one line per domain, so be sure to remove them all. Once done, save and exit.
Step 4 – Finally restart httpd service (Apache):
service httpd restart
Also, you may also want to upgrade MySQL using this command:
mysql_upgrade -u root -p
That’s it. Do not forget to follow me on Twitter @serveromdotcom or download ServerMom’s official Android app to get faster information update. adiós!
I went through this but still am at PHP Version 5.3.3
try to clean the cache of repo with:
# yum clean all
Can we do that for Zpanel 10.1.1 that have 5.3.3? Can we follow that for 5.5.X ?
Thx for this!
I did the entire provedure and I was still having PHP 5.3.3
Then I did # yum clean all and repeat everything but I’m still having PHP5.3.3
Is there anythig else to solve the prolem?