chromedude
chromedude

Reputation: 4302

How do you execute Vhosts via 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?

Upvotes: 0

Views: 142

Answers (1)

ghbarratt
ghbarratt

Reputation: 11711

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.

Include conf/vhosts/*.conf

(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:

$ /usr/sbin/apachectl -t
Syntax OK

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 the file_get_contents and file_put_contents functions easier to work with.

Hope this helps.

Upvotes: 1

Related Questions