php exec() command permission denied

家住魔仙堡 提交于 2019-12-30 05:13:10

问题


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

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); 

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

to

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

It still does not work.

I set the apache in my mac according to http://foundationphp.com/tutorials/php_leopard.php


回答1:


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.

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

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

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




回答2:


Try look at the disable function in php.ini

disable_functions = exec


来源:https://stackoverflow.com/questions/10236091/php-exec-command-permission-denied

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!