shell whoami doesn't equal php shell_exec whoami?

后端 未结 4 928
挽巷
挽巷 2021-01-07 10:37

In a shell I do simple whoami and I get geoff, which is good, since that\'s who I am.

In a php file I have shell_exec(\'whoami\'); and I get nobody.

This see

相关标签:
4条回答
  • 2021-01-07 11:06

    The result from whoami you obtained simply means that your apache is running as nobody. This is as it should be and I strongly recommend not to change this.

    The reason imagemagick doesn't work isn't probably directly related to the privileges with which your php code is run. There isn't enough information to diagnose the problem exactly, but it is most likely an executable or library search failure. Make sure that the binary and libraries are readable by nobody and that they are in a location where apache will find them. In particular ensure that $PATH and $LD_LIBRARY_PATH are set up correctly.

    0 讨论(0)
  • 2021-01-07 11:07

    @anubhava is correct about why you get two different answers when you run whoami. However, if you're trying to convert a PDF to a PNG using ImageMagick (like in your comment on the question), even using the full path to ImageMagick's convert won't work if the script's PATH doesn't contain the path location to Ghostscript also. Without messing with any user paths, you could add:

    putenv("PATH=/usr/local/bin:/usr/bin:/bin");
    

    Or something similar depending on your setup. The gs executable has to be in your script user's path somewhere or ImageMagick will fail to convert PDF or EPS files.

    0 讨论(0)
  • 2021-01-07 11:07
    1. add "2>&1" to your command
    2. specify the full path to shell_exec(nobody has no $PAHT, so it just don't know where imagemagic binary is stored.
    3. try to run the script as user on the console to see that is going wrong.
    0 讨论(0)
  • 2021-01-07 11:09

    It should be simple to understand.

    • In shell you are logged in as Unix user geoff and that's what you get.
    • PHP is run in a httpd process in Unix which has nobody as the owner hence that's what you get when you shell_exec('whoami'); from PHP.
    0 讨论(0)
提交回复
热议问题