duan0714
2011-12-29 13:07
浏览 56
已采纳

PHP shell_exec,执行-rwxrwxrwx shell脚本的权限被拒绝

I am currently over ssh on a remote CentOS 5.6 system which runs an Apache webserver. I need to use the poppler pdftohtml binary which, unfortunately, is not currently installed on that machine. So I downloaded the poppler package and built it under my user folder. Since I I am not the system admin, I didn't do

make install

and I have all my compiled files under

/users/myfolder/poppler-0.18.2/

The file that I need to execute through php shell_exec() is

/users/myfolder/poppler-0.18.2/utils/pdftohtml

If I execute it through my ssh bash, I get the correct output. If I, instead, put this line on a php script:

echo shell_exec("/users/myfolder/poppler-0.18.2/utils/pdftohtml");

I get the following output:

sh: /users/myfolder/poppler-0.18.2/utils/pdftohtml: Permission denied

I tried setting to 777 the file permissions, which currently are -rwxrwxrwx. I also noticed that using shell_exec("whoami"); results in "apache". Shouldn't apache be able to execute the script if the file permissions are -rwxrwxrwx?

I also know that installing poppler through make install would solve the problem but since this is for testing purpose, I would like to avoid "contaminating" the system outside my personal folder until the testing is complete.

Thanks to anyone who will help!

图片转代码服务由CSDN问答提供 功能建议

我目前在运行Apache网络服务器的远程CentOS 5.6系统上使用ssh。 我需要使用poppler pdftohtml 二进制文件,遗憾的是,该二进制文件当前未安装在该计算机上。 所以我下载了poppler包并在我的用户文件夹下构建它。 由于我不是系统管理员,我没有做

  make install 
   
 
 

我拥有所有 我编译的文件

  /users/myfolder/poppler-0.18.2/
   
 
 

我的文件 需要通过php执行 shell_exec()

  /users/myfolder/poppler-0.18.2/utils/pdftohtml
    
 
 

如果我通过ssh bash执行它,我会得到正确的输出。 相反,如果我把这一行放在php脚本上:

  echo shell_exec(“/ users / myfolder / poppler-0.18.2 / utils / pdftohtml”); 
    
 
 

我得到以下输出:

  sh:/users/myfolder/poppler-0.18.2/utils/  pdftohtml:权限被拒绝
   
 
 

我尝试将文件权限设置为777,目前为-rwxrwxrwx。 我还注意到使用 shell_exec(“whoami”); 会产生“apache”。 如果文件权限是-rwxrwxrwx,apache是​​否应该能够执行脚本?

我也知道通过 make install 安装poppler会解决问题但是 由于这是出于测试目的,我希望避免在我的个人文件夹外“污染”系统,直到测试完成。

感谢任何有帮助的人! \ n

  • 写回答
  • 好问题 提建议
  • 关注问题
  • 收藏
  • 邀请回答

1条回答 默认 最新

  • duannai1883 2011-12-29 13:50
    已采纳

    Just because a file is executable for a user does not mean that user is actually able to execute the file. The user needs to also be able to 'get to' the file: The user needs execution permission for all 'parent directories', in your case for /users, myfolder, poppler-0.18.2 and utils.

    Assuming /users is the same basic thing as /home, everybody should have +x on that. From there, you can set it: simply do chmod o+x /users/myfolder /users/myfolder/poppler-0.18.2 /users/myfolder/poppler-0.18.2/utils

    (Note: This will make it possible for everybody to execute this binary, not just Apache.)

    If the apache user and you share a group, it would be better to use chown the poppler directory and everything in to be owned by that group, and set g+x instead of o+x.

    已采纳该答案
    评论
    解决 无用
    打赏 举报

相关推荐 更多相似问题