Command line /usr/local/bin/php and PHP-FPM

ItsMattSon

Well-Known Member
Sep 5, 2016
182
38
103
Perth
cPanel Access Level
Root Administrator
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
 

ItsMattSon

Well-Known Member
Sep 5, 2016
182
38
103
Perth
cPanel Access Level
Root Administrator
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?
 

cPanelMichael

Administrator
Staff member
Apr 11, 2011
47,904
2,218
463
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.
 

ItsMattSon

Well-Known Member
Sep 5, 2016
182
38
103
Perth
cPanel Access Level
Root Administrator
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.
What is the difference between /usr/bin/php and /usr/local/bin/php?
The /usr/bin/php binary calls the PHP CGI handler. The /usr/local/bin/php binary calls the PHP command-line handler.


My php -v for each is:

[[email protected] ~]$ /usr/bin/php -v
ea-php-cli Copyright 2017 cPanel, Inc.
PHP 7.0.27 (cgi-fcgi) (built: Feb 7 2018 02:54:05)
Copyright (c) 1997-2017 The PHP Group
Zend Engine v3.0.0, Copyright (c) 1998-2017 Zend Technologies

[[email protected] ~]$ /usr/local/bin/php -v
ea-php-cli Copyright 2017 cPanel, Inc.
PHP 7.0.27 (cli) (built: Feb 7 2018 02:53:45) ( NTS )
Copyright (c) 1997-2017 The PHP Group
Zend Engine v3.0.0, Copyright (c) 1998-2017 Zend Technologies


With that said, I changed my MultiPHP INI Editor memory limit to 512M (in domain's cPanel) but it still says 128M as per the value set in MultiPHP INI Editor via WHM.

I definitely changed directory to /home/user/public_html before running php -r "echo ini_get('memory_limit');"

Any ideas?
 

cPanelMichael

Administrator
Staff member
Apr 11, 2011
47,904
2,218
463
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:

Code:
# cd /home/username/public_html/
# /usr/bin/php -i|grep memory_limit
<tr><td class="e">memory_limit</td><td class="v">128M</td><td class="v">128M</td></tr>
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:

Code:
# /usr/bin/php -i|grep memory_limit
<tr><td class="e">memory_limit</td><td class="v">65M</td><td class="v">65M</td></tr>
4. Enabled PHP-FPM for the account, repeated steps 1-3 above (except using 70M as the value), and confirmed it was properly reflected:

Code:
]# /usr/bin/php -i|grep memory_limit
<tr><td class="e">memory_limit</td><td class="v">70M</td><td class="v">70M</td></tr>
Can you verify which steps you are using to reproduce the issue, and which version of cPanel is installed on your system?

Thanks!
 

ItsMattSon

Well-Known Member
Sep 5, 2016
182
38
103
Perth
cPanel Access Level
Root Administrator
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.

Code:
/usr/bin/php -i | grep "Loaded Configuration"
<tr><td class="e">Loaded Configuration File </td><td class="v">/home/user/public_html/php.ini </td></tr>
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?
 

cPanelMichael

Administrator
Staff member
Apr 11, 2011
47,904
2,218
463
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:

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.
 
  • Like
Reactions: ItsMattSon

SoftDux

Well-Known Member
May 27, 2006
1,023
5
168
Johannesburg, South Africa
cPanel Access Level
Root Administrator
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:



Code:
 php -v
ea-php-cli Copyright 2017 cPanel, Inc.
PHP 7.0.33 (cli) (built: Feb 10 2019 12:54:41) ( NTS )

Code:
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

Code:
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?

Code:
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
 

cPanelMichael

Administrator
Staff member
Apr 11, 2011
47,904
2,218
463

Floyd John

Registered
Mar 31, 2018
1
0
1
Brasil
cPanel Access Level
Root Administrator
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?
 
Last edited: