How to get Apache and CLI to use the same PHP version?

ivordurham

Registered
Dec 28, 2019
1
0
1
94022
cPanel Access Level
Website Owner
After selecting a non-default PHP version through the PHP Selector applied to "/" on a shared hosting package, Apache correctly uses the expected version with no .htaccess modification. Both /usr/local/bin/php and /usr/bin/php are the cPanel scripts which use the ea_php_cli package, but from the shell or cron scripts they select the system default version of PHP instead of the one set via the PHP Selector. What do I need to do to get command line PHP scripts to use the same PHP version as Apache?
 

cPJeremy

Technical Analyst
Staff member
Feb 13, 2019
58
3
83
Houston TX
cPanel Access Level
Root Administrator
Hello ivordurham!

This may be depending on the PHP handler being used by the particular version. It might still be running PHP crons and scripts using the system version. You can confirm the PHP handlers being used by running this command: /usr/local/cpanel/bin/rebuild_phpconf --current

Can you confirm what PHP Handler you are using for the user's selected PHP version? Although it is not a requirement, CloudLinux does suggest using LSAPI as the handler. Would you be willing to try installing mod_lsapi? You can do this using the steps and commands shown here: CloudLinux Documentation | Installing Mod_lsapi

Once Mod_lsapi is installed, can you go to WHM's Home »Software »MultiPHP Manager and click on the Tab for "PHP Handlers." From here, can you set the version for the user to use mod_lsapi? Once that is done, can you confirm if that helped and it running the scripts as the user and using the user's PHP version?

Thank you!