How to make this apache virtualhost working in Ubuntu?

Posted on 2012-09-13
Medium Priority
Last Modified: 2012-09-14
According to the docs https://help.ubuntu.com/10.04/serverguide/httpd.html i have done following, and that is almost how i do always in my Fedora, but Ubuntu looks like its not working.

a) DNS to IP

    $ echo "  a" > /etc/hosts
    $ echo "  b" > /etc/hosts

b) Apache virtualhost

    $ ls
    1  2  default  default.backup  default-ssl
    $ cat 1
    <VirtualHost *:80>
     ServerName a
     ServerAlias a
     DocumentRoot /var/www/html/a/public
     <Directory /var/www/html/a/public>
        #AddDefaultCharset utf-8
        DirectoryIndex index.php
        AllowOverride All
        Order allow,deny
        Allow from all
    $ cat 2
    <VirtualHost *:80>
     ServerName b
     ServerAlias b
     DocumentRoot /var/www/html/b/public
     <Directory /var/www/html/b/public>
        #AddDefaultCharset utf-8
        DirectoryIndex index.php
        AllowOverride All
        Order allow,deny
        Allow from all

c) load into Apache and restart the service
    $ a2ensite 1
    $ a2ensite 2
    $ a2dissite default
    $ /etc/init.d/apache2 restart
d) Browse the new 2 hosts

    $ firefox http://a

Does not work it goes always with `http://a` or `http://b` to `/var/www/html`

How do i fix it so that it goes to its own directory e.g: `http://a` goes to `/var/www/html/a/public` not `/var/www/html`?
Question by:Amber Bruelemans
  • 3
LVL 84

Expert Comment

by:Dave Baldwin
ID: 38397242
Interesting question.  I tried it a slightly different way using the GUI on Ubuntu 8.04 but it did the same thing.  I think it should work but I haven't figured out how.
LVL 84

Accepted Solution

Dave Baldwin earned 1000 total points
ID: 38397630
After a Lot of trial and error I got 'aaa' and 'bbb' sites working in subdirectories under '/var/www'.  I had to give them both their own IP addresses on my network, add them to the hosts file, and the last step was adding them to the 'interfaces' file.  I was not able to get them to work as additional sites under ''.

This is something I have done with several '/home' directories but it took forever to realize that I had to add the new interfaces to the 'auto' list in '/etc/network/interfaces' in addition to listing them as 'eth0-6'.  This is what my virtual directory file 'aaa' in 'sites-available' looks like.

	ServerAdmin webmaster@localhost
	ServerName aaa
	DocumentRoot /var/www/aaa/
	<Directory /var/www/aaa/>
		Options Indexes FollowSymLinks MultiViews
		AllowOverride None
		Order allow,deny
		allow from all

	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


Open in new window

LVL 51

Expert Comment

ID: 38397833
>     $ echo "  a" > /etc/hosts
>     $ echo "  b" > /etc/hosts

ends up with a /etc/hosts containing (only):  b

maybe you need to rethink about generating your /etc/hosts ;-)
LVL 84

Expert Comment

by:Dave Baldwin
ID: 38397900
Thanks for the points.  Note that when you do it that way, you can add it to the hosts file on any computer in your network and access it by name.

Featured Post

Free Tool: Site Down Detector

Helpful to verify reports of your own downtime, or to double check a downed website you are trying to access.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Over the last year I have answered a couple of basic URL rewriting questions several times so I thought I might as well have a stab at: explaining the basics, providing a few useful links and consolidating some of the most common queries into a sing…
The title says it all. Writing any type of PHP Application or API code that provides high throughput, while under a heavy load, seems to be an arcane art form (Black Magic). This article aims to provide some general guidelines for producing this typ…
Are you ready to place your question in front of subject-matter experts for more timely responses? With the release of Priority Question, Premium Members, Team Accounts and Qualified Experts can now identify the emergent level of their issue, signal…
Whether it be Exchange Server Crash Issues, Dirty Shutdown Errors or Failed to mount error, Stellar Phoenix Mailbox Exchange Recovery has always got your back. With the help of its easy to understand user interface and 3 simple steps recovery proced…
Suggested Courses
Course of the Month13 days, 12 hours left to enroll

755 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question