Please whitelist cPanel in your adblocker so that you’re able to see our version release promotions, thanks!

The Community Forums

Interact with an entire community of cPanel & WHM users!

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

Discussion in 'General Discussion' started by ItsMattSon, Feb 24, 2018.

Tags:
  1. ItsMattSon

    ItsMattSon Well-Known Member

    Joined:
    Sep 5, 2016
    Messages:
    167
    Likes Received:
    34
    Trophy Points:
    103
    Location:
    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
     
  2. ItsMattSon

    ItsMattSon Well-Known Member

    Joined:
    Sep 5, 2016
    Messages:
    167
    Likes Received:
    34
    Trophy Points:
    103
    Location:
    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?
     
  3. cPanelMichael

    cPanelMichael Forums Analyst
    Staff Member

    Joined:
    Apr 11, 2011
    Messages:
    43,961
    Likes Received:
    1,821
    Trophy Points:
    363
    cPanel Access Level:
    Root Administrator
    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.
     
    Stop hovering to collapse... Click to collapse... Hover to expand... Click to expand...
  4. ItsMattSon

    ItsMattSon Well-Known Member

    Joined:
    Sep 5, 2016
    Messages:
    167
    Likes Received:
    34
    Trophy Points:
    103
    Location:
    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:

    [me@srv ~]$ /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

    [me@srv ~]$ /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?
     
  5. cPanelMichael

    cPanelMichael Forums Analyst
    Staff Member

    Joined:
    Apr 11, 2011
    Messages:
    43,961
    Likes Received:
    1,821
    Trophy Points:
    363
    cPanel Access Level:
    Root Administrator
    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!
     
    Stop hovering to collapse... Click to collapse... Hover to expand... Click to expand...
  6. ItsMattSon

    ItsMattSon Well-Known Member

    Joined:
    Sep 5, 2016
    Messages:
    167
    Likes Received:
    34
    Trophy Points:
    103
    Location:
    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?
     
  7. cPanelMichael

    cPanelMichael Forums Analyst
    Staff Member

    Joined:
    Apr 11, 2011
    Messages:
    43,961
    Likes Received:
    1,821
    Trophy Points:
    363
    cPanel Access Level:
    Root Administrator
    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:

    Thank you.
     
    Stop hovering to collapse... Click to collapse... Hover to expand... Click to expand...
    ItsMattSon likes this.
Loading...

Share This Page

  1. This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
    By continuing to use this site, you are consenting to our use of cookies.
    Dismiss Notice