Introduction
PHP 7, which was released on December 3, 2015, promises substantial speed improvements over previous versions of the language, along with new features like scalar type hinting. This guide explains how to quickly upgrade an Apache or Nginx web server running PHP 5.x (any release) to PHP 7, using community-provided packages.
Warning: As with most major-version language releases, it's best to wait a little while before switching to PHP 7 in production. In the meanwhile, it's a good time to test your applications for compatibility with the new release, perform benchmarks, and familiarize yourself with new language features.
If you have installed phpMyAdmin for database management, it is strongly recommended that you wait for official CentOS PHP 7 packages before upgrading, as phpMyAdmin packages do not yet support the upgrade. If you're running any other services or applications with active users, it is safest to first test this process in a staging environment.
Prerequisites
This guide assumes that you are running PHP 5.x on CentOS 7, using either mod_php
in conjunction with Apache, or PHP-FPM in conjunction with Nginx. It also assumes that you have a non-root user configured with sudo
privileges for administrative tasks.
Subscribing to the IUS Community Project Repository
Since PHP 7.x is not yet packaged in official repositories for the major distributions, we'll have to rely on a third-party source. Several repositories offer PHP 7 RPM files. We'll use the IUS repository.
IUS offers an installation script for subscribing to their repository and importing associated GPG keys. Make sure you're in your home directory, and retrieve the script using curl
:
- cd ~
- curl 'https://setup.ius.io/' -o setup-ius.sh
Run the script:
sudo bash setup-ius.sh
Upgrading mod_php
with Apache
This section describes the upgrade process for a system using Apache as the web server and mod_php
to execute PHP code. If, instead, you are running Nginx and PHP-FPM, skip ahead to the next section.
Begin by removing existing PHP packages. Press y and hit Enter to continue when prompted.
sudo yum remove php-cli mod_php php-common
Install the new PHP 7 packages from IUS. Again, press y and Enter when prompted.
sudo yum install mod_php70u php70u-cli php70u-mysqlnd
Finally, restart Apache to load the new version ofmod_php
:
sudo apachectl restart
You can check on the status of Apache, which is managed by thehttpd
systemd
unit, usingsystemctl
:
systemctl status httpd