Take the 2-minute tour ×
Server Fault is a question and answer site for system and network administrators. It's 100% free, no registration required.

I'm not sure if what I'm asking is possible, but I'd like to pick the brains of smart sysadmins here. I have a domain mysite.com to which I add sub-domains. I then install a piece of software on each sub-domain.

Is there anyway I can automate this process so that I can connect directly from my localhost development environment and just run this script that say adds subdomain1.mysite.com and installw software1 on it, or adds subdomain2.mysite.com and installs this other software2 on it?

Since I'm a developer and use shared hosting, I'd prefer a solution that uses .htaccess if it exists. If not, what are my options.

share|improve this question

4 Answers 4

So Apache runs on your own machine?

You could use the module mod_vhost_alias. After enabling it, add

VirtualDocumentRoot /var/www/virtual/%0

to your main config/virtual host.

This means: Everything below /var/www/virtual is treated as a virtual host, no configuration needed, only create the directory (so it's easily scriptable).

Your folders must look like this for a configuration of "%0":

/var/www/virtual/mysite.com
/var/www/virtual/subdomain1.mysite.com

"Installing a piece of software" is a bit generic, please describe which steps are involved when doing it manually.

share|improve this answer

I can't provide a recommendation on the httpd side but as far as DNS goes... If you are looking for ways to create the DNS automatically you could consider wildcard DNS entries. If you define * as the host with an A record of 1.2.3.4 this will point everything not explicitly defined within the zone to 1.2.3.4, the same works for CNAME's and MX records.

Hope this helps partially resolve your query.

share|improve this answer

Not sure if you can add vhosts via .htaccess (or whether it is actually a good idea at all, come to think of it). However its simple to set up apache to scan a dir for config files - when I had a similar setup, I had a seperate .conf file for each vhost in /etc/httpd/vhosts (some apache installations now implement this out-of-the box). Bind was a bit more complex as each conf file must be explicitly referenced by the master file - but a simple sed script took care of that.

I also had a couple of template installations set up so I could automatically populate the site.

So yes - its just a matter of scripting what you already do manually. Not clear what the issue is.

share|improve this answer

Taken from an earlier question

http://stackoverflow.com/questions/183928/how-to-let-php-to-create-subdomain-automatically-for-each-user

You're looking to create a custom A record.

I'm pretty sure that you can use wildcards when specifying A records which would let you do something like this:

*.mywebsite.com IN A 127.0.0.1

127.0.0.1 would be the IP address of your webserver. The method of actually adding the record will depend on your host.

Doing it like http://mywebsite.com/user would be a lot easier to set up if it's an option.

Then you could just add a .htaccess file that looks like this:

Options +FollowSymLinks

RewriteEngine On RewriteRule ^([aA-zZ])$ dostuff.php?username=$1 In the above, usernames are limited to the characters a-z

The rewrite rule for grabbing the subdomain would look like this:

RewriteCond %{HTTP_HOST} ^(^.).mywebsite.com RewriteRule (.) dostuff.php?username=%1

this could solve the issue of creating the subdomain but the installation of software can be tackled quite a few different ways.

Is there a specific software you would like to auto install or is there a vast amount of different software?

share|improve this answer
    
this is also possible for use on your shared hosting. as long as the provider allows –  Trozz Oct 18 '10 at 12:42

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.