How to install RedHat Software Collections Library PHP 7 on CentOS 7

Ensure httpd is stopped and disabled.

systemctl stop httpd
systemctl disable httpd

Install the CentOS EPEL & Software Collections Library (scl) release packages, clean, & rebuild the yum cache.

yum install epel-release centos-release-scl
yum clean all
yum makecache

Install the latest RedHat SCL php 7.0 & corresponding, dependent httpd24 packages.

The following command installs the most commonly required php modules, as well.

yum install rh-php70 rh-php70-php rh-php70-php-bcmath rh-php70-php-cli rh-php70-php-common rh-php70-php-dba rh-php70-php-embedded rh-php70-php-enchant rh-php70-php-fpm rh-php70-php-gd rh-php70-php-intl rh-php70-php-ldap rh-php70-php-mbstring rh-php70-php-mysqlnd rh-php70-php-odbc rh-php70-php-pdo rh-php70-php-pear rh-php70-php-pgsql rh-php70-php-process rh-php70-php-pspell rh-php70-php-recode rh-php70-php-snmp rh-php70-php-soap rh-php70-php-xml rh-php70-php-xmlrpc sclo-php70-php-imap sclo-php70-php-mcrypt sclo-php70-php-pecl-apcu sclo-php70-php-pecl-apcu-bc sclo-php70-php-pecl-memcached sclo-php70-php-tidy httpd24 httpd24-mod_ssl

Configure the necessary operating system files.

For '’bash’‘, '’crond’‘, & '’systemctl’‘ to work properly with the RedHat SCL php 7 packages, the following files MUST be configured manually.




if [ -d /opt/rh/ ] && [ -r /opt/rh/ ]; then
    Rhscl_Roots=$(find /opt/rh/ -type f -name enable 2> /dev/null | sort -V)
    for Rhscl_Enable in $Rhscl_Roots; do
        if [ -r "$Rhscl_Enable" ]; then
            . "$Rhscl_Enable"
        Rhscl_Root="$(dirname "$Rhscl_Enable")/root"
        Rhscl_Bins="usr/bin usr/sbin bin sbin"
        for Rhscl_Bin in $Rhscl_Bins; do
            if [ -d "$Rhscl_Root/$Rhscl_Bin" ]; then
        unset Rhscl_Bin Rhscl_Bins  Rhscl_Enable Rhscl_Root
    unset Rhscl_Roots
export PATH_SCL=$Scl_Path


Description=The Apache HTTP Server

ExecStart=/opt/rh/httpd24/root/usr/sbin/httpd-scl-wrapper $OPTIONS -DFOREGROUND
ExecReload=/opt/rh/httpd24/root/usr/sbin/httpd-scl-wrapper $OPTIONS -k graceful
ExecStop=/bin/kill -WINCH ${MAINPID}
# We want systemd to give httpd some time to finish gracefully, but still want
# it to kill httpd after TimeoutStopSec if something went wrong during the
# graceful stop. Normally, Systemd sends SIGTERM signal right after the
# ExecStop, which would kill httpd. We are sending useless SIGCONT here to give
# httpd time to finish.


Enable, start, and check the status of httpd.

systemctl daemon-reload # important!
systemctl enable httpd
systemctl start httpd
systemctl status httpd

Verify locations of php ini files.

At this point, there should be a fully functional httpd 2.4 with php 7.0 (using the mysqlnd driver, etc).

php --ini

Configuration File (php.ini) Path: /etc/opt/rh/rh-php70
Loaded Configuration File:         /etc/opt/rh/rh-php70/php.ini
Scan for additional .ini files in: /etc/opt/rh/rh-php70/php.d
Additional .ini files parsed:      /etc/opt/rh/rh-php70/php.d/20-bcmath.ini,

Optional Steps

The following steps are OPTIONAL, but recommended.

These are some things that will make using the RedHat PHP 7.0.x SCL packages and upgrading existing code bases a little easier.

  • On development machines that may be building C/C++ packages that require installed php headers, additionally install the corresponding devel packages.

      yum install rh-php70-php-devel rh-php70-scldevel sclo-php70-php-pecl-apcu-devel sclo-php70-php-pecl-http-devel
  • Remove the default CentOS7 httpd* & php* packages & their dependencies. This can help avoid confusion as to which version of php (& httpd) is actually in use.

      yum remove httpd httpd-tools php*
  • Create (or modify) the systemctl EnvironmentFile for httpd.service. By doing this, it will cause the scl httpd24 to re-use the existing /etc/httpd structure (rather than what’s in /opt/rh/httpd24/root/etc/httpd). If #OPTIONS= in /opt/rh/httpd24/root/etc/sysconfig/httpd and change it to the following, then be sure to update the contents of /etc/httpd to reflect what’s in /opt/rh/httpd24/root/etc/httpd.

      OPTIONS="-d /etc/httpd"


The following information may be helpful.

Many packages, programs, & utilities (and people) expect the default CentOS 7 filesystem locations for associated files. The RedHat SCL packages relocate everything to /opt/rh/.

  • If you chose to update the /opt/rh/httpd24/root/etc/httpd OPTIONS then make sure there are no base httpd artifacts left in /etc/httpd. Using rsync can be helpful in this case, i.e.

      rsync -avp /opt/rh/httpd24/root/etc/httpd/ /etc/httpd/ --delete-after
  • On CentOS 7 machines with only rh-php-7.0 installed, it may be easiest to use a symbolic link. However, it should not be done on machines that choose to have the default php and scl php co-exist on the same machine.

      ln -s /opt/rh/rh-php70/root/usr/bin/php /usr/bin/php
  • Best practice, for scripts in general, is to use tge /usr/bin/env <processor> directives rather than hard coding something like #!/usr/bin/php.

    #!/usr/bin/env php

  • Here’s a quick one liner to find all files from the current directory that contain ‘‘bin/php’’; they may need to be changed to #!/usr/bin/env php (rather than relying on a symbolic link).

      find . -type f -exec gawk 'FNR>10 {nextfile} /bin\/php/ { print FILENAME ; nextfile }' {} \;
  • If open source scripts or packages are found using hard coded shebang conventions then please report them to their author(s) and have them changed upstream.