PHP shell_exec,执行 -rwxrwxrwx shell 脚本的权限被拒绝
我目前在运行 Apache Web 服务器的远程 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: Permission denied
我尝试将文件权限设置为 777,当前为 -rwxrwxrwx。我还注意到使用 shell_exec("whoami");
会产生“apache”。如果文件权限是-rwxrwxrwx,apache 不应该能够执行该脚本吗?
我也知道通过 make install
安装 poppler 可以解决问题,但由于这是出于测试目的,我想避免在测试完成之前“污染”我个人文件夹之外的系统。
感谢任何愿意提供帮助的人!
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!
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
仅仅因为文件对于用户来说是可执行的,并不意味着用户实际上能够执行该文件。用户还需要能够“访问”文件:用户需要所有“父目录”的执行权限,在您的情况下为 /users、myfolder、poppler-0.18.2 和 utils。
假设 /users 与 /home 是相同的基本内容,每个人都应该在上面有 +x 。从那里,您可以设置它:只需执行
chmod o+x /users/myfolder /users/myfolder/poppler-0.18.2 /users/myfolder/poppler-0.18.2/utils
(注意:这将使每个人都可以执行这个二进制文件,而不仅仅是 Apache。)
如果 apache 用户和您共享一个组,那么最好使用 chown poppler 目录以及其中的所有内容都归该组所有,并设置 g+x 而不是 o+x。
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.