How to make this apache virtualhost working in Ubuntu?

Posted on 2012-09-13
Last Modified: 2012-09-14
According to the docs 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
    LVL 82

    Expert Comment

    by:Dave Baldwin
    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 82

    Accepted Solution

    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

    >     $ 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 82

    Expert Comment

    by:Dave Baldwin
    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.

    Write Comment

    Please enter a first name

    Please enter a last name

    We will never share this with anyone.

    Featured Post

    Maximize Your Threat Intelligence Reporting

    Reporting is one of the most important and least talked about aspects of a world-class threat intelligence program. Here’s how to do it right.

    Suggested Solutions

    In my time as an SEO for the last 2 years and in the questions I have assisted with on here I have always seen the need to redirect from non-www urls to their www versions. For instance redirecting ( to http…
    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…
    Hi everyone! This is Experts Exchange customer support.  This quick video will show you how to change your primary email address.  If you have any questions, then please Write a Comment below!
    how to add IIS SMTP to handle application/Scanner relays into office 365.

    737 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

    Need Help in Real-Time?

    Connect with top rated Experts

    16 Experts available now in Live!

    Get 1:1 Help Now