Link to home
Start Free TrialLog in
Avatar of Amber Bruelemans
Amber BruelemansFlag for Belgium

asked on

How to make this apache virtualhost working in Ubuntu?

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 "127.0.0.1  a" > /etc/hosts
    $ echo "127.0.0.1  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
     </Directory>
    </VirtualHost>
   
    $ 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
     </Directory>
    </VirtualHost>

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`?
Avatar of Dave Baldwin
Dave Baldwin
Flag of United States of America image

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.
ASKER CERTIFIED SOLUTION
Avatar of Dave Baldwin
Dave Baldwin
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
>     $ echo "127.0.0.1  a" > /etc/hosts
>     $ echo "127.0.0.1  b" > /etc/hosts

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

maybe you need to rethink about generating your /etc/hosts ;-)
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.