0

I'm trying to restart nginx from php

The problem is when I type the code from my command line everything work fine but from my php i got this as an output

* Restarting nginx nginx ...fail!

My php code is

 echo   shell_exec ("service nginx restart");

file permission 7777

nginx error log

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)
user1669496
  • 32,176
  • 9
  • 73
  • 65

1 Answers1

0

I solved the problem by adding this command inside sudo users

what i did is

1-visudo

2-go to the last line and add this

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

and the problem is fixed