通过php重启nginx不起作用

时间:2016-09-15 15:25:53

标签: php ubuntu nginx

我正在尝试从php重新启动nginx

问题是当我从命令行输入代码时,一切正常 但是从我的PHP 我把它作为输出

* Restarting nginx nginx ...fail!

我的PHP代码是

 echo   shell_exec ("service nginx restart");

档案权限7777

nginx错误日志

2016/09/15 15:17:13 [emerg] 2872#0: open() "/run/nginx.pid" failed (13: Permission denied)
2016/09/15 15:30:30 [warn] 2997#0: the "user" directive makes sense only if the master process runs with super-user privileges, ignored in /etc/nginx/nginx.conf:1
2016/09/15 15:30:30 [emerg] 2997#0: open() "/run/nginx.pid" failed (13: Permission denied)

1 个答案:

答案 0 :(得分:0)

我通过在sudo用户中添加此命令来解决问题

我做的是

1-visudo
  

2 - 转到最后一行并添加此

 www-data  ALL = NOPASSWD: /etc/init.d/nginx reload

问题已修复