我用php改变nginx conf文件,我想重启nginx。但无法重启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";
}
?>
输出是:
error<hr>
error<hr>
error
要做exec("service nginx restart")
我需要以root身份访问php-fpm,所以我去/usr/local/etc/php-fpm.conf
user = nobody
group = nobody
并将其更改为:
user = root
group = root
然后进入service php-fpm restart
输出:
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
这意味着它不能以root身份运行。
那么如何使用php重新启动或重新加载nginx呢?