Search code examples
phprhel6

How to permanent enable PHP 5.4 on RHEL? (PHP 5.3.3 also installed on the system)


I recently installed PHP54 on a RHEL 6.5 server from the RHN Software Collection 1.1 The package has successfully been installed, and it needs to be mentioned there is an existing previous installed PHP version (5.3.3) on the servers which is the current enabled version.

I have checked several sites/forums/blogs and the suggestions are always the same, enable via scl (Setup and run software from Software Collection environment) and/or sourcing the file "/opt/rh/php54/enable". This seems to be a proper workaround to enable PHP54 as can be seen in the commands below.

But it is not permanent, as soon as I exit the shell the user who enabled PHP the changes are discarded. NOTE: the commands has been run as "root" with the exact same behaviour shown in the following commands.

I've found references to add the source workaround into the ".bash_profile" of the user(s), but does not seems to be the best solution for me, I am wondering if someone else have already faced this problem and how it was solved.

Any suggestions?

[mithrandir@mordor ~]# scl enable php54 "php -v"
PHP 5.4.16 (cli) (built: Feb  4 2014 08:10:51)
Copyright (c) 1997-2013 The PHP Group
Zend Engine v2.4.0, Copyright (c) 1998-2013 Zend Technologies


[mithrandir@mordor ~]# php -v
PHP 5.3.3 (cli) (built: Jul 15 2014 08:48:08)
Copyright (c) 1997-2010 The PHP Group
Zend Engine v2.3.0, Copyright (c) 1998-2010 Zend Technologies


[mithrandir@mordor ~]# source /opt/rh/php54/enable
[mithrandir@mordor ~]# php -v
PHP 5.4.16 (cli) (built: Feb  4 2014 08:10:51)
Copyright (c) 1997-2013 The PHP Group
Zend Engine v2.4.0, Copyright (c) 1998-2013 Zend Technologies


[mithrandir@mordor ~]# date
Fri Aug 29 12:29:35 MDT 2014

[mithrandir@mordor ~]# exit
logout

[me@mordor ~]$ sudo su -
[sudo] password for me:

[mithrandir@mordor ~]# php -v
PHP 5.3.3 (cli) (built: Jul 15 2014 08:48:08)
Copyright (c) 1997-2010 The PHP Group
Zend Engine v2.3.0, Copyright (c) 1998-2010 Zend Technologies

[mithrandir@mordor ~]# date
Fri Aug 29 12:29:57 MDT 2014

Solution

  • It seems that in order to enable a package from the RH Software Collection the only way is by adding a script under "/etc/profile.d" and including the "source /opt/rh/php54/enable" command.

    This is a link to RH devs blog, showing the solution. Be aware that it is for python33 but this workaround applies for software included on RHSC such as PHP54.

    Permanently Enable a Software Collection

    I implemented the solution and it is working. I hope this helps someone else.