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

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

问题描述

我有一个 C++ 可执行文件skypeforwarder".如果我在 Mac 的终端中使用命令行,skypeforwarder 可以工作:henry$/Users/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.

此外,非常建议将文件更改为由 _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天全站免登陆