2

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.

3 Answers 3

3

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

1
  • when access from browser, the user is apache not www. I also believe it is permissions problem, but just do not known how to solve
    – cheng
    Mar 9, 2011 at 14:17
1

Try this

chmod 755 a.out
chmod 666 temp
1
  • Try this 'echo "dev" > temp', is this execute from web?
    – azat
    Mar 9, 2011 at 14:23
1

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

su www-data

And then execute the command again.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.