Migrating CentOS 7 to PHP 7

Migrating CentOS 7 to PHP 7

CentOS is a conservative distribution, meaning you get the most stability and security out of it, but this comes at the expense of newer features like the latest PHP release.

Fortunately there are ways around for getting a newer PHP on CentOS by using one of the several repositories out there providing updated packages. My personal choice for this task is Remi’s Repository.

Start by adding Remi’s repository to your local repositories list (EPEL is also needed):

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

Then you can install PHP 7.2 (the current release as of writing this article). The list below includes the core packages and most used extensions:

yum install php72-php php72-php-cli php72-php-common php72-php-gd php72-php-mbstring php72-php-mcrypt php72-php-opcache php72-php-pdo php72-php-pear php72-php-pecl-zip php72-php-xml php72-php-xmlrpc php72-php-mysqlnd

This will get the latest 7.2 release alongside the existing older one (most likely PHP 5.4).

Running two (or even multiple) PHP versions simultaneously will allow you to individually switch Virtualmin virtual servers between PHP versions one at a time (WHM has a similar feature), for the added comfort of testing the sites for code compatibility.

Virtualmin will use the highest available PHP version for new virtual servers by default, so keep that in mind.

Leave a Reply