Upgrade PHP on RedHat 7 and CentOS 7


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.4.0 you must upgrade. This guide takes you through upgrading your installation of PHP to one of the supported PHP versions (7.4) on Red Hat or CentOS 7.

Upgrade PHP to Version 7.4

To upgrade to PHP 7.4 you first need to subscribe to the Red Hat Software Collections channel repository to download and install the PHP 7.4 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.4 packages. You can use the command below to save you time.

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

Enable PHP 7.4 and Disable PHP 5.6

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

cp /opt/rh/rh-php74/enable /etc/profile.d/rh-php74.sh source /opt/rh/rh-php74/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.4 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-php74-php.conf /etc/httpd/conf.d/
cp /opt/rh/httpd24/root/etc/httpd/conf.modules.d/15-rh-php74-php.conf /etc/httpd/conf.modules.d/
cp /opt/rh/httpd24/root/etc/httpd/modules/librh-php74-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