How to install PHP 7 (and 7.1) on CentOS 7
PHP 7 is a huge revolution in the PHP world. Bringing up to 100% speed gain under certain workloads. Still, PHP 7 adoption is not as widespread as it should. As a matter of fact CentOS 7 still uses PHP 5.4, although it’s safe, with some tricks you can install PHP 7 and enjoy all of its benefits on CentOS 7.
PHP 7 is great, fast and absolutely one of the best re-engineering a language has ever seen. But beware, applications are not automatically compatible. Although a certain degree of backward compatibility is guaranteed, there are many deprecations and many removals (e.g. the mysql driver has been removed in favour of mysqli or MYSQL_PDO). Before upgrading to PHP 7.0 you should read the migration guide, and if you intend to install PHP 7.1, there’s a guide too.
CentOS 7 still uses PHP 5.4, and there’s a good reason Red Hat is still maintaining this version. Following this guide you will add repositories that are not part of CentOS by themselves (epel and webtatic). Installing these packages will allow you to leverage your package manager without recompiling PHP. This is especially good, but if you’re on RHEL 7 (rather than CentOS7) you will probably break Red Hat Product support. Installing these package is at user’s own risk.
Installing PHP 7(.1)
The process is quite straightforward, first we need to install epel and the webtatic repository:
# yum install epel-release
# rpm -Uvh https://mirror.webtatic.com/yum/el7/webtatic-release.rpm
Once done, you can decide to go for version 7 or 7.1:
That’s it, you now have a functioning PHP 7(.1) installation, you can simply verify so (if you installed PHP-cli) by issuing:
# php --version
PHP 7.1.4 (cli) (built: Apr 15 2017 08:07:03) ( NTS )
Copyright (c) 1997-2017 The PHP Group
Zend Engine v3.1.0, Copyright (c) 1998-2017 Zend Technologies
This one is for advanced users. If you already have PHP 5.4 installed, you might want to upgrade without removing PHP altogether. In this cases you can use yum-plugin-replace to achieve such behaviour. Be careful, this procedure is prone to errors and can lead to undesired behaviours. Once again: be careful.
Latest posts by mark (see all)
- Firefox 57: get ready for a Quantum leap - 15 November 2017
- MINIX: the OTHER operating system in your Intel computer - 8 November 2017
- Ubuntu 18.04 LTS new features: Bionic Beaver and new theme - 1 November 2017