为什么PHP命令'EXEC(Q​​UOT;服务的Apache2重启");`在Ubuntu开不工作? [英] why php command `exec("service apache2 restart");` does't work on ubuntu?

查看:116
本文介绍了为什么PHP命令'EXEC(Q​​UOT;服务的Apache2重启");`在Ubuntu开不工作?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我需要使用PHP和Apache配置我的Web服务器上执行某些命令。

I need to execute some commands on my web server with php configured with apache.

exec("service apache2 restart", $output);
print_r($output);


输出:

Array (
    [0] =>  * Restarting web server apache2
    [1] => Action 'start' failed.
    [2] => The Apache error log may have more information.
    [3] =>    ...fail! 
)

我的猜测是,那是因为在我的Ubuntu的PHP的权限!
你有什么建议?

My guess is it's because of permissions of php on my ubuntu! What do you suggest?

推荐答案

您需要运行:

visudo

检查是否有这样一行

check that you have a line like

Host_Alias LOCAL=192.168.0.1 

与该文件的顶部您自己的本地IP,然后添加一个行

with your own local IP at the top of the file, then add a line

www-data       LOCAL=NOPASSWD:/usr/bin/service

和上次在你的PHP文件:

And last in your PHP file :

exec("/usr/bin/sudo /usr/bin/service apache2 restart");

(你正在试图通过网络,以重新启动Apache,也许你不知道 webmin的接口?我想有更佳的解决方案比这个须藤方式这不是授权www数据停止,启动(...)所有的服务是一件好事更好地解释为什么你想重新启动Apache;))

(You are trying to restart apache by web, maybe you don't know webmin interface ? I think there's betters solutions than this sudo way. It's not a good thing to authorize www-data to stop, start (...) all the services. Better explain why you'd like to restart apache ;) )

这篇关于为什么PHP命令'EXEC(Q​​UOT;服务的Apache2重启");`在Ubuntu开不工作?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆