How to install PHP 7.* 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.* you should read the appropriate migration guide:
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.*
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, 7.1 or 7.2:
That’s it, you now have a functioning PHP 7.* 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)
- Linux Mint 20 “Ulyana” what’s new - 1 July 2020
- How to install NextCloud 19 server on CentOS 8.x and 7.x - 24 June 2020
- How to install NextCloud 19 on Ubuntu 18.04/19.04/19.10/20.04 - 17 June 2020