Steven SullivanSteven Sullivan - 16th March 2018

I’ve published one before on the VestaCP Forums regarding how to install PHP 7.0 on Centos 7 with VestaCP. This tutorial is now for PHP 7.2 which has increased performance over PHP 7.0 and 7.1. If you have a handful of WordPress websites on PHP 5, you should upgrade. If you’re on PHP 7.0 from my previous tutorials, or are using my Server Installer Script then this will also work for you. I would advise upgrading when you have time.

Note: This only works on NGINX + PHP-FPM VestaCP installs.

Install PHP 7.2 on CentOS 7

This method will completely remove any older PHP version.

If you have REMI Repository you can skip this step.

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

Then enable Remi

yum --enablerepo=remi update remi-release

Now remove old PHP and install PHP7

service php-fpm stop
yum -y --enablerepo=remi install php72-php php72-php-pear php72-php-bcmath php72-php-pecl-jsond-devel php72-php-mysqlnd php72-php-gd php72-php-common php72-php-fpm php72-php-intl php72-php-cli php72-php php72-php-xml php72-php-opcache php72-php-pecl-apcu php72-php-pecl-jsond php72-php-pdo php72-php-gmp php72-php-process php72-php-pecl-imagick php72-php-devel php72-php-mbstring

Remove and re-link new PHP 7.2

rm -f /usr/bin/php
ln -s /usr/bin/php72 /usr/bin/php

Test if we have PHP 7.2

php -v

Output should be (take note of PHP 7.2!!)

[[email protected] system]# php -v
PHP 7.2.3 (cli) (built: Mar  2 2018 12:24:56) ( NTS )
Copyright (c) 1997-2018 The PHP Group
Zend Engine v3.2.0, Copyright (c) 1998-2018 Zend Technologies
    with Zend OPcache v7.2.3, Copyright (c) 1999-2018, by Zend Technologies

Now open up new PHP-FPM.conf ( [b]/etc/opt/remi/php72/php-fpm.conf[/b] ) file and change [b]line 11[/b] to:

include=/etc/php-fpm.d/*.conf

Start PHP-FPM

service php72-php-fpm start

Remove old systemctl php-fpm and link to new one

rm -f /usr/lib/systemd/system/php-fpm.service
ln -s /usr/lib/systemd/system/php72-php-fpm.service /usr/lib/systemd/system/php-fpm.service

Reload systemctl daemon

systemctl daemon-reload

Now if you want to keep PHP 7.2 up-to-date when you do updates, you’ll need to disable the previous PHP 5 repos like so;

yum install yum-utils
yum-config-manager --disable remi-php56
yum-config-manager --disable remi-php55
yum-config-manager --disable remi-php56-debuginfo
yum-config-manager --disable remi-php55-debuginfo
yum clean all
yum update

2 thoughts...

  1. Alexander says:

    This does NOT work on a fresh install of the Server Installer Script with automated PHP7.0 update.
    PHP version after update: PHP 7.2.12. However info.php still shows 7.0 which is really weird.

    Also, PHP-FPM crashed. systemctl status php72-php-fpm.service shows the following
    Nov 30 21:24:08 hostname systemd[1]: Starting The PHP FastCGI Process Manager…
    Nov 30 21:24:08 hostname php-fpm[8193]: [30-Nov-2018 21:24:08] ERROR: unable to bind listening socket for address ‘127.0.0.1:9001’: Address already in use (98)
    Nov 30 21:24:08 hostname php-fpm[8193]: [30-Nov-2018 21:24:08] ERROR: FPM initialization failed
    Nov 30 21:24:08 hostname systemd[1]: php72-php-fpm.service: main process exited, code=exited, status=78/n/a
    Nov 30 21:24:08 hostname systemd[1]: Failed to start The PHP FastCGI Process Manager.
    Nov 30 21:24:08 hostname systemd[1]: Unit php72-php-fpm.service entered failed state.
    Nov 30 21:24:08 hostname systemd[1]: php72-php-fpm.service failed.

    1. Alexander says:

      Update: Both problems solved after REBOOT of the server

Leave a Reply

Your email address will not be published. Required fields are marked *