The Challenge Rambles and riff raff about all this and that

20Jun/075

Activating mod_rewrite on Apache @ Ubuntu

I can usually find my way through Server configuration files fairly easy, but upon installing a LAMP server on Ubuntu I noticed "mod_rewrite" wasn't working at all. The answer ended up being fairly simple, once you know where to look, but for others not to struggle as I did I'll post what and where to look.

Ubuntu's Apache is quite modularized; both in packages and in runtime senses. This has several advantages which I wont mention here, but forces you to edit several configuration files to make adjustments.

Here's the ABC to it:

  • Add a loader to mod_rewrite module:
    Execute (on the shell):
    sudo a2enmod rewrite
  • Edit the apache2.conf by adding a call:
    On ubuntu this file usually sits on: /etc/apache2/apache2.conf
    <IfModule mod_rewrite.c>
    RewriteEngine On
    </IfModule>

    Note: you can also add this on the .htaccess files.
  • Edit the virtual host file:
    To know what hosts are enabled take a look at:
    /etc/apache2/sites-enabled/
    There you'll see a simlink to some file(s) sitting at:
    /etc/apache2/sites-available/
    which you'll have to edit.
    You need to add the permissions for your directorie(s):
    <Directory />
    Options FollowSymLinks
    AllowOverride All
    </Directory>
    Note: you can set this values for the root directory (as in this example) or for just 1 or more folders / sub-folders.
  • Restart your Apache:
    sudo /etc/init.d/apache2 force-reload
    or
    sudo apache2ctl restart

That should do the trick!

  • mark

    Esteban,

    I think this post is a valid example of the prior discussion on resume blogging. You’ve just screamed, “I’m a very technical guy” who’s savvy on the lattest trends LAMP servers for hosting.

    Kudos.

  • http://blog.estebanglas.com Esteban Glas

    Thanks Mark, Actually I usually use the Internet as my bookstore, when I face a problem I can’t solve I google around in search of answers.

    This particular case was one of the handful where I could not find the appropriate answers. Thus I thought it would be nice to post the resolution just in case I could make any other poor soul’s life less miserable.

  • http://dioxys.com Justin Shreve

    Just wanted to let you know that engine is spelled wrong above and will cause an error in loading.

  • http://blog.estebanglas.com Esteban Glas

    Thanks for the catch Justin, fixed!!

  • Mark Pearson

    Just installed Ubuntu 7.04 server and this was just what the doctor ordered. Can’t understand why mod_rewrite isn’t there by default. Thanks for these easy to follow instructions.