dqhdz04240 2016-02-11 12:20 采纳率: 0%
浏览 109

如何重启或重新加载nginx使用PHP

i change nginx conf file with php next i want restart nginx. but can not restart nginx

<?php
    if(exec("service nginx restart")) {
        echo "ok shd";
    } else {
        echo "error";
    }
?>
<hr>
<?php
    if(exec("/etc/init.d/nginx reload")) {
        echo "ok shd";
    } else {
        echo "error";
    }
?>
<hr>
<?php
    if(exec("/usr/sbin/nginx -s reload")) {
        echo "ok shd";
    } else {
        echo "error";
    }
?>

output is :

error<hr>
error<hr>
error

To do exec("service nginx restart") I need acces to php-fpm as root, so i go to /usr/local/etc/php-fpm.conf

user = nobody
group = nobody

and change it to:

user = root
group = root

and next enter service php-fpm restart

output:

Starting php-fpm [11-Feb-2016 05:14:33] ERROR: [pool www] please specify user and group other than root
[11-Feb-2016 05:14:33] ERROR: FPM initialization failed
 failed

and this means it can't be run as root.

So how can I restart or reload nginx using php?

  • 写回答

2条回答 默认 最新

  • duanen19871021 2016-02-11 13:36
    关注

    I need acces to php-fpm as root

    OMG NO

    Theres's a very good reason PHP-FPM won't run as root - because its a really, really bad thing to do.

    If you really must expose this functionality via a webserver then do it via sudo. Similarly any changes to your system config should be via sudo.

    BTW: one crucially important thing missing from your script is ignore_user_abort(). When (if) nginx is restarted by PHP the connection to the browser will be lost. By default, PHP will terminate at this point.

    评论

报告相同问题?

悬赏问题

  • ¥15 matlab中使用gurobi时报错
  • ¥15 WPF 大屏看板表格背景图片设置
  • ¥15 这个主板怎么能扩出一两个sata口
  • ¥15 不是,这到底错哪儿了😭
  • ¥15 2020长安杯与连接网探
  • ¥15 关于#matlab#的问题:在模糊控制器中选出线路信息,在simulink中根据线路信息生成速度时间目标曲线(初速度为20m/s,15秒后减为0的速度时间图像)我想问线路信息是什么
  • ¥15 banner广告展示设置多少时间不怎么会消耗用户价值
  • ¥16 mybatis的代理对象无法通过@Autowired装填
  • ¥15 可见光定位matlab仿真
  • ¥15 arduino 四自由度机械臂