I need to execute some commands on my web server with php configured with apache.
exec("service apache2 restart", $output);
print_r($output);
output:
Array (
[0] => * Restarting web server apache2
[1] => Action 'start' failed.
[2] => The Apache error log may have more information.
[3] => ...fail!
)
My guess is it's because of permissions of php on my ubuntu! What do you suggest?
You need to run :
visudo
check that you have a line like
Host_Alias LOCAL=192.168.0.1
with your own local IP at the top of the file, then add a line
www-data LOCAL=NOPASSWD:/usr/bin/service
And last in your PHP file :
exec("/usr/bin/sudo /usr/bin/service apache2 restart");
(You are trying to restart apache by web, maybe you don't know webmin interface ? I think there's betters solutions than this sudo way. It's not a good thing to authorize www-data to stop, start (...) all the services. Better explain why you'd like to restart apache ;) )
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With