【发布时间】:2016-05-22 05:21:21
【问题描述】:
我用 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?
【问题讨论】:
-
当您
shell_exec()或exec()时,您的用户是nginx,而不是root。 -
@phabarest:不,不是。这是关于 PHP,它不作为 nginx 进程组的一部分运行,更不用说它的 uid。
-
所以你removed你所有的代码都来自你的问题?