While you are working with PHP in command mode, the php command automatically runs the PHP CLI binary file corresponding to the default PHP version.
To view a list with all PHP CLI options, use the following command:
php -h
To check the current PHP CLI version, you should execute:
php -
To see the current php.ini file (which will load every time by default), use:
php --ini
In case you have not specified another file, PHP CLI will always use the default system php.ini file /opt/cpanel/ea-phpXX/root/etc/php.ini.
If it is necessary to set specific settings for executing a PHP script, you might need to add a -c option to the command followed by the custom php.ini file. For example:
php -c /home/cpuser/my-custom-php.ini /home/cpuser/public_html/file.php
/home/cpuser/my-custom-php.ini – replace the full path and the .ini file name;
/home/cpuser/public_html/file.php – the file that will be executed;
If the custom php.ini file will be used with each PHP command in the console, add a line in the .bash_profile file so that you do not need to type the file name every next time:
alias php='php -c /home/cpuser/my-custom-php.ini'
/home/cpuser/my-custom-php.ini – replace with the full path and the .ini file name;
If you wish to work with a different PHP (cli) version, edit the line by changing the binary file path:
alias php=’/opt/cpanel/ea-phpXX/root/usr/bin/php -c /home/cpuser/my-custom-php.ini’
ea-phpXX – replace with the PHP version, for example /opt/cpanel/ea-php72/root/usr/bin/php;
To load the ini file with PHP modules, add in .bash_profile file the line:
export PHP_INI_SCAN_DIR=/home/cpuser/.sh.phpmanager/phpXX.d
/home/cpuser/.sh.phpmanager/phpXX.d – replace with the path to the ini file directory;
If you are logged into the hosting account via SSH, log out and then log in again to activate this setting. You might also use this command:
source ~/.bash_profile
The .bash_profile file settings will load every time you access your hosting account via SSH.
Check which .ini file is loaded with:
php --ini
This time the command result should display the custom .ini file in the Loaded Configuration File field.
In the command line you can set different values for certain PHP directives through the -d (configuration_directive=value) option. For example:
php -c /home/cpuser/php.ini /home/cpuser/file.php -d memory_limit=256M
According to the set parameters for script execution, the value for memory_limit will be 256MB.
This article is about: hosting services with cPanel.