Reputation: 257
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
Upvotes: 4
Views: 22756
Reputation: 270599
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.
Upvotes: 6
Reputation: 651
Try look at the disable function in php.ini
disable_functions = exec
Upvotes: 0