How to Permanently Enable Software Collections (SCL) on CentOS 7 for Persistent Access to rh-php56


1 views

When working with Software Collections (SCL) on CentOS 7, you might notice that enabled collections don't persist across new shell sessions. This is particularly frustrating when you need consistent access to packages like rh-php56 for development or production environments.

The most reliable method to permanently enable an SCL is by modifying your shell's configuration file. Here's how to do it for different scenarios:

# For bash users (most common case)
echo "source scl_source enable rh-php56" >> ~/.bashrc

# For zsh users
echo "source scl_source enable rh-php56" >> ~/.zshrc

# System-wide configuration (use with caution)
echo "source /opt/rh/rh-php56/enable" >> /etc/profile.d/php56.sh

If you prefer more control over when the SCL loads, consider creating an alias:

echo "alias enablephp='source scl_source enable rh-php56'" >> ~/.bashrc

Then simply run enablephp whenever you need the collection.

After implementing any of these solutions, verify that the SCL is properly enabled:

# Start a new shell session
exec bash

# Verify PHP version
php -v

# Check SCL environment variables
env | grep -i php

For services that need SCL packages, you'll need to modify the service unit file:

[Service]
EnvironmentFile=/opt/rh/rh-php56/enable
ExecStart=/usr/bin/php /path/to/your/script.php

If you encounter problems:

  • Check file permissions on your shell configuration files
  • Verify the SCL package is properly installed (yum list installed rh-php56)
  • Ensure the scl_source script exists (ls -la /etc/profile.d/scl.sh)

When working with Red Hat-based systems like CentOS 7, Software Collections (SCL) provide a powerful way to access newer versions of software without affecting system-wide installations. The temporary nature of SCL activation (via scl enable) means developers often need persistent activation across SSH sessions.

The rh-php56 collection you've installed exists in /opt/rh/rh-php56, but simply installing it doesn't make its binaries available in your PATH. Each new shell session loses the SCL context, requiring manual reactivation.

Here are three reliable ways to permanently enable an SCL:

1. Modifying Shell Configuration

Add this to your ~/.bashrc:


# Enable rh-php56 permanently
source /opt/rh/rh-php56/enable

2. System-wide Profile Configuration

For all users, create /etc/profile.d/scl_php56.sh:


#!/bin/bash
source /opt/rh/rh-php56/enable
export X_SCLS="$(scl --list | tr '\n' ' ')"

3. Using .scl_enable File

Create ~/.scl_enable containing:


rh-php56

After implementing any method, verify with:


php -v
which php

The output should show the SCL-provided PHP 5.6 version and binary location under /opt/rh.

For simpler cases, create symlinks to system paths:


sudo ln -s /opt/rh/rh-php56/root/usr/bin/php /usr/local/bin/php56
  • Environment variable propagation can differ between interactive and non-interactive shells
  • Some applications may not respect the modified PATH
  • SCL collections may conflict with system packages in complex ways

For services using SCL software, modify the service unit file:


[Service]
EnvironmentFile=/opt/rh/rh-php56/enable
ExecStart=/opt/rh/rh-php56/root/usr/bin/php your_script.php