Virtual Web Site Hosting
A common practice is to use one apache server to host websites for multiple domain names. Apache supports virtual servers out of the box making this easy to setup. This tutorial is based on Fedora Core 5, but should apply to most other linux distros.
To get started you need to have a folder to store the data for each virtual website. On my system I have a created a new user for each website following the pattern.
For example to add jsmith. Note that the /home/jsmith folder must have execute permissions and the public_html folder must have read permissions for apache.
useradd jsmith cd /home/jsmith mkdir public_html chown jsmith:jsmith public_html chmod 711 . chmod 755 public_html
Lets open up the apache config and add the required sections.
Scroll down to the end of the file and you will see the virtual hosting section. The first thing we must do is let apahce know what IPs and ports it will be serving for virtual hosts. The * wild card is supported. The line below states that apache will server requests for port 80 on all incoming IPs.
Now we set the individual settings for each virtual host. If you are a hosting provider you probably will want a catchall host to display if the user goes to the server’s IP or hostname. To do this we use the _default_ attribute.
<VirtualHost _default_:80> ServerAdmin email@example.com DocumentRoot /var/www/html ServerName www.domain.com </VirtualHost>
On the rest of your virtual hosts I recommend to fill in a ServerAlias. Lets say your site is http://www.jsmith.com/. Without a ServerAlias if a visitor points his/her browser to http://jsmith.com/ they will get the default host instead of http://www.jsmith.com/.
<VirtualHost *:80> ServerAdmin firstname.lastname@example.org DocumentRoot /home/jsmith/public_html ServerName www.jsmith.com ServerAlias jsmith.com *.jsmith.com </VirtualHost>
Make sure to verify the apache config first
If it comes back syntax OK you are ready to reload the config
service httpd reload
or start up the apache server if it is not already running.
service httpd start