Php 未能重新加载nginx.service:需要交互式身份验证
我正在使用symfony 3进行项目工作, 该项目在nginx服务器上运行 我正在尝试使用以下命令重新加载配置文件: 从控制器中选择“systemctl reload nginx”Php 未能重新加载nginx.service:需要交互式身份验证,php,symfony,nginx,command-line,Php,Symfony,Nginx,Command Line,我正在使用symfony 3进行项目工作, 该项目在nginx服务器上运行 我正在尝试使用以下命令重新加载配置文件: 从控制器中选择“systemctl reload nginx” /** * @Route("/testReloadConfig") */ public function testReloadConfigAction(Request $request){ $output = []; $result = null; $cmd = 'systemctl re
/**
* @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,
]);
}
回答:{“结果”:1,“输出”:[“未能重新加载nginx.service:需要交互式身份验证。”,“有关详细信息,请参阅系统日志和\u0027systemctl状态nginx.service\u0027”。]}很可能
nginx
不与用户root
一起运行,这正是您需要使用的systemctl
。因此,您应该使用sudo
执行命令
现在,有不同的方法可以使用root
权限从web服务器运行命令:
- 使用用户
运行root
,由于明显的安全原因,这是非常不鼓励的nginx
- 仅将此特定命令添加到
as,以便在没有任何密码提示的情况下以sudoers
权限运行它root
- 通过
as传递您的echo
密码root
- 编写一个包含有限函数的bash脚本,如下所示