PHP可以重新启动Apache? [英] Can PHP restart Apache?

查看:152
本文介绍了PHP可以重新启动Apache?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有哪些需要做一个虚拟主机修改Apache的配置文件,然​​后重新启动Apache使新的配置生效的本地服务器。

I have a local server which needs to make changes to a virtual hosts apache config file and then restart apache so the new config takes effect.

可以在PHP这样做呢?我试图中继和exec,但他们没有工作。也许问题在于我试图重新启动PHP的父进程?

Can PHP do this? I tried passthru and exec but they didn't work. Maybe the problem is that I'm trying to restart PHP's parent process?

感谢您的帮助!

推荐答案

我用cron脚本(用PHP编写的,而不是从网络服务器执行)来检查服务器启动并重新启动服务器。

I've used a cron script (written in PHP, not executed from the webserver) to check a server is up and restart the server.

不过,我不会从一个服务器创建的过程中做到这一点,因为你知道你要杀死父进程,这对孩子不好的影响。

However, I wouldn't do this from a server-created process, because you know you're about to kill the parent process, which has bad implications for the child.

最简单的方法是将有一个文件/ tmp / RESTART_APACHE这PHP可以创建和其中的cron脚本检查。如果cron的脚本看到文件/ tmp / RESTART_APACHE那么它的Apache正确重新启动。

The simplest method would be to have a file /tmp/RESTART_APACHE which PHP can create, and which the cron script checks for. If the cron script sees the file /tmp/RESTART_APACHE then it does a proper restart of Apache.

使用cron脚本将引入的延迟(最多60年代,如果你运行它每分钟),但除此之外,应该工作,只要你想。

Using a cron script will introduce a delay (up to 60s if you run it each minute), but apart from that should work as you want.

根据您打算如何使用这个,这可能做的伎俩。

Depending on how you intend using this, that may do the trick.

(您可能需要使用不同的目录的/ tmp /设置服务器能够创建该文件的权限和prevent任何人。)

(You probably want to use a different directory than /tmp/ to set permissions and prevent anyone on the server being able to create the file.)

编辑:请参阅亚伦H公司的这一职务评论。我同意他说的话:你真的要小心,要重新启动你的web服务器的能力不是一般向公众提供的服务。

Please see Aaron H's comment to this post. I agree with what he says: you really do want to be careful that the ability to restart your webserver is not a service generally available to the public.

限制访问可以触发重启系统;确保触发重新启动该文件有严格的权限,只允许网络程序可以创建文件,一般是聪明的。

Restrict access to the system which can trigger the restart; ensure that the file which triggers the restart has restrictive permissions so only the web process can create that file, and generally be smart.

这篇关于PHP可以重新启动Apache?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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