When using PHP commands via the terminal, it reads the system php.ini instead of the local one, so any local settings are not recognized.
To enable the PHP command to read the local php.ini file along with its options, you need to add the path to that php.ini file.
For a list and help with PHP commands, you can use the command:
To list the php.ini files and their locations that are loaded without specifying a path, i.e., the default ones:
Now we want to use our local php.ini:
php -c /home/username/path/to/php.ini /home/username/public_html/file.php
In this part, we have the PHP command that starts, -c which tells which php.ini file to use and you should provide the full path to your file. If it’s in the public_html, it should be /home/username/public_html/php.ini, and replace ‘username’ with your username. If it’s an addon domain, it’s another folder and path to the php.ini in that other folder. After the php.ini part, add the path to the file you are calling, like in our example file.php.
This way, you’ve run the file with the php.ini from the desired location.
If you have multiple commands and use them often, you can add a line to .bash_profile to avoid typing the path every time:
alias php='php -c /home/username/path/to/php.ini'
Now, if you run php –ini again, it would show your local php.ini file.
Also, for other PHP versions, use ea-phpXX instead of PHP (replace xx with the PHP version, such as 74, 80, etc.).