【问题标题】:How to set permissions in php for shell_exec command如何在 php 中为 shell_exec 命令设置权限
【发布时间】:2015-01-28 14:22:51
【问题描述】:

我需要在运行雪豹的 Mac 上运行 apache 作为 localhost 的 php 文件中通过 shell_exec 执行 ImageMagick 的 convert。我已经尝试了从这里的大量问题和解决方案中获得的各种提示、技巧、编辑和权限。但似乎没有什么能解决问题。下面的php文件突出了这个问题:

<?php
  echo shell_exec('whoami');  //daemon. I chown-ed convert by daemon
  apache_setenv('PATH', '/usr/local/bin:/usr/bin:/bin'); // this works: checked with getenv("PATH");
  echo shell_exec('cp /Users/fullpath/file.pdf  /Users/fullpath/file.pdf 2>&1'); // this works, so shell_exec works
echo shell_exec('/usr/local/bin/convert /Users/fullpath/file.pdf  /Users/fullpath/file.png  2>&1'); // this fails, convert: UnableToCreateTemporaryFile and then convert: NoImagesDefined

?>

我认为这是一个权限问题:但是在哪里,在哪个文件上?

编辑:完整的错误信息是:

convert: UnableToCreateTemporaryFile `/Users/fullpath/file.pdf': Permission denied @ error/pdf.c/ReadPDFImage/390.

convert: NoImagesDefined `/Users/fullpath/file.png' @ error/convert.c/ConvertImageCommand/3021.

【问题讨论】:

    标签: php macos permissions


    【解决方案1】:

    您正在成功执行convert,但随后convert 本身返回错误convert: UnableToCreateTemporaryFile and then convert: NoImagesDefined

    我认为这是基本问题的答案,可以在https://superuser.com/questions/819277/cant-convert-pdf-into-image-because-of-no-images-defined-error找到

    【讨论】:

    • 感谢您的建议。我尝试了which gs 并获得了路径/opt/local/bin,因此将其包含在apache_setenv 行中。我重新启动了apache。仍然会发生同样的错误。我将在问题中编辑完整的错误日志。
    猜你喜欢
    • 2011-04-04
    • 1970-01-01
    • 2021-09-05
    • 1970-01-01
    • 1970-01-01
    • 2022-01-09
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多