问题
I am working on project using symfony 3, the project run on nginx server and i am trying to reload the configuration files with the following command: "systemctl reload nginx" from the controller.
/**
* @Route("/testReloadConfig")
*/
public function testReloadConfigAction(Request $request){
$output = [];
$result = null;
$cmd = 'systemctl reload nginx 2>&1';
exec($cmd, $output, $result);
return new JsonResponse([
'result' => $result,
'output' => $output,
]);
}
The response:
{"result":1,"output":["Failed to reload nginx.service: Interactive authentication required.","See system logs and \u0027systemctl status nginx.service\u0027 for details."]}
回答1:
Most probably nginx
doesn't run with user root
which is what you need to use systemctl
. Therefore you should execute your command using sudo
.
Now there are different ways of running a command from web-server with root
privileges:
- Run
nginx
with userroot
which is highly discouraged for obvious security reasons - Add only this specific command to
sudoers
as described here in order to run it withroot
privileges without any password prompt - Pass your
root
password throughecho
as described here - Write a bash script with limited functions as described here
But of course you might find something else searching on for it.
来源:https://stackoverflow.com/questions/51500748/failed-to-reload-nginx-service-interactive-authentication-required