How to install or upgrade PHP from 5.4 to 5.5 on CentOS/RHEL 6/7
CentOS 7 by default installs PHP 5.4. At the end of September PHP 5.4 came to the end of it’s life, no longer receiving security updates. A number of systems still run PHP 5.4. This guide will take you through installing PHP 5.5 fresh on a CentOS/RHEL 6/7 machine or upgrading an existing system.
New features included in PHP 5.5 –
- Included generators and coroutines.
- Included the at last keyword.
- Included an improved secret key hashing API.
- Added support for constant array/string de-referencing.
- Included scalar class name determination by means of ::class.
- Included backing for utilizing empty() on the result of function calls and different expressions.
- Included support for list() builds in for every statements.
- Included the Zend OPcache extension for opcode reserving.
- The GD library has been moved up to form 2.1 including new capacities and enhancing existing functionality and so on.
Fresh Installation of PHP
CentOS 7 (including EPEL install)
wget http://dl.fedoraproject.org/pub/epel/7/x86_64/e/epel-release-7-5.noarch.rpm
wget http://rpms.famillecollet.com/enterprise/remi-release-7.rpm
rpm -Uvh remi-release-7*.rpm epel-release-7*.rpm
If you already have EPEL installed:
wget http://rpms.famillecollet.com/enterprise/remi-release-7.rpm
rpm -Uvh remi-release-7*.rpm
CentOS 6 (including EPEL install)
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
If you already have EPEL installed:
wget http://rpms.famillecollet.com/enterprise/remi-release-6.rpm
rpm -Uvh remi-release-6*.rpm
Installing PHP
yum -y install php55w php55w-opcache
Extra modules which may be relevant to your PHP scripts functioning correctly –
yum -y install php55w-xml php55w-mcrypt php55w-gd php55w-devel php55w-mysql php55w-intl php55w-mbstring
Start HTTP
service httpd restart
Upgrade Existing Installation of PHP 5.4
It is risky to upgrade an existing system, I would highly recommend you only do this if you are proficient. Usually it is easier to install on a new system, and transfer files over. Make sure to create a backup before proceeding.
To get started, we need to first check the current version of PHP.
php -v
PHP 5.4.35 (cli) (built: Dec 14 2014 03:09:18)
Copyright (c) 1997-2014 The PHP Group
Zend Engine v2.6.0, Copyright (c) 1998-2015 Zend Technologies
with Zend OPcache v7.0.4-dev, Copyright (c) 1999-2015, by Zend Technologies
CentOS 7 (including EPEL install)
wget http://dl.fedoraproject.org/pub/epel/7/x86_64/e/epel-release-7-5.noarch.rpm
wget http://rpms.famillecollet.com/enterprise/remi-release-7.rpm
rpm -Uvh remi-release-7*.rpm epel-release-7*.rpm
If you already have EPEL installed:
wget http://rpms.famillecollet.com/enterprise/remi-release-7.rpm
rpm -Uvh remi-release-7*.rpm
CentOS 6 (including EPEL install)
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
If you already have EPEL installed:
wget http://rpms.famillecollet.com/enterprise/remi-release-6.rpm
rpm -Uvh remi-release-6*.rpm
You then need to install yum-plugin-replace
yum install yum-plugin-replace
If yum cannot find the plugin, add the RPM –
rpm -UvH http://repo.webtatic.com/yum/el7/x86_64/RPMS/yum-plugin-replace-0.2.7-1.ius.el7.noarch.rpm
Try the command again.
Then, to replace PHP with the latest version. Do NOT run the -y flag, you must ensure that you know what is being replaced.
yum replace php-common --replace-with=php55w-common
Then, restart Apache/HTTP
service httpd restart
And check your PHP version
php -v
PHP 5.5.30 (cli) (built: Oct 16 2015 07:35:20)
Copyright (c) 1997-2015 The PHP Group
Zend Engine v2.5.0, Copyright (c) 1998-2015 Zend Technologies
with Zend OPcache v7.0.6-dev, Copyright (c) 1999-2015, by Zend Technologies
And you’re done! 🙂