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)
- How to install Fedora 31 in 10 easy steps - 6 November 2019
- How to install Ubuntu 19.10 Eoan Ermine in 10 easy steps! - 30 October 2019
- How to install NextCloud 17 server on CentOS 7.x - 23 October 2019