https://help.superhosting.bg/en/php-cli-settings-use-custom-ini.html
  • bg
  • en

Hosting, Domains, Cloud, Virtual Private Servers (VPS), Managed VPS, SSL Certificates

Using Custom php.ini File for PHP (cli) via SSH

PHP
php, php cli, php shell, php ssh, php command line, php console, php-cli, php sapi, php sapi cli

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 -v
Check the version of PHP CLI
To see the current php.ini file (which will load every time by default), use:

php --ini
Check the loaded php.ini file (Loaded Configuration File)

In case you have not specified another file, PHP CLI will always use the default system php.ini file /usr/local/lib/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='/usr/local/php7.0/bin/php -c /home/cpuser/my-custom-php.ini'
/usr/local/php7.0/bin/php - replace php7.0 with the desired version;

info-iconNote: Also, if there are any irregularities in the .ini file such as unsupported directives from older PHP versions, you will get an error message in the console. For example: "Fatal error: Directive 'allow_call_time_pass_reference' is no longer available in PHP in Unknown on line 0". Make sure that the .ini file's content is intended for the current PHP version.

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

500px270px
SuperHosting.BG
    PHP
  • PHP Manager by SuperHosting
    In cPanel you can change the PHP settings for all hosting plans offered by SuperHosting.BG. You can change the PHP version, enable or disable PHP modules and change PHP directives. This... »
  • How to View My PHP Settings (Version, Directives, Modules)?
    For the PHP directives there are system values set by default. You can get information about them by calling the phpinfo() function. By using phpinfo you can view the PHP version, enabled PHP... »
  • PHP Modules (PHP Extensions)
    PHP modules are extensions mostly written in C language. They can be compiled with PHP to enable static loading (as part of the binary file) or dynamic loading (with the... »
  • How to Install and Use a PEAR Package?
    To start using a PEAR Package, first install it into your hosting account and then enable it for the PHP application/script. Installing a PEAR Package Automatic Installation in cPanel PEAR Packages are automatically... »
  • PEAR Packages
    PEAR (PHP Extension and Application Repository) is a framework and distribution system for reusable PHP components. PEAR packages are bundles of files written in PHP that can be embedded into PHP applications. PEAR packages... »
All rights reserved © 2005-2017 , www.superhosting.bg