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 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 domain.com
ServerAdmin [email protected]

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, 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!

Check out my first virtually hosted webs: Morrowtech and Bums Tums and Thighs.

Tags: , , , , ,