开发者

php call c++ socket function cause Permission denied error

I have a php code:

<?php
$res = "";
exec("./a.out>temp", $res);
print_r(error_get_last());
print_r($res);
?>

a.out is a simple c++ program creating a socket. when I call this php code from browser an error of "Permission denied" is printed in the "temp" file.

I know this is a problem related to the right of apache user, but how to solve it?

Note: I have redirected the stderr int开发者_开发知识库o the "temp" file so that I can see what is wrong.

Thanks.


Perhaps the 'www' (or apache) users permissions are the problem.

Another option is that the socket already exists . .

Perhaps it is a problem with SE linux (if you are on linux)

/usr/sbin/setsebool httpd_can_network_connect=1

Source: http://www.rkrishardy.com/2009/12/permission-denied-13-when-opening-socket-in-php-apache/

On a side note, php can do socket stuff as-well . .


Try this

chmod 755 a.out
chmod 666 temp


Change your user to the one which is executing your apache. For example like this:

su www-data

And then execute the command again.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜