‘Clean’ upgrade to PHP 7.* (CentOS / Debian / Ubuntu)

Earlier this year, I wrote a short article: 80% of the web powered by PHP. Also, in the article it was noted that more than 90% of PHP based websites are still using PHP 5. This remains true today. It must be said however, in the past 6 months, there’s been more upgrades to PHP 5.6 than to PHP 7. So there’s progress, albeit slow. A few factors preventing mass upgrades to PHP 7 are compatibly, lack of PHP 7 built-in support by Linux distros and maybe some not fully aware of PHP 7 efficiency benefits.

The easy part is tracking down which lines code aren’t PHP 7 ready. You can do this with PHP7cc. php7cc is a command line tool designed to make migration from PHP 5.3-5.6 to PHP 7 easier by searching your existing code and generating a report containing file names, line numbers and description of each incompatibility issue. Using it is as easy as: PHP7cc is no longer supported, use one of these PHP compatibility check methods instead. The following upgrade instructions will replace PHP rather than installing separate versions…

CentOS 6: Upgrade to PHP 7

CentOS: Upgrade to PHP 7

For a clean in-place upgrade to PHP 7 on CentOS 6 add EPEL and Remi repositories:

yum install https://dl.fedoraproject.org/pub/epel/epel-release-latest-6.noarch.rpm
yum install http://rpms.remirepo.net/enterprise/remi-release-6.rpm

Install yum-utils:

yum install yum-utils

Select which version of PHP 7 you would like:

yum-config-manager --enable remi-php71

or one of these:

yum-config-manager --enable remi-php70
yum-config-manager --enable remi-php72

Upgrade PHP 7.

yum update

 

CentOS 7: Upgrade to PHP 7

For a clean in-place upgrade to PHP 7 on CentOS 7 add EPEL and Remi repositories:

yum install https://dl.fedoraproject.org/pub/epel/epel-release-latest-7.noarch.rpm
yum install http://rpms.remirepo.net/enterprise/remi-release-7.rpm

Install yum-utils:

yum install yum-utils

Select which version of PHP 7 you would like:

yum-config-manager --enable remi-php71

or one of these:

yum-config-manager --enable remi-php70
yum-config-manager --enable remi-php72

Upgrade to PHP 7.

yum update

 

Debian 8/9: Upgrade to PHP 7

Add Sury’s PHP repository:

sudo apt-get install apt-transport-https lsb-release ca-certificates
sudo wget -O /etc/apt/trusted.gpg.d/php.gpg https://packages.sury.org/php/apt.gpg
sudo echo "deb https://packages.sury.org/php/ $(lsb_release -sc) main" > /etc/apt/sources.list.d/php.list

Upgrade to PHP 7:

sudo apt-get update && sudo apt-get upgrade

Ubuntu 14 to 16: Upgrade to PHP 7

Add Sury’s Personal Package Archives (PPA):

sudo add-apt-repository ppa:ondrej/php

Upgrade to PHP 7:

sudo apt-get update && sudo apt-get upgrade

 

Access PHP 7 without adding repositories

For Debian/Ubuntu, if you are a bit wary of using deb.sury.org, you can instead upgrade your distribution to Ubuntu 16 or Debian 9. Both support PHP 7.0 (not 7.1+). Add suggestions other than compiling below.

Edit: For CentOS 6/7 also see IUS repo for php. (Thanks @godman_8)

Tags: , , ,



Top ↑