Upgrade PHP on RedHat 7 and CentOS 7

Introduction

You should, almost, always upgrade to the latest version of PHP supported by ownCloud, if and where possible. And if you’re on a version of PHP older than 7.1 you must upgrade. This guide steps you through upgrading your installation of PHP to one of the supported PHP versions (7.1, 7.2, and 7.3) on Red Hat or CentOS 7.

Upgrade PHP to Version 7.1

To upgrade to PHP 7.1 you first need to subscribe to the Red Hat Software Collections channel repository to download and install the PHP 7.1 package in RHEL 7 (if you’ve not done this already). This documentation uses the same command as you will find there.

Ensure that you have subscription-manager installed. If you don’t, yet, have it installed, do so with the following command:

# Install subscription manager
yum install --assumeyes subscription-manager

# Add the required repositories for the PHP packages
subscription-manager repos --enable rhel-server-rhscl-7-rpms

Install the Required Packages

Then, proceed by installing the required PHP 7.1 packages. You can use the command below to save you time.

yum install \
  rh-php71 \
  rh-php71-php \
  rh-php71-php-cli \
  rh-php71-php-curl \
  rh-php71-php-devel \
  rh-php71-php-gd \
  rh-php71-php-intl \
  rh-php71-php-ldap \
  rh-php71-php-mbstring \
  rh-php71-php-mysqlnd \
  rh-php71-php-opcache
  rh-php71-php-pdo \
  rh-php71-php-pear \
  rh-php71-php-xml \
  rh-php71-php-xmlrpc \
  rh-php71-php-zip

Enable PHP 7.1 and Disable PHP 5.6

Next, you need to enable PHP 7.1 and disable PHP 5.6 system-wide. To enable PHP 7.1 system-wide, run the following command:

cp /opt/rh/rh-php71/enable /etc/profile.d/rh-php71.sh source /opt/rh/rh-php71/enable

Then, you need to disable loading of the PHP 5.6 Apache modules. You can do this either by changing their names, as in the example below, or deleting the files.

mv /etc/httpd/conf.d/php.conf /etc/httpd/conf.d/php56.off
mv /etc/httpd/conf.modules.d/10-php.conf /etc/httpd/conf.modules.d/10-php56.off

Update the Apache Configuration Files

With that done, you next need to copy the PHP 7.1 Apache modules into place; that being the two Apache configuration files and the shared object file.

cp /opt/rh/httpd24/root/etc/httpd/conf.d/rh-php71-php.conf /etc/httpd/conf.d/
cp /opt/rh/httpd24/root/etc/httpd/conf.modules.d/15-rh-php71-php.conf /etc/httpd/conf.modules.d/
cp /opt/rh/httpd24/root/etc/httpd/modules/librh-php71-php7.so /etc/httpd/modules/

Upgrade PHP to Version 7.2

To upgrade to PHP 7.2 you first need to subscribe to the Red Hat Software Collections channel repository to download and install the PHP 7.2 package in RHEL 7 (if you’ve not done this already). This documentation uses the same command as you will find there.

Ensure that you have subscription-manager installed. If you don’t, yet, have it installed, do so with the following command:

# Install subscription manager
yum install --assumeyes subscription-manager

# Add the required repositories for the PHP packages
subscription-manager repos --enable rhel-server-rhscl-7-rpms

Install the Required Packages

Then, proceed by installing the required PHP 7.2 packages. You can use the command below to save you time.

yum install \
  rh-php72 \
  rh-php72-php \
  rh-php72-php-cli \
  rh-php72-php-curl \
  rh-php72-php-devel \
  rh-php72-php-gd \
  rh-php72-php-intl \
  rh-php72-php-ldap \
  rh-php72-php-mbstring \
  rh-php72-php-mysqlnd \
  rh-php72-php-opcache
  rh-php72-php-pdo \
  rh-php72-php-pear \
  rh-php72-php-xml \
  rh-php72-php-xmlrpc \
  rh-php72-php-zip

Enable PHP 7.2 and Disable PHP 5.6

Next, you need to enable PHP 7.2 and disable PHP 5.6 system-wide. To enable PHP 7.2 system-wide, run the following command:

cp /opt/rh/rh-php72/enable /etc/profile.d/rh-php72.sh source /opt/rh/rh-php72/enable

Then, you need to disable loading of the PHP 5.6 Apache modules. You can do this either by changing their names, as in the example below, or deleting the files.

mv /etc/httpd/conf.d/php.conf /etc/httpd/conf.d/php56.off
mv /etc/httpd/conf.modules.d/10-php.conf /etc/httpd/conf.modules.d/10-php56.off

Update the Apache Configuration Files

With that done, you next need to copy the PHP 7.2 Apache modules into place; that being the two Apache configuration files and the shared object file.

cp /opt/rh/httpd24/root/etc/httpd/conf.d/rh-php72-php.conf /etc/httpd/conf.d/
cp /opt/rh/httpd24/root/etc/httpd/conf.modules.d/15-rh-php72-php.conf /etc/httpd/conf.modules.d/
cp /opt/rh/httpd24/root/etc/httpd/modules/librh-php72-php7.so /etc/httpd/modules/

Upgrade PHP to Version 7.3

To upgrade to PHP 7.3 you first need to subscribe to the Red Hat Software Collections channel repository to download and install the PHP 7.3 package in RHEL 7 (if you’ve not done this already). This documentation uses the same command as you will find there.

Ensure that you have subscription-manager installed. If you don’t, yet, have it installed, do so with the following command:

# Install subscription manager
yum install --assumeyes subscription-manager

# Add the required repositories for the PHP packages
subscription-manager repos --enable rhel-server-rhscl-7-rpms

Install the Required Packages

Then, proceed by installing the required PHP 7.3 packages. You can use the command below to save you time.

yum install \
  rh-php73 \
  rh-php73-php \
  rh-php73-php-cli \
  rh-php73-php-curl \
  rh-php73-php-devel \
  rh-php73-php-gd \
  rh-php73-php-intl \
  rh-php73-php-ldap \
  rh-php73-php-mbstring \
  rh-php73-php-mysqlnd \
  rh-php73-php-opcache
  rh-php73-php-pdo \
  rh-php73-php-pear \
  rh-php73-php-xml \
  rh-php73-php-xmlrpc \
  rh-php73-php-zip

Enable PHP 7.3 and Disable PHP 5.6

Next, you need to enable PHP 7.3 and disable PHP 5.6 system-wide. To enable PHP 7.3 system-wide, run the following command:

cp /opt/rh/rh-php73/enable /etc/profile.d/rh-php73.sh source /opt/rh/rh-php73/enable

Then, you need to disable loading of the PHP 5.6 Apache modules. You can do this either by changing their names, as in the example below, or deleting the files.

mv /etc/httpd/conf.d/php.conf /etc/httpd/conf.d/php56.off
mv /etc/httpd/conf.modules.d/10-php.conf /etc/httpd/conf.modules.d/10-php56.off

Update the Apache Configuration Files

With that done, you next need to copy the PHP 7.3 Apache modules into place; that being the two Apache configuration files and the shared object file.

cp /opt/rh/httpd24/root/etc/httpd/conf.d/rh-php73-php.conf /etc/httpd/conf.d/
cp /opt/rh/httpd24/root/etc/httpd/conf.modules.d/15-rh-php73-php.conf /etc/httpd/conf.modules.d/
cp /opt/rh/httpd24/root/etc/httpd/modules/librh-php73-php7.so /etc/httpd/modules/

Restart Apache

Finally, you need to restart Apache to make the changes permanent, as in the command below.

service httpd restart