Upgrade Your Apache to a Newer PHP Version

Posted on Fri 08 June 2018 in Sysadmin

Upgrading PHP from 7.0 to 7.1 or 7.2 on Ubuntu 16.04 LTS is almost trivial as this blog post (in German) explains:

First, add a PPA (personal package archive):

sudo apt-get install -y python-software-properties (falls nicht bereits installiert)
sudo add-apt-repository -y ppa:ondrej/php
sudo apt-get update -y

Second, upgrade all packages:

sudo apt-get -y update && apt-get -y upgrade && apt-get -y dist-upgrade

Third, if you use Nextcloud, install all required PHP packages (for PHP 7.1 and 7.2 at the same time in this example):

sudo apt-get install -y php7.1 libapache2-mod-php7.1 php7.1-cli php7.1-common php7.1-mbstring php7.1-gd php7.1-intl php7.1-xml php7.1-mysql php7.1-mcrypt php7.1-zip php7.1-dev php7.1-curl libapache2-mod-php7.2 php7.2-cli php7.2-common php7.2-mbstring php7.2-gd php7.2-intl php7.2-xml php7.2-mysql php7.2-zip php7.2-dev php7.2-curl

Then, add the following code to your /etc/php/7.1/apache2/php.ini or /etc/php/7.1/apache2/php.ini, respectively:

opcache.enable=1
opcache.enable_cli=1
opcache.interned_strings_buffer=8
opcache.max_accelerated_files=10000
opcache.memory_consumption=128
opcache.save_comments=1
opcache.revalidate_freq=1

Finally, enable the new PHP modules in your Apache:

sudo a2dismod php7.0
sudo a2enmod php7.1
service apache2 restart