Debian Wheezy (7.5): Name-Based Web Sites on a Single IP Address (vhosts)

Configuring virtual hosting with Debian Wheezy has a little different steps from that with Slackware. To avoid from getting myself confused (and hopefully help someone else to set their virtual host sites), these are the steps I used for my local sites.

Disclaimer:
The information in this site is the result of my researches in the Internet and of my experiences. It is solely used for my purpose and may not be suitable for others. I will NOT take any responsibility of end result after following these steps (although I will try to help if you send me your questions/problems).

1) Disabling Default Virtual Host

First, let's disable the default Apache virtual host with a2dissite. What this command do is simply removing a symlink to /etc/apache2/sites-enabled/. # a2dissite default

2) Creating a New Directory and Setting Permissions

It's necessary to create a directory where site's website files and logs reside and grant ownership of the directory to the user instead of keeping it on the root system. For example, I'm setting up for siteA.org and siteB.org.

siteA.org
# mkdir -p /var/www/siteA.org/public_html # mkdir /var/www/siteA.org/logs # chown -R [$user]:[$group] /var/www/siteA.org/public_html
siteB.org
# mkdir -p /var/www/siteB/public_html # mkdir /var/www/siteB.org/logs # chown -R [$user]:[$group] /var/www/siteB.org/public_html

3) Creating Config files

Each virtual host needs own configuration file placed in /etc/apache2/sites-available/ directory. Each configuration file is as follow. Make sure that you have all directories specified in each conf file exist before you restart the apache process; otherwise, it'll fail to start.

siteA.org

# vim /etc/apache2/sites-available/siteA.org.conf ------------------------------------ <VirtualHost *:80> ServerAdmin webmaster@siteA.org ServerName siteA.org ServerAlias www.siteA.org DocumentRoot /var/www/siteA.org/public_html <Directory /> Options FollowSymLinks AllowOverride None </Directory> <Directory /var/www/siteA.org/public_html/> Options Indexes FollowSymLinks AllowOverride None Order allow,deny allow from all </Directory> ErrorLog /var/www/siteA.org/logs/error.log CustomLog /var/www/siteA.org/logs/access.log combined </VirtualHost>

siteB.org

# vim /etc/apache2/sites-available/siteB.org.conf ------------------------------------ <VirtualHost *:80> ServerAdmin webmaster@siteA.org ServerName siteB.org ServerAlias www.siteB.org DocumentRoot /var/www/siteB.org/public_html <Directory /> Options FollowSymLinks AllowOverride None </Directory> <Directory /var/www/siteB.org/public_html/> Options Indexes FollowSymLinks AllowOverride None Order allow,deny allow from all </Directory> ErrorLog /var/www/siteB.org/logs/error.log CustomLog /var/www/siteB.org/logs/access.log combined </VirtualHost>

4) Enabling the Sites

Now activate the host: # a2ensite siteA.org.conf # a2ensite siteB.org.conf

5) Restarting Apache

Restart the Apache server to initialize the changes: # service apache2 restart

6) Setting Up Local Host

Edit /etc/hosts so that the sites can be found by name: # vim /etc/hosts ------------------------------------ 127.0.0.1 localhost siteA siteB

That's all!
-gibb

Post a comment

You may use the following HTML:
<a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <s> <strike> <strong>