Enabling and Disabling the Apache Rewrite Module (mod_rewrite) in Linux (Ubuntu)

Enabling the Rewrite Module

Run the command followed by the module name:

sudo a2enmod rewrite

Restart Apache for the changes to take effect:

sudo service apache2 restart

Disabling the Rewrite Module

Run the command followed by the module name:

sudo a2dismod rewrite

Restart Apache for the changes to take effect:

sudo service apache2 restart

That’s it!

Enabling Clean URLs for CodeIgniter

CodeIgniter by default will have to first load the index.php page which would then further load the rest of the pages. This can be removed from the URL simply by following these steps:

  1. Create a new file in the CodeIgniter root folder named .htaccess with the following contents.
    <IfModule mod_rewrite.c="">
        RewriteEngine On
        RewriteBase /
        #Removes access to the system folder by users.
        #Additionally this will allow you to create a System.php controller,
        #previously this would not have been possible.
        #'system' can be replaced if you have renamed your system folder.
        RewriteCond %{REQUEST_URI} ^system.*
        RewriteRule ^(.*)$ /index.php?/$1 [L]
    
        #When your application folder isn't in the system folder
        #This snippet prevents user access to the application folder
        #Submitted by: Fabdrol
        #Rename 'application' to your applications folder name.
        RewriteCond %{REQUEST_URI} ^application.*
        RewriteRule ^(.*)$ /index.php?/$1 [L]
    
        #Checks to see if the user is attempting to access a valid file,
        #such as an image or css document, if this isn't true it sends the
        #request to index.php
        RewriteCond %{REQUEST_FILENAME} !-f
        RewriteCond %{REQUEST_FILENAME} !-d
        RewriteRule ^(.*)$ index.php?/$1 [L]
    </IfModule>
    
    <IfModule !mod_rewrite.c="">
        # If we don't have mod_rewrite installed, all 404's
        # can be sent to index.php, and everything works as normal.
        # Submitted by: ElliotHaughin
    
        ErrorDocument 404 /index.php
    </IfModule>
    

    If CodeIgniter is not the webroot and is a subfolder then alter the line RewriteBase / to RewriteBase /[Sub Folder Name]/ where [Sub Folder Name] should be replaced by the actual name of the folder.

    Note: In case the above file doesn’t work, remove the <IfModule> opening and closing tags to test if for some reason Apache wasn’t able to load the module.

    Save the file.

  2. Open the file inside the CodeIgniter folder in the path application/config/config.php and alter the following line
    $config['index_page'] = 'index.php';

    Remove the ‘index.php’ to (empty string) and save.

  3. Enable the mod_rewrite module of Apache using the following command on Ubuntu:
    sudo a2enmod rewrite

    The Apache needs to be restarted before changes can take affect.

  4. Make sure the required settings are made in the sites file. In Ubuntu this file can be found at /etc/apache/sites-available/default and make the following changes:
    <Directory>
           ...
           Options FollowSymLinks
           AllowOverride FileInfo
           ...
    </Directory>
  5. Restart Apache using the following command:
    sudo service apache2 restart

Now test the website by using the URL without the index.php word and it should work fine.

Install Apache, PHP and MySQL on Ubuntu

Installing these packages on Ubuntu is very simple. Just execute the following commands and you will be done with everything.

Install Apache

sudo apt-get install apache2

Install PHP

sudo apt-get install php5 libapache2-mod-php5

Install MySQL (with Apache & PHP support)

sudo apt-get install mysql-server libapache2-mod-auth-mysql php5-mysql

Restart Apache

sudo /etc/init.d/apache2 restart

Install MySQL Query Browser

sudo apt-get install mysql-query-browser

Update for MySQL

MySQL has officially declared EOL (End of Life) for Query Browser. You can check it onhttp://dev.mysql.com/doc/query-browser/en/

MySQL Workbench is its replacement and its now available in Ubuntu 12.04 repositories:

sudo apt-get install mysql-workbench

All features are supported by Workbench.