如何通过 PHP 执行 Vhost?
我正在创建一个网站,每个用户都可以在我的服务器上指向他们域的 A 记录,我将为他们提供他们的网页。我知道如何通过 Linux 命令行执行此操作,但我不确定如何在脚本中执行此操作。我知道 mkdir(/*file location*/)
执行 mkdir
命令。我也知道fopen
。我的方法是 http://www.rackspace.com/knowledge_center/index.php/ Ubuntu_-_Apache_Virtual_Hosts 。我不太确定如何通过 PHP 脚本创建自定义虚拟主机等。
有什么想法如何做到这一点?
I am creating a website where each of the users can point an A record of their domain at my server and I will serve up their web page for them. I know how to do it by Linux command-line, but I am not sure how to do it in a script. I know that mkdir(/*file location*/)
executes the mkdir
command. I also know fopen
. My method is http://www.rackspace.com/knowledge_center/index.php/Ubuntu_-_Apache_Virtual_Hosts . I am not exactly positive how to create the custom vhosts etc. by a PHP script.
Any ideas how to do this?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
听起来好像您希望使用 php 脚本更改 Apache 配置文件。这样做有点危险,因为您总是冒着错误配置 Apache 配置文件的风险,从而阻止 Apache 重新启动,但我认为这对您来说是显而易见的。
我建议您使用 include 指令 到您所在的目录将添加和删除每个虚拟主机的单独conf文件。
(include 指令中的路径是相对于 ServerRoot 的。)这样您就可以使事情更有组织性并减少竞争条件的可能性。
另外,您可能应该在脚本中编写一些代码来检查运行 apachectl configtest 的输出 命令:
通过各种 PHP shell/"Program" 之一执行它执行函数,如果有错误,恢复您刚刚更改的conf 文件。
如果您喜欢
fopen
,请使用它,但许多人找到file_get_contents
和file_put_contents
函数更易于使用。希望这有帮助。
It sounds as though you are hoping to alter the Apache configuration files using a php script. It is a bit dangerous to do this because you always risk misconfiguring your Apache config file(s) in a way that will prevent Apache from restarting, but I assume that is obvious to you.
I suggest that you use an include directive to a directory where you will be adding and removing individual conf files per vhost.
(Paths in the include directive are relative to the ServerRoot.) That way you can keep things a little more organized and reduce the possibility of a race condition.
Also you should probably write some code in your script that checks the output of running an apachectl configtest command:
executing it through one of the various PHP shell/"Program" execution functions and if there is an error, revert the conf file you just altered.
If you like
fopen
, then use it, but many find thefile_get_contents
andfile_put_contents
functions easier to work with.Hope this helps.