php exec()命令权限被拒绝 [英] php exec() command permission denied

查看:739
本文介绍了php exec()命令权限被拒绝的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个C ++可执行文件'skypeforwarder'.如果我在Mac的终端机中使用命令行,skypeforwarder可以使用: henry $/用户/henry/Desktop/skypeForwarder/skypekit-sdk_sdk-4.1.2.20_793394/examples/cpp/tutorial/step3/skypeForwarder

I have a C++ executable file 'skypeforwarder'. skypeforwarder works if I use command line in Terminal in Mac: henry$ /Users/henry/Desktop/skypeForwarder/skypekit-sdk_sdk-4.1.2.20_793394/examples/cpp/tutorial/step3/skypeForwarder

sh: /Users/henry/Desktop/skypeForwarder/skypekit-sdk_sdk-4.1.2.20_793394/examples/cpp/tutorial/step3/skypeForwarder: Permission denied

但是如果它在php exec()中被调用,它总是会发出权限被拒绝"的信息.

But it always issued 'permission denied' if it is called in php exec();

<?php 
echo exec('whoami');

$output = null;

$execBuild = '/Users/henry/Desktop/skypeForwarder/skypekit-sdk_sdk-4.1.2.20_793394/examples/cpp/tutorial/step3/';
$execBuild .= 'skypeForwarder';

$n  = exec($execBuild, $output); 

我搜索了很多.问题应该是Web服务器中的php/browser权限问题.我还尝试从以下位置更改文件的所有者:

I searched a lot. The problem should be the problem of the php/browser permission in web server. I also tried to change the owner of the file from:

-rwxr-xr-x  1 henry  staff  1212716 19 Apr 11:23 skypeForwarder

-rwxr-xr-x  1 _www  staff  1212716 19 Apr 11:23 skypeForwarder

它仍然不起作用.

我根据 http://foundationphp.com/tutorials/php_leopard.php在我的Mac中设置了Apache

推荐答案

尽管Web服务器可以读取文件本身,但Desktop文件夹很可能无法读取,因此Web服务器无法遍历该文件来定位可执行文件.您应该将skypeforwarder二进制文件移动到Web服务器可读的位置,例如与尝试提供该PHP脚本的位置平行的目录.但是,该目录不能通过网络访问.使用.htaccess保护它,或将其放置在Web DocumentRoot上方,但Web服务器必须可读.

Although the file itself is readable by the web server, the Desktop folder most likely is not, and the web server therefore cannot traverse into it to locate the executable file. You should move the skypeforwarder binary file into a location readable by the web server, such as a directory parallel to where you are attempting to serve this PHP script. That directory should not, however, be web-accessible. Protect it with .htaccess or place it above the web DocumentRoot, but it must be readable by the web server.

默认情况下,OSX上的Desktop-rwxr------,建议不要更改该目录上的权限 .

By default, Desktop on OSX is -rwxr------ and it is not advisable to change permissions on that directory.

此外, 最好不要更改Web服务器用户_www拥有和可写的文件.相反,它应该可由Web服务器读取和执行,但不可写.

Moreover, it is very much not advisable to change the file to be owned and writable by _www the web server user. Instead, it should be readable and executable by the web server, but not writable.

chown henry skypeforwarder
chmod 755 skypeforwarder

标准免责声明:与往常一样,从网络上可访问的PHP脚本执行系统调用时要格外小心.

Standard disclaimer: As always, be extremely cautious when executing system calls from PHP scripts accessible on the web.

这篇关于php exec()命令权限被拒绝的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆