English 中文(简体)
为什么营地指挥“Exec(”service apache2start”?
原标题:why php command `exec("service apache2 restart");` does t work on ubuntu?

我需要在我的网络服务器上执行一些指挥系统,配备了一批藏匿点。

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! 
)

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 

然后,在案头上添加一条线。

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

最后,在您的PHP档案中:

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

(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 ;) )

问题回答

系统服务(如Patricia httpd)只能由根本用户操纵(启动、停用、重新启动)。

你们要么在根基(bad <<>>>>/em>思想)上操作PHP文字,要么使用sudo作为超级用户管理指挥。 尽管如此,在利用超级用户特权实施方案时,会带来非常严重的安全影响,特别是如果你不适当地使你的投入san!

你们是否看着阿帕奇的错误记录。 在那里什么?

几乎肯定的是,你的PHP书在未经充分许可的情况下运行,以便重新启动阿帕奇。 这可能是最好的。 如果你真的需要工作,则考虑从购买力平价中提取一个既定的基本文字(指出这不应用于生产,而且可能会造成安全漏洞)。

你还可以写一小件事,作为根基,接受指挥,从你的PHP文字中恢复阿帕奇。 尽管目前的任务本身似乎不适当,但这样做是一种更加“适当”的方法,因此我不敢确保你继续走这条道路。





相关问题
Signed executables under Linux

For security reasons, it is desirable to check the integrity of code before execution, avoiding tampered software by an attacker. So, my question is How to sign executable code and run only trusted ...

encoding of file shell script

How can I check the file encoding in a shell script? I need to know if a file is encoded in utf-8 or iso-8859-1. Thanks

How to write a Remote DataModule to run on a linux server?

i would like to know if there are any solution to do this. Does anyone? The big picture: I want to access data over the web, using my delphi thin clients. But i´would like to keep my server/service ...

How can I use exit codes to run shell scripts sequentially?

Since cruise control is full of bugs that have wasted my entire week, I have decided the existing shell scripts I have are simpler and thus better. Here is what I have so far svn update /var/www/...

Good, free, easy-to-use C graphics libraries? [closed]

I was wondering if there were any good free graphics libraries for C that are easy to use? It s for plotting 2d and 3d graphs and then saving to a file. It s on a Linux system and there s no gnuplot ...