Setting up virtual host with mod rewrite enabled in Ubuntu Hardy Heron

24 thoughts on “Setting up virtual host with mod rewrite enabled in Ubuntu Hardy Heron”

  1. Instead of duplication

    sudo cp /etc/apache2/sites-available/ilove.php /etc/apache2/sites-enabled/ilove.php

    it’s much better to create symbolic link

    cd /etc/apache2/sites-enabled
    sudo ln -s /etc/apache2/sites-available/ilove.php ilove.php

  2. Hi! I don’t see how this has to do with mod_rewrite. As far as I understand, this is the normal way to do multiple localhosts on a debian system, regardless of mod_rewrite.

    Also, krig, here is a shortcut to the ln -s stuff:

    sudo a2ensite ilove.php



  3. I was just about to mention it when I saw Jay already mentioned it. In step 3, instead of manually creating the symbolic link, we can use

    sudo a2ensite ilove.php

    And we can easily disable the site using

    sudo a2dissite ilove.php

    Though its a debian/ubuntu specific command, but reduces the hassle of creating and removing symbolic links. And, this article is about ubuntu anyway 😉

  4. Hi,
    Thanks a lot for the post. I had a similar article myself on virtual hosts and have been following that procedure on Feisty and Gutsy. But somethings seems not to be working in Hardy. I have created a file called drupal6 and it looks like this

    ServerName drupal6

    DocumentRoot /home/madhu/mywebdevelopment/drupal6.0/

    Options FollowSymLinks
    AllowOverride All

    Options Indexes FollowSymLinks MultiViews
    AllowOverride All
    Order allow,deny
    allow from all

    ScriptAlias /cgi-bin/ /usr/lib/cgi-bin/

    AllowOverride None
    Options +ExecCGI -MultiViews +SymLinksIfOwnerMatch
    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

    Alias /doc/ “/usr/share/doc/”

    Options Indexes MultiViews FollowSymLinks
    AllowOverride None
    Order deny,allow
    Deny from all
    Allow from ::1/128

    and as you said have enabled the site and have added drupal6
    to the host. But when I give drupal6 in browser it gives the following error

    403 Forbidden

    You don’t have permission to access / on this server.

    My apache error.log has the following entries

    Mon Jun 02 09:18:50 2008] [crit] [client] (13)Permission denied: /home/madhu/mywebdevelopment/.htaccess pcfg_openfile: unable to check htaccess file, ensure it is readable

    Note that even though my DocRoot points to one directory below i. /home/…/mywebdevelopment/drupal6.0 it is looking for .htaccess in mywebdevelopment. So just to test I put my .htaccess copy there also. Still it shows the same error. Permission on all the files and directories is set to 777.

    Please help me. Thanks a lot

  5. Hi, thanks for this howto, i am getting the next error when i try to reload apache2

    NameVirtualHost *:80 has no VirtualHosts

    can somedody help me please?

  6. nice tut.

    Alfred! i got same error. but i solved it as:

    if you use NameVirtualhost *:80 then use


    NAMEVIRTUALHOST * then use

    i don’t know why it happens. but when i did it the error has gone. 🙂

  7. Hi,
    I’ve never had to do this, and am still a bit confused.
    Here is my setup.

    Ubuntu 8.04 running on a remote server
    Tomcat 5.5

    My webserver is running at successfully. I have a separate application that I installed can only get to by typing in the url:

    I want users to type in

    I know this should be ‘easy’ but I’ve google for hours and not found ‘the step-by-step’ files to edit and text to enter to do this. Can anyone help? Thanks in Advance!

  8. I love this tutorial. It used to work great but I just installed ubuntu 9.1 and it ceased to work as well.
    Apache has changed a few things like the httpd.conf file is now empty. Apache is making things more modular. Anyway enabling mod_rewrite is a little different now. Its a sym link. But the MAIN THING is that I could not get the name-based virtual host to work until I set this line:


    So after hours of work. That is what it took.

  9. I have another site in sites-available “mysite”. (Like you just tutored)
    Then I a2dissite default reloaded apache, a2ensite mysite, & then reloaded apache2.
    I get success messages at each step.
    But when i open localhost, index.html of default opens.

    Any help is greatly appreciated…


Leave a Reply

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