我正在使用 symfony 3 进行项目,
项目运行在nginx服务器上
我正在尝试使用以下命令重新加载配置文件:
从控制器“systemctl reload nginx”。
/**
* @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,
]);
}
响应:
{“result”:1,“output”:[“无法重新加载nginx.service:需要交互式身份验证。”,“有关详细信息,请参阅系统日志和systemctl status nginx.service。”]}
最可能nginx
不与用户一起运行root
这是你需要使用的systemctl
。因此你应该使用执行你的命令sudo
.
现在有不同的方法可以从网络服务器运行命令root
特权:
- Run
nginx
与用户root
这是非常沮丧出于明显的安全原因
- 仅将此特定命令添加到
sudoers
as 此处描述 https://askubuntu.com/questions/159007/how-do-i-run-specific-sudo-commands-without-a-password为了运行它root
没有任何密码提示的权限
- 通过你的
root
密码通过echo
as 此处描述 https://stackoverflow.com/questions/43095751/run-php-shell-exec-like-root-user
- 编写一个功能有限的 bash 脚本,如下所示此处描述 https://stackoverflow.com/questions/1598231/how-to-run-php-exec-as-root
但当然,您可能会发现其他东西正在寻找它。
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)