Tagged: virtualhost

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

Slackware64: Name-Based Web Sites on a Single IP Address (vhosts)

Configuring VirtualHost with Slackware64 13.37 is also relatively easy. This is my local setup.

Uncomment below from /etc/httpd/httpd.conf. This enables virtual host. Include /etc/httpd/extra/httpd-vhosts.conf

Edit /etc/httpd/extra/httpd-vhosts.conf

Note on access control. From Apache version 2.4, Options, Allow, and other directives are replaced by the Require directive. Neglecting to make this change could result in 403 Forbidden You don't have permission to access / on this server. or AH01630: client denied by server configuration... in the error log.

For more detailed information, upgrading overview document is useful. NameVirtualHost *:80 <virtualhost *:80> <directory "/home/ubyt3m3/www/siteA"> Options Indexes FollowSymLinks AllowOverride None Order allow,deny Allow from all Require all granted [Edit: To comply with Apache 2.4] </directory> ServerName siteA DocumentRoot "/home/ubyt3m3/www/siteA" ErrorLog "/var/log/httpd/siteA.err" CustomLog "/var/log/httpd/siteA.log" common </virtualhost> <virtualhost *:80> <directory "/home/ubyt3m3/www/siteB"> Options Indexes FollowSymLinks AllowOverride None Order allow,deny Allow from all Require all granted [Edit: To comply with Apache 2.4] </directory> ServerName siteB DocumentRoot "/home/ubyt3m3/www/siteB" ErrorLog "/var/log/httpd/siteB.err" CustomLog "/var/log/httpd/siteB.log" common </virtualhost>

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

Restart the httpd process: /etc/rc.d/rc.httpd stop /etc/rc.d/rc.httpd start

That's all!
-gibb

Disclaimer:
Information in this page 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.