How to Make Softaculous Detect the Correct PHP Version

It appears that Softaculous is slightly broken if you have ever used the /scripts/makecpphp script to rebuild cPanel’s internal version of PHP. I found that Softaculous detects version 5.2.17 (as of cPanel 11.32) rather than the newer version (5.4.7) that I have installed. This becomes problematic when clients wish to install software that requires PHP > 5.2.17. This appears to be caused by the Softaculous installer ignoring the PHP Binary setting (uses the cPanel internal binary rather than the one specified). The ideal solution, of course, would be for this bug to be fixed on their end.

The only documentation I’ve found for this is a forum thread on the vendor’s site that doesn’t give a long-term solution. The “solution” presented in that thread is to manually set the version of PHP in a hooks file. This certainly isn’t ideal since most will forget to update the version of PHP in that file whenever PHP is upgraded. Knowing that I will definitely forget, I’ve written a little code that will take care of everything. 🙂

1) cd /usr/local/cpanel/whostmgr/docroot/cgi/softaculous/enduser/hooks/
2) Warning: if pre_install.php already exists, skip to the next step
cp pre_install.txt pre_install.php
3) nano pre_install.php
4) Add the following below “// Do stuff here e.g. is as follows”:

        function get_real_php_version()
        {
                //discovers version of client-facing PHP on cPanel servers
 
                //the path to the default PHP binary in cPanel
                $php_file = file_get_contents('/usr/bin/php');
 
                //get the part we're interested in
                preg_match('/X-Powered-By: PHP/*[0-9]*.*[0-9].*[0-9]/', $php_file, $version_dirty);
 
                //get rid of the junk
                $version = str_replace('X-Powered-By: PHP/', '', $version_dirty[0]);
 
                return $version;
        }
 
        define('php_version', get_real_php_version());

Once you’ve done that, you should have something that looks like this:

5) Now press Ctrl + X, then Y, and finally Enter to save your changes.

If all went well, you should now be able to install software that is compatible with your PHP version.

  • audioprobe

    Something even easier, perhaps, would be to read from the PHP version file that cPanel magically generates… /usr/local/apache/conf/php5.version

  • Brijesh Kothari

    Hi,

    I am from the Softaculous team.
    If you using CageFS or H1 to switch PHP versions you will have to configure a hook for that :
    CageFS :
    http://softaculous.com/docs/Detect_PHP_Version_on_CageFS
    and
    H1 :
    http://softaculous.com/docs/Hooks#Change_PHP_Version_using_.htaccess

    Once you configure these hooks Softaculous will detect the correct versions.

    • audioprobe

      Hi. I’m not using either of those. I just have the normal installation of CentOS 6 and cPanel.

      It appears that this issue was fixed at some point either by an update of cPanel (11.36) or and update of Softaculous. I haven’t kept track so i don’t know when it was fixed. This is no longer an issue.