How to Permanently Enable RHSCL PHP (rh-php56) for Global System Access in RedHat/CentOS


2 views

When installing PHP through Red Hat Software Collections (RHSCL) using yum install rh-php56, the binaries aren't automatically added to standard system paths. This occurs because RHSCL uses a filesystem hierarchy under /opt/rh/ to maintain multiple parallel versions.

RHSCL intentionally isolates packages to prevent conflicts. The PHP binary you found at /opt/rh/rh-php56/root/usr/bin/php is the correct one, but requires activation via:

scl enable rh-php56 'php -v'

Method 1: Modify Shell Profiles (Recommended for User Access)

Add this to /etc/profile.d/rh-php56.sh:

#!/bin/bash
source /opt/rh/rh-php56/enable
export XDG_CONFIG_DIRS="/opt/rh/rh-php56/root/etc/xdg:${XDG_CONFIG_DIRS:-/etc/xdg}"
export PATH="/opt/rh/rh-php56/root/usr/bin${PATH:+:${PATH}}"

Method 2: System-wide Symlinks (For Service Compatibility)

Create symbolic links to standard locations:

ln -s /opt/rh/rh-php56/root/usr/bin/php /usr/bin/php56
ln -s /opt/rh/rh-php56/root/usr/lib64 /usr/lib64/rh-php56

Method 3: Permanent SCL Enable for Services

For Apache/Nginx integration, modify service files:

# For httpd
echo "/opt/rh/rh-php56/root/usr/lib64/httpd/modules/" > /etc/httpd/conf.modules.d/10-php56.conf

After implementation:

php -v
# Should show RHSCL version without scl prefix

which php
# Should return /usr/bin/php56 (or standard path)
  • Never copy binaries directly - use symlinks or environment variables
  • For production systems, consider using systemctl edit to modify service environments
  • Package updates will maintain paths under /opt/rh/

If using PHP-FPM, modify pool configuration:

[www]
user = apache
group = apache
listen = /var/run/php-fpm/php56-fpm.sock
listen.owner = apache
listen.group = apache
php_admin_value[include_path] = "/opt/rh/rh-php56/root/usr/share/pear"
env[PATH] = /opt/rh/rh-php56/root/usr/bin:/usr/local/bin:/usr/bin:/bin

Red Hat Software Collections (RHSCL) are intentionally designed to run in isolated environments to prevent conflicts with system packages. When you installed rh-php56, it was deployed under /opt/rh/rh-php56/ rather than the standard system paths. This is normal behavior for RHSCL packages.

As you've discovered, the immediate way to access the PHP binary is through:

scl enable rh-php56 'php -v'

However, this only works for the current session. For web servers and persistent environments, we need a permanent solution.

Method 1: System-wide scl Enable

Create an environment file in /etc/profile.d/:

echo "source scl_source enable rh-php56" | sudo tee /etc/profile.d/rh-php56.sh
sudo chmod +x /etc/profile.d/rh-php56.sh

This will automatically enable the collection for all users upon login.

Method 2: Symbolic Links to Standard Paths

For direct access without scl commands:

sudo ln -s /opt/rh/rh-php56/root/usr/bin/php /usr/local/bin/php
sudo ln -s /opt/rh/rh-php56/root/usr/bin/php-cgi /usr/local/bin/php-cgi
sudo ln -s /opt/rh/rh-php56/root/usr/bin/pear /usr/local/bin/pear
sudo ln -s /opt/rh/rh-php56/root/usr/bin/pecl /usr/local/bin/pecl

For Apache, modify your virtual host configuration:

<FilesMatch \.php$>
    SetHandler "proxy:unix:/var/opt/rh/rh-php56/run/php-fpm.sock|fcgi://localhost"
</FilesMatch>

After implementing any of these methods, verify with:

php -v
which php

You should see the RHSCL PHP version and the correct path.

  • Never copy binaries directly to /usr/bin as this can cause conflicts
  • The symbolic link method may require PATH adjustments if /usr/local/bin isn't in your default PATH
  • For system services, you may need to enable the collection in service unit files