你如何重新启动Apache用(网络)按一下按钮?
我和我的VM玩弄和code我开发要求我重启apache每一个捕捉变化的时间。我认为这将是很好,只是有一个书签,或链接或按钮点击我可以运行做到这一点。关于如何使用PHP实现这一目标的一个CentOS 5 dev的任何想法VM?
I'm playing around with my VM and the code I'm developing requires that I restart apache every time to capture the changes. I thought it would be nice to just have a bookmarklet, or link or button click I could run to do this. Any thoughts on how to accomplish this with PHP on a CentOS 5 dev VM?
正如马克乙说,你需要root权限才能重新启动Apache。处理这种情况的最好办法,恕我直言,是给了Apache下运行的访问通过在来重新启动Apache用户须藤
命令。
As Marc B said, you need root privs to be able to restart Apache. The best way to handle this, IMHO, is to give the user that Apache runs under access to restart Apache via the sudo
command.
您将要修改的/ etc / sudoers文件
文件,并添加类似于以下行:
You'll want to edit your /etc/sudoers
file and add lines similar to the following:
Cmnd_Alias RESTART_APACHE = /sbin/service apache2 restart
www-data ALL=NOPASSWD: RESTART_APACHE
您可能需要人
而不是 www数据
,这取决于它在Apache下运行用户。在Debian,阿帕奇通常在用户运行 www数据
,而红帽,往往Apache下用户运行人
。此外, / sbin目录/服务的Apache2重启
可能需要 / sbin目录/服务的Apache重新启动
或者 / sbin目录/的httpd服务重新启动
。一切都取决于你的系统配置。
You may need nobody
instead of www-data
, it depends on the user which Apache runs under. On Debian, Apache typically runs under user www-data
, whereas under Red Hat, often Apache runs under user nobody
. Also, the /sbin/service apache2 restart
may need to be /sbin/service apache restart
or maybe /sbin/service httpd restart
. All depends on your system's configuration.
一旦这样做了,在PHP中可以使用code:
Once that's done, in PHP you can use the code:
exec('/sbin/service apache2 restart');
(显然改变,如果命令来重新启动Apache服务器上的不同。)
(Obviously changing that if the command to restart Apache differs on your server.)
请注意: 这很可能被认为是一个安全隐患的如果你这样做,你完全信任须藤
二进制文件,在服务
二,你的系统,以遵守规则,而不是让一个Apache / PHP程序得到一个root shell。我强烈建议在询问 http://serverfault.com 了解你在做什么在这里的含义。
Please note: this could very well be considered a security risk! If you do this, you fully trust the sudo
binary, the service
binary, and your system to obey the rules and not let an Apache/PHP process get a root shell. I highly recommend asking on http://serverfault.com for the implications of what you're doing here.