The Community Forums

Interact with an entire community of cPanel & WHM users!
  1. This site uses cookies. By continuing to use this site, you are agreeing to our use of cookies. Learn More.

Enable shell_exec() on internal cPanel PHP (for cPanel plugin)

Discussion in 'cPanel Developers' started by mikelegg, Oct 14, 2011.

  1. mikelegg

    mikelegg Well-Known Member

    Joined:
    Mar 29, 2005
    Messages:
    330
    Likes Received:
    0
    Trophy Points:
    16
    I'm developing a simple cPanel plugin using LivePHP that runs a couple of bash commands via shell_exec().

    When I run it I get this error ...

    PHP:
    Warningshell_exec() has been disabled for security reasons in /usr/local/cpanel/base/frontend/x3/mypluginname/myfilename.livephp on line x
    /usr/local/cpanel/3rdparty/etc/php.ini has this setting ...
    PHP:
    disable_functions    = ;
    So I can't work out why the plugin says that shell_exec() has been disabled.

    Which php.ini file does LivePHP use?
     
  2. mikelegg

    mikelegg Well-Known Member

    Joined:
    Mar 29, 2005
    Messages:
    330
    Likes Received:
    0
    Trophy Points:
    16
    I tried to find the php.ini file via phpinfo(), but got the error ...

    PHP:
    Warningphpinfo() has been disabled for security reasons in /usr/local/cpanel/base/frontend/x3/mypluginname/phpinfo.livephp on line x
     
  3. ModServ

    ModServ Well-Known Member

    Joined:
    Oct 17, 2006
    Messages:
    332
    Likes Received:
    5
    Trophy Points:
    18
    Location:
    Egypt
    cPanel Access Level:
    Root Administrator
    You need to remove these functions from /usr/local/lib/php.ini

    To check function existence:
    PHP:
    grep -iw "shell_exec" /usr/local/lib/php.ini
    If exist you will get the whole functions so just remove it from the file and restart apache.
     
  4. mikelegg

    mikelegg Well-Known Member

    Joined:
    Mar 29, 2005
    Messages:
    330
    Likes Received:
    0
    Trophy Points:
    16
    Thanks for that, I'd just done a search for all php.ini files on the server and was working my way through all the likely ones.
     
  5. ModServ

    ModServ Well-Known Member

    Joined:
    Oct 17, 2006
    Messages:
    332
    Likes Received:
    5
    Trophy Points:
    18
    Location:
    Egypt
    cPanel Access Level:
    Root Administrator
    Hi,

    You welcome, And if you need anything in BASH just let me know.

    Thanks,
     
  6. mikelegg

    mikelegg Well-Known Member

    Joined:
    Mar 29, 2005
    Messages:
    330
    Likes Received:
    0
    Trophy Points:
    16
    Thanks for the offer.

    The Bash stuff is really simple - it's just 2 lines to fix file and folder permissions inside the public_html folder to make them compatible with suPHP (644/755) I've been running the commands manually for years but I just wanted to create a cPanel plugin so that customers can just click a button and fix the permissions themselves.

    I've almost finished it.
     
  7. ModServ

    ModServ Well-Known Member

    Joined:
    Oct 17, 2006
    Messages:
    332
    Likes Received:
    5
    Trophy Points:
    18
    Location:
    Egypt
    cPanel Access Level:
    Root Administrator
    That's great, I'm thinking of creating a lot of plugins but my problem is that I'm not an expert in PHP neither Perl.
     
  8. mikelegg

    mikelegg Well-Known Member

    Joined:
    Mar 29, 2005
    Messages:
    330
    Likes Received:
    0
    Trophy Points:
    16
    The part I find hardest is getting my mind around how the cPanel integration works.
     
  9. ModServ

    ModServ Well-Known Member

    Joined:
    Oct 17, 2006
    Messages:
    332
    Likes Received:
    5
    Trophy Points:
    18
    Location:
    Egypt
    cPanel Access Level:
    Root Administrator
    Yeah, API is blowing my mind till this moment :D

    Good luck with your plugin.
     
  10. mikelegg

    mikelegg Well-Known Member

    Joined:
    Mar 29, 2005
    Messages:
    330
    Likes Received:
    0
    Trophy Points:
    16
    It's just dawned on me that /usr/local/lib/php.ini is used by the default PHP configuration that customers web sites use - so I've had to disable shell_exec() again which means my plugin won't work.

    I assumed LivePHP would have used cpsrvd rather than the public web server.

    Looks like I'll have to start from scratch and not use LivePHP.
     
    #10 mikelegg, Oct 14, 2011
    Last edited: Oct 14, 2011
  11. mikelegg

    mikelegg Well-Known Member

    Joined:
    Mar 29, 2005
    Messages:
    330
    Likes Received:
    0
    Trophy Points:
    16
    OK, I've re-written my plugin using the old method instead of LivePHP.

    According to CpanelPhp < SoftwareDevelopmentKit < TWiki the relevant php.ini is /usr/local/cpanel/3rdparty/etc or /var/cpanel/3rdparty/etc

    (In my case it's /usr/local/cpanel/3rdparty/etc)

    This php.ini contains
    PHP:
    disable_functions    = ; 
    But I'm still getting ...
    PHP:
    Warningshell_exec() has been disabled for security reasons in /tmp/cpanel_phpengine.1318648444.24620AVb0p9xNbT on line 150
    So back to my original question - what do I have to do to enable shell_exec() on cPanel's custom PHP binary?
     
  12. mikelegg

    mikelegg Well-Known Member

    Joined:
    Mar 29, 2005
    Messages:
    330
    Likes Received:
    0
    Trophy Points:
    16
    OK here's the answer ...

    cPanel/WHM was incorrectly using the public php.ini (/usr/local/lib/php.ini) instead of /usr/local/cpanel/3rdparty/etc/php.ini.

    I fixed the problem by running /scripts/makecpphp
     
  13. ModServ

    ModServ Well-Known Member

    Joined:
    Oct 17, 2006
    Messages:
    332
    Likes Received:
    5
    Trophy Points:
    18
    Location:
    Egypt
    cPanel Access Level:
    Root Administrator
    Glad to hear that.

    Good luck :)
     
  14. Brian

    Brian Well-Known Member

    Joined:
    Dec 1, 2010
    Messages:
    117
    Likes Received:
    2
    Trophy Points:
    18
    Location:
    Texas
    cPanel Access Level:
    Root Administrator
    Some further clarification here. /scripts/makecpphp shouldn't have been necessary.

    What seems likely is that you did not have the touch file that is on cPanel/WHM installs by default:

    /var/cpanel/usecpphp

    When that empty file exists (which it does by default), cPanel/WHM uses the internal cP PHP build out of /usr/local/cpanel/3rdparty (or if custom built, /var/cpanel/3rdparty). So, it sounds like this was removed on your server which would've intentionally caused cPanel/WHM to utilize the main system PHP.

    /scripts/makecpphp would've coincidentally created /var/cpanel/usecpphp, hence why it resolved the matter for you. However, rebuilding cP PHP would not have been necessary.
     
  15. mikelegg

    mikelegg Well-Known Member

    Joined:
    Mar 29, 2005
    Messages:
    330
    Likes Received:
    0
    Trophy Points:
    16
    Thanks Brian

    I've installed the plugin on 3 servers so far and found the same situation on each one.

    Creating /var/cpanel/usecpphp is a lot quicker than running /scripts/makecpphp, so I'll use that on the rest.
     
  16. mambovince

    mambovince Well-Known Member

    Joined:
    Jan 15, 2005
    Messages:
    192
    Likes Received:
    0
    Trophy Points:
    16
    Location:
    London, UK
    Interesting, I just had same issue running latest STABLE version.
    WHM 11.30.5 (build 3)
    CENTOS 5.7 x86_64 virtuozzo

    And I see no /var/cpanel/usecpphp file.

    As Fantastico installs have worked without this issue for years, is it possible that latest build deleted the /var/cpanel/usecpphp file somehow?

    - Vincent
     
Loading...
Similar Threads - Enable shell_exec() internal
  1. jvandellen
    Replies:
    3
    Views:
    383
  2. sparek-3
    Replies:
    2
    Views:
    275

Share This Page