Finally got Apache 2.2.3 set up with virtual hosts

What a night. I have spent most of the last few days faffing around trying to set up virtual hosts on my Ubuntu Apache server. I had almost given up. I tried using Webmin, but failed. I read many tutorials, which led me to installing Virtualmin at one point, which was useless. Some tutorials suggested that I need change settings in DNS / Bind, but that was a red herring. In the end, the only changes that I had to make were in /etc/apache2/sites-available/default – i.e. ignoring the httpd.conf file, and not using the include method in the apache2.conf file either (which Webmin seems to prefer to set up).

Here is the successful code:

NameVirtualHost *

<virtualhost 80=””>
ServerName www.domain.co.uk
ServerAdmin [email protected]

DocumentRoot /var/www/domain
<directory>
Options FollowSymLinks
AllowOverride None
</directory>
<directory var=”” www=”” uk=””>
Options Indexes FollowSymLinks MultiViews
AllowOverride All
Order allow,deny
allow from all
# This directive allows us to have apache2’s default start page
# in /apache2-default/, but still have / go to the right place
#RedirectMatch ^/$ /apache2-default/
</directory>

ScriptAlias /cgi-bin/ /usr/lib/cgi-bin/
<directory usr=”” lib=”” bin=””>
AllowOverride None
Options ExecCGI -MultiViews +SymLinksIfOwnerMatch
Order allow,deny
Allow from all
</directory>

ErrorLog /var/log/apache2/error.log

# Possible values include: debug, info, notice, warn, error, crit,
# alert, emerg.
LogLevel warn

CustomLog /var/log/apache2/access.log combined
ServerSignature On

Alias /doc/ “/usr/share/doc/”
<directory usr=”” share=”” doc=””>
Options Indexes MultiViews FollowSymLinks
AllowOverride None
Order deny,allow
Deny from all
Allow from 127.0.0.0/255.0.0.0 ::1/128
</directory>

</virtualhost>

<virtualhost 80=””>
ServerName www.domain.com
ServerAdmin emailadddress

DocumentRoot /var/www/domain.com
<directory>
Options FollowSymLinks
AllowOverride None
</directory>
<directory var=”” www=”” com=””>
Options Indexes FollowSymLinks MultiViews
AllowOverride All
Order allow,deny
allow from all
# This directive allows us to have apache2’s default start page
# in /apache2-default/, but still have / go to the right place
#RedirectMatch ^/$ /apache2-default/
</directory>

ScriptAlias /cgi-bin/ /usr/lib/cgi-bin/
<directory usr=”” lib=”” bin=””>
AllowOverride None
Options ExecCGI -MultiViews +SymLinksIfOwnerMatch
Order allow,deny
Allow from all
</directory>

ErrorLog /var/log/apache2/error.log

# Possible values include: debug, info, notice, warn, error, crit,
# alert, emerg.
LogLevel warn

CustomLog /var/log/apache2/access.log combined
ServerSignature On

Alias /doc/ “/usr/share/doc/”
<directory usr=”” share=”” doc=””>
Options Indexes MultiViews FollowSymLinks
AllowOverride None
Order deny,allow
Deny from all
Allow from 127.0.0.0/255.0.0.0 ::1/128
</directory>

</virtualhost>

So everything is working, both Morrowtech and Bums Tums and Thighs are working (update: neight site is hosted at home now), finally. Time for bed! And there was me hoping for an early night tonight.

The good news is of course that finally I can host any number of sites for my friends and family, which will start to give me more experience, and maybe one day I will be a fully fledged web hosting solutions provider!

I should add that in my frustration with configuring Apache this evening I attempted to reinstall it, as I managed to delete my sites-available/default file. I failed to do this, and ended up reinstalling Ubuntu. SO I now have a clean install AND a working virtual hosting platform. About time!

  2 comments for “Finally got Apache 2.2.3 set up with virtual hosts

  1. February 17, 2011 at 1:39 am

    Years later, but I stumbled across this page trying to get a virtual server setup using WebMin on CentOS 5.3. A couple thoughts for anyone else that gets here:

    1. The file layouts are not consistent across Linux systems. CentOS 5.3 Apache “httpd” from standard distros does not make “apache2” directories (perhaps if does if you “make” it yourself, but not if you “yum install httpd”). See http://wiki.apache.org/httpd/DistrosDefaultLayout for info about various system setups.

    2. Keep SELinux in mind (Security Enabled Linux). If that is on and you are just thinking “chmod file protections”, think again. Consider “sestatus”, “system-config-securitylevel-tui” and the like. If things are not working, you might turn that off using th tui (text user interface) for a moment to see if that is your pain… and if so, good luck.

  2. Webologist
    February 17, 2011 at 2:08 pm

    Hey, yeah it has been a few years hasn’t it? Other thoughts – security! I stopped running my home server not long after I set it up. One day I noticed that my Internet connection was very slow so I looked at the server and saw that it was being accessed from Mexico. Someone had managed to hack their way in. no idea what they were doing but it looked like they had set up a mini OS in there. Probably sending spam mails or something! Shut the server down and that was the end of the experiment. Pro hosting from then on!

Leave a Reply

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