i change nginx conf file with php next i want restart nginx. but can not restart nginx
<?php
if(exec("service nginx restart")) {
echo "ok shd";
} else {
echo "error";
}
?>
<hr>
<?php
if(exec("/etc/init.d/nginx reload")) {
echo "ok shd";
} else {
echo "error";
}
?>
<hr>
<?php
if(exec("/usr/sbin/nginx -s reload")) {
echo "ok shd";
} else {
echo "error";
}
?>
output is :
error<hr>
error<hr>
error
To do exec("service nginx restart")
I need acces to php-fpm as root, so i go to /usr/local/etc/php-fpm.conf
user = nobody
group = nobody
and change it to:
user = root
group = root
and next enter service php-fpm restart
output:
Starting php-fpm [11-Feb-2016 05:14:33] ERROR: [pool www] please specify user and group other than root
[11-Feb-2016 05:14:33] ERROR: FPM initialization failed
failed
and this means it can't be run as root.
So how can I restart or reload nginx using php?