Ayesh Karunaratne: Full-time traveler, freelance software architect and security researcher
Wed, 2017-11-29 01:34
PHP 7.2 is just around the corner, and here is a quick note how to upgrade to 7.2. I wrote about upgrading to PHP 7.1 when it was released, and this is a continuation of that post.
1. Add PPA
We use Ondřej Surý's awesome PHP PPA. It already has PHP 7.2, so we'll add the PPA and update the package information.
sudo add-apt-repository ppa:ondrej/php
sudo apt update
sudo apt 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 sh -c 'echo "deb https://packages.sury.org/php/ $(lsb_release -sc) main" > /etc/apt/sources.list.d/php.list'
sudo apt update
2. Current PHP packages
This only applies if you are upgrading from a previous version. Note down the current PHP packages you have, so we can reinstall them for PHP 7.2.
dpkg -l | grep php | tee packages.txt
This will save your current packages to
packages.txt file in your working directory.
3. Install PHP 7.2
sudo apt install php7.2 php7.2-common php7.2-cli php7.2-fpm
This will install the bare basic packages you'd need to get started with PHP 7.2. Note that
php7.2-fpm package is used for your web server integration. If you are using Apache with
prefork MPM (type
apachectl -V to see the MPM used), you'd need to install
libapache2-mod-php7.2 instead of
4. Install additional modules
Take a look at the
packages.txt file we created at step #2, and install the additional PHP packages. Your packages.txt file will show packages such as
php7.1-mbstring, and you need to install their PHP 7.2 counterpart (
php7.2-mbstring for example).
5. Web server configuration
Before we remove the old PHP packages, make sure that your web server correctly uses the PHP 7.2 sockets/modules. If you installed
php7.2-fpm above, and using Apache,
a2enconf php7.2 will make Apache use PHP 7.2 FPM. Type
a2disconf php7.1-fpm to disable existing FPM configurations.
The steps would be similar for Nginx. Refer to the relevant documentation to change socket paths or IP:Port information.
You can disable the current PHP integration with
a2dismod php7.1 (or your current version) and enable new PHP 7.2 module with
6. Remove old versions
If everything is working well (check your
php --info), you can remove the old packages:
sudo apt purge php7.1*
Of course, change
php7.1 with all old versions you no longer need.
Enjoy your shiny new PHP 7.2!