Additional PHP versions on CentOS

Category: CentOS
Created: 2019-10-23
Updated: 2020-09-09

CentOS is known for it’s stability, but also for some software packages being a little outdated. CentOS 7 comes with PHP 5.4.16 - the 5.4 series isn’t maintained any more since September 2015. Many web applications require more modern PHP version like 7.2 or later.

This article explains how to install additional PHP versions in parallel and register them with LiveConfig.

Adding the REMI repository

We recommend to install the ready-to-use PHP packages from the REMI repository. Alternatively you may install PHP from source or using another repository - in this case just jump to the registering PHP section.

Check if you have already enabled the REMI repository (yum repolist). If not done yet, add it:

  • CentOS / Red Hat Enterprise Linux 6.x:

    rpm -Uvh remi-release-6.rpm epel-release-latest-6.noarch.rpm
  • CentOS / Red Hat Enterprise Linux 7.x:

    rpm -Uvh epel-release-latest-7.noarch.rpm remi-release-7.rpm
  • CentOS / Red Hat Enterprise Linux 8.x:

    rpm -Uvh epel-release-latest-8.noarch.rpm remi-release-8.rpm

The REMI repository is not enabled by default. To enable, edit the file /etc/yum.repos.d/remi.repo. Find the line enabled=0 and change it to 1:


Installing PHP

The LiveConfig repository provides helpful packages which install the desired PHP version and automatically registers them with LiveConfig.

  • PHP 7.3: CentOS/RHEL 6/7/8

    yum install lc-php73-remi
  • PHP 7.4: CentOS/RHEL 7/8

    yum install lc-php74-remi
  • PHP 8.0: CentOS/RHEL 7/8

    yum install lc-php80-remi

Registering PHP

Only if you have installed PHP manually or from another repository: for each additional version, create a corresponding Lua file in /etc/liveconfig/lua.d/. For example for PHP 7.3, name that file php73.lua.

-- register additional PHP interpreter with LiveConfig
LC.web.addPHP( {
  ['id']  = 'php73',
  ['cli'] = '/opt/php-7.3/bin/php',
  ['cgi'] = '/opt/php-7.3/bin/php-cgi',
  ['fpm'] = {
    ['bin']     = '/opt/php-7.3/sbin/php-fpm',
    ['start']   = 'service php73-fpm start',
    ['stop']    = 'service php73-fpm stop',
    ['reload']  = 'service php73-fpm reload',
    ['pool']    = '/etc/php-fpm/php73-fpm.d',
    ['sockets'] = '/var/run/php73-fpm'
} )


Run liveconfig --diag (or on a client system: lcclient --diag) and watch the PHP section:

[root@centos#] liveconfig --diag
 - PHP 7.3.16 (code='php73')
   CGI/FastCGI: /opt/remi/php73/root/usr/bin/php-cgi
   FPM: /opt/remi/php73/root/usr/sbin/php-fpm
        pool config: /etc/opt/remi/php73/php-fpm.d
   default php.ini: '/etc/opt/remi/php73/php.ini'

Only if you have installed PHP manually or from another repository: restart LiveConfig (systemctl restart liveconfig) to enable the new PHP interpreter(s).

Installing PHP extensions

In most cases you also want to install popular PHP extensions. Just search for already available modules like

yum search php73-

Some frequently required modules are installed like this:

yum install php73-php-gd php73-php-imap php73-php-intl php73-php-json php73-php-mbstring php73-php-mysqlnd php73-php-pdo php73-php-xml php73-php-pecl-apcu php73-php-pecl-imagick

You only need to adjust the version number depending on your actual PHP version.

Change default PHP version

LiveConfig uses the PHP version provided by the respective Linux distribution as “default version”.

If you want to use a different PHP interpreter as the standard version, create a file /etc/liveconfig/lua.d/php-default.lua and enter the following line there:

-- change PHP default version
LC.web.PHPDEFAULT = 'php73'

Instead of php73 please enter the code of the desired PHP version (see listing when running liveconfig --diag).

If you run liveconfig --diag again, the selected version should then be marked with [DEFAULT]. Restart LiveConfig to apply the changes.