php and exec

Discussion in 'General' started by mrxUx, Oct 1, 2012.

  1. mrxUx

    mrxUx Member

    a quick question, maybe already answered but I couldn't find anything yet, so please excuse me :)

    I'm using cPanel + LiteSpeed, and for example, I have the following code on a php script:

    echo ":: ".`which convert`;
    Which should come up with the full path of convert (part of imagemagick), however is returning empty, now if I do the same from the user's shell by executing the php: "sudo -u user php -f file.php" y do get the right path.

    Another funny thing is, if instead I use `which --help` it works in both and actually "convert" does work without problems, so I'm kinda confused here :)
  2. mistwang

    mistwang LiteSpeed Staff

    You can set "PATH=...." in lsphp5 "Environment" configuration.
  3. mrxUx

    mrxUx Member

    Not sure if the issue is there, let me go deeper and show you with a small php script I did to print stuff over LiteSpeed:


    // no big deal, it will just execute things and print them nice
    out("echo \$PATH");
    out("ls /usr/bin/which");
    out("ls /usr/bin/convert");    
    out("/usr/bin/which --version");
    out("/usr/bin/convert --version");
    out("/usr/bin/which convert");

    out($cmd) {
    $out trim(`$cmd`);
    ":: [$cmd]\n\t$out\n\n";
    This was the result:

    :: [echo $PATH]
    :: [ls /usr/bin/which]
    :: [ls /usr/bin/convert]
    :: [/usr/bin/which --version]
    	GNU which v2.19, Copyright (C) 1999 - 2008 Carlo Wood.
    GNU which comes with ABSOLUTELY NO WARRANTY;
    This program is free software; your freedom to use, change
    and distribute this program is protected by the GPL.
    :: [/usr/bin/convert --version]
    	Version: ImageMagick 6.7.1-7 2012-09-15 Q16
    Copyright: Copyright (C) 1999-2011 ImageMagick Studio LLC
    Features: OpenMP
    :: [/usr/bin/which convert]
    I hope this helps, as some Gallery scripts try to "autodetect" some binaries but the problem here is that "which" is not giving the right path.
  4. NiteWave

    NiteWave Administrator

    my local test not empty, show " /usr/bin/convert" correctly:
  5. mrxUx

    mrxUx Member

    I guess you're testing it as root, how about using a non privileged user?

    Thanks for the updates guys :)
  6. NiteWave

    NiteWave Administrator

    tested with root, also tested with nobody

    access it through browser, it runs under lsphp5 user -- nobody.

    you can add
    to confirm it.
  7. mrxUx

    mrxUx Member

    I'm running out of ideas, not sure what it could be but the funny thing is that this issue happens on all the servers we have.

    Why it can execute "which" and only be able to get the help? :(
  8. webizen

    webizen Well-Known Member

    are you able to reproduce the issue in Apache?
  9. mrxUx

    mrxUx Member

    @webizen, yes Sir, this is the output:

  10. NiteWave

    NiteWave Administrator

    not sure why yet, but following tests may inspire others:
    echo "<pre>";
    out("echo \$PATH");
    out("echo $PATH");
    out("PATH=/usr/local/bin:/bin:/usr/bin /usr/bin/which ls");
    out("/usr/bin/which ls");

    out($cmd) {
    $out = `$cmd`;
    ":: [$cmd]\n\t$out\n";
    the output(in browser):
  11. NiteWave

    NiteWave Administrator

    1.the output of which is correct. since $PATH is empty
    2.the output of "env", no PATH, this also show that $PATH is empty
    3.why $PATH is empty, need further investigate.
    in exterl app lsphp5's definition, add
    to Environment, the output is what expected: local linux box, without set PATH explicitly in lsphp5's Environment, it still show PATH:
  12. mrxUx

    mrxUx Member

    @Nitewave: amazing :) this should be something configured by default isn't it? at least for the ones that use it with cPanel/WHM and dual PHP.

    Thanks for the help!

Share This Page