简体   繁体   中英

Some commands do run with PHP exec() others don't, how can I avoid/fix this?

  • Server is CentOS, I don't have root access.
  • I can run exec() without problem with pngquant but not with ImageMagick's convert
  • I get "Permission denied" when trying to open the image file with convert but works fine with pngquant (notice that both commands open same image file in same folder, same permissions, same user, etc).
  • Since I don't have root access, I've built ImageMagick and added it to the PATH.
  • From command line convert works perfect (user has enough privileges to read/write the image files).
  • PHP tries to run exec('convert ...') or shell_exec('convert ...') as nobody, this means echo shell_exec('whoami'); returns "nobody". Same for pngquant but with successful result (no "Permission denied" problem).

Any clues?

Since I don't have root access, I've built ImageMagick and added it to the PATH.

What are the permissions on the binary you created? Sounds like you—as the user—have rights to execute the binary. But PHP—who is running as nobody —does not have execution rights. I bet your binary permissions for what you created are something like 744 or maybe even 700 ? I would recommend chmod 755 on the binaries you created and try again.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM