automate subdomain creation + Apache

How to setup a LAMP server with mod_vhost_alias capability.

This document tell you how to setup a webserver so that all you need to do is upload to a ftp folder and tada you have a new subdomain. Read on!

Install MySQL

1. prefereably install using yum or up2date. If they fail then follow
directions on

Build Apache

1. wget
2. tar -zxf httpd-2.2.3.tar.gz
3. cd httpd-2.2.3
4. configure the build using following options


5. make | grep -i error
6. make install
7. /usr/local/apache/bin/apachectl configtest
8. /usr/local/apache/bin/apachectl start

Integrate PHP

1. wget
2. tar -zxf php-5.1.6.tar.gz
3. cd php-5.1.6
4. Configure the build using following command

./configure --prefix=/apache

5. make | grep -i error
6. make install

7. Edit /usr/local/apache/conf/httpd.conf and add following lines at relevant sections
LoadModule php5_module        modules/
AddHandler php5-script php

# Add index.php to your DirectoryIndex line:
DirectoryIndex index.php index.html

AddType text/html       php

# PHP Syntax Coloring
AddType application/x-httpd-php-source phps

8. /usr/local/apache/bin/apachectl configtest
9. /usr/local/apache/bin/apachectl start

Configure mod_vhost_alias

1. Add a user for the vhosts which will be used for running the server and uploading content.
useradd vhost
passwd vhost

2. If it exists, uncomment the Load module line for the vhost_alias module
LoadModule vhost_alias_module libexec/httpd/

3. If it exists, uncomment the AddModule one too:
AddModule mod_vhost_alias.c

4. add the User and Group directives (add these outside of
User vhost
Group vhost

5. Look for the following section:
< Directory />
Options FollowSymLinks
AllowOverride All
Order deny,allow
Deny from all
< /Directory >
change it to look as under:
< Directory />
Options FollowSymLinks
AllowOverride All
Order deny,allow
Allow from all
< /Directory >

6. Now add this snippet at the end of the file:
VirtualDocumentRoot /home/vhost/%2+/%1
VirtualScriptAlias /home/vhost/%2+/%1/cgi-bin

7. Add content to the /home/vhost directory
i... ftp to the server using username and password created in step 1
ii... create a folder with the domain name as name eg. /home/vhost/
iii... upload a site for example in the folder www under the
folder for domain will mean you upload content to /home/vhost/

8. /usr/local/apache/bin/apachectl configtest
9. /usr/local/apache/bin/apachectl start

If you don't see any errors, everything should be working.

At this point, you should be able to add folders like /home/vhost/
and access those as

Leave a Reply

Your email address will not be published. Required fields are marked *