Best way to make RHSCL PHP available globally

11,763

The way to import a software collection into your current shell (not launch a sub-shell) is to source the "enable" file.

For example for rh-php56 on a Redhat 7 machine...

source /opt/rh/rh-php56/enable

You can now run "php", or read manpages "man php" as normal.

that will add the appropriate environment variables to the current shells environment. Individual users can do this in there .bashrc files, allowing it to be available from SSH (non-interactive shells)

You can also copy (or symlink) the enable file into /etc/profile.d/ with a ".sh" suffix to automatically enable it for ALL users.

For example

ln -s /opt/rh/rh-php56/enable /etc/profile.d/rh-php56.sh

Becareful doing this if more than environment is needed (such as daemons?). Or if multiple versions of that software is present on a system (for backward compatibility with other software/services), as there may be interaction between versions. Also users may not want the 'latest' version, or become confused as to why the 'base' system (EG: /etc configs) does not effect the software collection version.

Anthony Thyssen (A very old system Admin)

Share:
11,763

Related videos on Youtube

Ozzy
Author by

Ozzy

Updated on September 18, 2022

Comments

  • Ozzy
    Ozzy almost 2 years

    I have installed RHSCL 2 using the following url:

    https://access.redhat.com/documentation/en-US/Red_Hat_Software_Collections/2/html/2.0_Release_Notes/chap-Installation.html

    using the RedHat subscription manager.

    I then ran yum remove php* followed by yum install rh-php56

    Everything went smoothly except now PHP is not found anywhere. I then ran find / -name php and found rh-php56 in the following directories:

    /var/opt/rh/rh-php56/lib/php
    /opt/rh/rh-php56/register.content/var/opt/rh/rh-php56/lib/php
    /opt/rh/rh-php56/root/usr/bin/php
    /opt/rh/rh-php56/root/usr/lib64/php
    /opt/rh/rh-php56/root/usr/share/php
    

    What is the best way to get these binaries into /usr/bin or any other directory that is usually globally available for all users?

    Did I miss a step when installing the packages which is why it is not available globally? Or is this just what happens when using RHSCLs?

    I have tested the binaries in those folders and they work when I run php -v so it is working fine.

    My first thought is to just cp into /bin or /usr/bin but maybe there is an official way to do what I am asking?

    edit

    Cannot comment, no rep... from chapter 3 of the link I posted, it says that software collection packages must be run like so:

    scl enable rh-php56 'php -v'

    Which does work... however how do I get it to run for all users like $ php -v with no additional commands. I need the php binaries globally available so webservers can use it and ssh users with normal shells.

    • FooBee
      FooBee over 8 years
      You forgot to read chapter 3 of the link you gave....
    • anthony
      anthony over 8 years
      Sven... I read it myself.. and all it has is starting a sub-shell with the collection made available. It does NOT detail how to make a collection available BY default without the user needing to run a sub-shell. I will detail a proper solution below.
    • Stefan Lasiewski
      Stefan Lasiewski over 8 years
      Sven, that would mean that every user and every daemon would need to run scl enable rh-php56 command, which is complicated. Enabling it globally via @antofthy's answer is much more elegant.
  • Darvanen
    Darvanen almost 8 years
    which instance of php.ini does this method invoke?
  • Darvanen
    Darvanen almost 8 years
    Ahhh... I was restarting httpd instead of the php-fpm service. Posting here in case anyone else gets stuck that way.
  • Stefan Lasiewski
    Stefan Lasiewski about 7 years
    Is this actually sufficient to enable a SCL package? access.redhat.com/solutions/527703 seems to create a bash script which does something like source scl_source enable python33
  • anthony
    anthony almost 7 years
    Should be sufficient. It basically sets the environment to use the specific version over the system version. But only within the sub-shell started.