Symptoms
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.
Cause
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:
- 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 the cPanel account.
- .htaccess 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 in cPanel to select your desired PHP version. When changing the version in the MultiPHP Manager 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.
Resolution
- Log in to the cPanel interface for the user
- Navigate to the MultiPHP Manager icon under the Software section
- Edit one of the domains to use your desired EA-PHP version
- Via CLI as the cPanel user (do not use root), navigate to the document root of that domain.
- Open the .htaccess file in the document root with the less command to read the contents
-
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.
<IfModule mime_module>
AddHandler application/x-httpd-ea-php72 .php .php7 .phtml
</IfModule>
# php -- END cPanel-generated handler, do not edit - Exit the less command by pressing the letter q
- Via the CLI, navigate to the directory where you are executing PHP via CLI
- Create a new .htaccess file within that directory and paste the cPanel PHP configuration into the .htaccess file
-
Test the PHP version inside that directory by running the following commands:
# /usr/local/bin/php -v
# /usr/local/bin/php -i | grep "^Configuration File"
Comments
0 comments
Article is closed for comments.