Command line /usr/local/bin/php and PHP-FPM
Hi guys,
So i'll try keep this as clear as I can but apologies in advance because I'm confused myself.
I have PHP-FPM enabled on my domain and I learned a day or so ago that configuration is done via YAML files which I've now sorted and phpinfo shows a 3G memory_limit and disable_functions shows just "system" for the sake of testing.
My issue is that whilst I think that's configured correctly for web browser I'm not so sure those configurations are being honored by the command line interpreter.
When I run a script in bash via /usr/local/bin/php and that script uses exec() it says the function is disabled. Also when I run a script that take more than say 2mb of memory, it lets me know that it bombed out because the allowed memory size was exhausted.
The exact error is: Allowed memory size of 134217728 bytes exhausted (tried to allocate 32768 bytes)
So how come I can't run scripts that need exec() even though I overrode PHP-FPM's default (yep, i know PHP-FPM disable it by default) and how come I can't run scripts that need more than 2mb of mem?
My only ideas are that 1) It's not looking at my /home/user/php.ini or /home/user/public_html/php.ini or my .user.ini. and 2) Though its called php it's actually php-cli which has its own INI somewhere?
Any pointers would be fantastic - Thanks
-
I've learned that the php-cli interpreter is /usr/local/bin/ea-php70 and the memory_limit is 128M because that is what is set in WHM's MultiPHP INI Editor. Same for disable_functions, if I remove exec my test script works. Is there a way to override this for php-cli per account so that these can remain as default for new accounts? 0 -
Is there a way to override this for php-cli per account so that these can remain as default for new accounts?
Hi Matt, You should be able to use the "/usr/bin/php" path for the EA4 php-cli package. It should find the version specified for the directory you are currently in (not the directory the file exists in). If you do not run the command from the document root for the domain (e.g. /home/username/public_html/), it will use the system default version. Thank you.0 -
Hi @cPanelMichael, Looks like the documentation doesn't agree with itself? Looks like /usr/bin/php is the cgi binary and /usr/local/bin/php is the cli binary? EasyApache 4 and the ea-php-cli Package - EasyApache 4 - cPanel Documentation What does the ea-php-cli package do? The ea-php-cli package installs the following PHP binaries: - /usr/bin/php " This executable uses the php-cli binary for the specified PHP version.
- /usr/local/bin/php " This executable uses the php-cgi binary for the specified PHP version.
0 -
Hi Matt, Here's an example of the steps I took in an effort to reproduce this: 1. Browsed to /home/username/public_html via SSH and checked the PHP memory_limit: # cd /home/username/public_html/ # /usr/bin/php -i|grep memory_limit memory_limit 128M 128M
2. Browsed to cPanel >> MultiPHP INI Editor for this account, selected the primary domain name and changed the memory limit PHP value to 65M. 3. Repeated step 1, and noticed the updated value:# /usr/bin/php -i|grep memory_limit memory_limit 65M 65M
4. Enabled PHP-FPM for the account, repeated steps 1-3 above (except using 70M as the value), and confirmed it was properly reflected:]# /usr/bin/php -i|grep memory_limit memory_limit 70M 70M
Can you verify which steps you are using to reproduce the issue, and which version of cPanel is installed on your system? Thanks!0 -
Hi Michael, Your test returns the same results for me, same observations, but sorry to cut that short I think I need to start over to explain what's going on here at least for me. /usr/bin/php (cgi-fcgi) honours the current/working directory ini file (/home/user/public_html/php.ini) IF it exists, which it does if you Save your cPanel MultiPHP INI Editor settings. I know this by checking the Loaded Configuration File line with the below command similar to yours. That line shows /home/user/public_html/php.ini if it exists otherwise if shows /opt/cpanel/ea-php70/root/etc/php.ini which hosts the WHM MultiPHP INI Editor settings. So /usr/bin/php appears to load the local values - cool. /usr/bin/php -i | grep "Loaded Configuration" Loaded Configuration File /home/user/public_html/php.ini
However, the same cannot be said for /usr/local/bin/php... /usr/local/bin/php (cli) does not honour the /home/public_html/php.ini at all, even if it exists. It always loads /opt/cpanel/ea-php70/root/etc/php.ini whether you're in the public_html directory or not. Perhaps this is by design but this really makes it hard to run Magento 2 commands from the command line, as it's pulling the WHM memory_limit (128M) from /opt/cpanel/ea-php70/root/etc/php.ini instead of using the 2G limit I set in /home/user/public_html/php.ini via cPanel MultiPHP INI Editor. Magento's upgrade needs min 768M but recommended 2G (crazy, i know). I can pass the directives to the binary directly with the -d switch which is a work-around but it is not preferable... (ie. /usr/local/bin/php -d memory_limit=2G /home/user/public_html/bin/magento setup:upgrade). Is it possible to have the CLI binary honour the account's INIs?0 -
However, the same cannot be said for /usr/local/bin/php... /usr/local/bin/php (cli) does not honour the /home/public_html/php.ini at all, even if it exists. It always loads /opt/cpanel/ea-php70/root/etc/php.ini whether you're in the public_html directory or not. Perhaps this is by design but this really makes it hard to run Magento 2 commands from the command line, as it's pulling the WHM memory_limit (128M) from /opt/cpanel/ea-php70/root/etc/php.ini instead of using the 2G limit I set in /home/user/public_html/php.ini via cPanel MultiPHP INI Editor. Magento's upgrade needs min 768M but recommended 2G (crazy, i know). I can pass the directives to the binary directly with the -d switch which is a work-around but it is not preferable... (ie. /usr/local/bin/php -d memory_limit=2G /home/user/public_html/bin/magento setup:upgrade). Is it possible to have the CLI binary honour the account's INIs?
Hi Matt, It looks like you've encountered an issue we have an internal case open to address. Internal case CPANEL-17535 is open to improve our implementation of PHP-CLI so that it properly detects the use of PHP-FPM. Additionally, while not entirely related to the issue you are currently facing, another open case to be aware of is CPANEL-15923. Here's a brief summary of this case: [QUOTE] When a customer uses PHP-FPM, the "AddType" directive is commented out from the domain's DocRoot's .htaccess file. This causes the "ea-php-cli" binary (/usr/bin/php & /usr/local/bin/php) to be unable to detect the PHP version set for that domain via MultiPHP Manager. This means that cron jobs and shell executed PHP using ea-php-cli will often run the incorrect version of PHP for the domain.
Update: Internal case CPANEL-23538 will address the issue reported as part of CPANEL-17535. Thank you.0 -
I am sitting with the same problem. Both WHM and cPanel is set to use PHP 7.2, but in shell I still get PHP 7.0: php -v ea-php-cli Copyright 2017 cPanel, Inc. PHP 7.0.33 (cli) (built: Feb 10 2019 12:54:41) ( NTS )
ea-php70 -v PHP 7.0.33 (cli) (built: Feb 10 2019 17:39:23) ( NTS ) Copyright (c) 1997-2017 The PHP Group Zend Engine v3.0.0, Copyright (c) 1998-2017 Zend Technologies
ea-php71 -v PHP 7.1.26 (cli) (built: Feb 10 2019 17:54:56) ( NTS ) Copyright (c) 1997-2018 The PHP Group Zend Engine v3.1.0, Copyright (c) 1998-2018 Zend Technologies
How do I get shell to use PHP 7.2?ea-php72 -v PHP 7.0.33 (cli) (built: Feb 10 2019 12:54:41) ( NTS ) Copyright (c) 1997-2017 The PHP Group Zend Engine v3.0.0, Copyright (c) 1998-2017 Zend Technologies
0 -
Hello @SoftDux, We provide an overview of how the PHP-CLI package works at: EasyApache 4 and the ea-php-cli Package - EasyApache 4 - cPanel Documentation Can you verify which directory you are running that command from, and if you are logged in as "root"? Also, which cPanel & WHM version is installed on the system? Thank you. 0 -
I agree with ItsMattSon, I think the documentation is wrong. I've already spent some time trying to understand. The documentation says /usr/local/bin/php will use CLI, ie in theory max_execution_time would be set to 0. But look what happens: WHM has max_execution_time 30s by default and php.ini from an "anyaccount" account contains local settings with max_execution_time 600s. When I run a cpanel cron task using /usr/local/bin/php I get "Fatal error: Maximum execution time of 30 seconds exceeded in". That is, /usr/local/bin/php cannot be using CLI. Please, any ideas on this? 0
Please sign in to leave a comment.
Comments
9 comments