When executing PHP while logged in as a cPanel user via CLI, the version of PHP shows as an ALT PHP version, but I want the version to be an EA PHP version instead.
ALT-PHP vs EA-PHP what is the difference?
When a cPanel user on CloudLinux tries to use PHP on the command line, the version of PHP used will be governed by the following rules:
1. The System PHP Version will be used by default on the CLI. When CageFS is enabled for a user, the System PHP Version is selected within the "Select PHP Version" icon inside of the cPanel account.
2. .htacess files that have a cPanel generated PHP version configuration in them will override PHP Selector's System PHP Version.
PHP Selector only offers the ability to set a single PHP version for the entire account. Although it is not possible to specify different PHP versions on a per-website / per-directory basis in PHP Selector, it is possible to override PHP Selector's System PHP Version with cPanel's EA-PHP versions on the CLI by using the MultiPHP Selector icon in cPanel to select your desired PHP version. When changing the version in the MultiPHP Manager icon in cPanel, it will update the .htaccess configuration in the document root of the domain that you have edited. Although you should not modify the cPanel generated PHP version configuration in the .htaccess file, it is possible to copy that cPanel generated configuration and place it within a .htaccess file in another directory within the account so that your desired EA-PHP version is used when executing PHP via CLI there. See the workaround below for specific steps.
1. Login to the cPanel interface for the user that needs the updated configuration
2. Navigate to the MultiPHP Manager icon under the Software section
3. Edit one of the domains to use your desired EA-PHP version
4. Via CLI as the cPanel user (do not use root), navigate to the document root of that domain. If you don't know what the document root of the domain is you can learn how to find that here -> How to find the document root of a domain
5. Open the .htaccess file in the document root with the less command to read the contents
6. Copy the cPanel generated PHP configuration from within the file. It should look similar to the following:
# php -- BEGIN cPanel-generated handler, do not edit
# Set the “ea-php72” package as the default “PHP” programming language.
AddHandler application/x-httpd-ea-php72 .php .php7 .phtml
# php -- END cPanel-generated handler, do not edit
7. Exit the less command by pressing the letter q
8. Via CLI navigate to the directory where you are executing PHP via CLI
9. Create a new .htaccess file within that directory and paste the cPanel PHP configuration into the .htaccess file
10. Test the PHP version inside of that directory by running the following commands:
/usr/local/bin/php -i | grep "^Configuration File"