cheng
cheng

Reputation: 2146

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 into the "temp" file so that I can see what is wrong.

Thanks.

Upvotes: 2

Views: 581

Answers (3)

the JinX
the JinX

Reputation: 1980

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 . .

Upvotes: 3

powtac
powtac

Reputation: 41070

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

su www-data

And then execute the command again.

Upvotes: 1

azat
azat

Reputation: 3565

Try this

chmod 755 a.out
chmod 666 temp

Upvotes: 1

Related Questions