Setting up Clean Urls for Drupal 7 on Ubuntu 14.04 on Digital Ocean

So you have installed LAMP successfully on your ubuntu server and imported your drupal 7 site files and database, linked both via settings.php but apart from the front page your site is not working?

Here is the solution

If you developed your site and had clean urls working fine on the development environment, but now find it doesn’t bootstrap any page past the front page, the issue is caused by the new site failing the clean urls test.

The solution is to fix rewriting on your server.

You need and probably have. Ssh access to your server.
The first step is to enable a rewriting modification to your PHP/Apache environment.

  1. At the prompt type

    sudo a2enmod rewrite

  2. The next bit depends upon where you are in the development process. If you have not linked your server to your domain yet then you may have a url of where is the IP address of your server and mysite is a folder with your site in. (you might have the site in /var/www/html in which case there is no folder.

    So you need to edit your 000-default.conf file
    This is found at /etc/apache2/sites-available/000-default.conf

    You can edit this using vim or nano or upload it to your editing software. In the case of the former two options type either:
    sudo nano /etc/apache2/sites-available/000-default.conf

    You will see a file like this:

    <VirtualHost *:80 >
    # The ServerName directive sets the request scheme, hostname and port that
    # the server uses to identify itself. This is used when creating
    # redirection URLs. In the context of virtual hosts, the ServerName
    # specifies what hostname must appear in the request's Host: header to
    # match this virtual host. For the default virtual host (this file) this
    # value is not decisive as it is used as a last resort host regardless.
    # However, you must set it for any further virtual host explicitly.

    ServerAdmin webmaster@localhost
    DocumentRoot /var/www/html

    # Available loglevels: trace8, ..., trace1, debug, info, notice, warn,
    # error, crit, alert, emerg.
    # It is also possible to configure the loglevel for particular
    # modules, e.g.
    #LogLevel info ssl:warn

    ErrorLog ${APACHE_LOG_DIR}/error.log
    CustomLog ${APACHE_LOG_DIR}/access.log combined

    # For most configuration files from conf-available/, which are
    # enabled or disabled at a global level, it is possible to
    # include a line for only one particular virtual host. For example the
    # following line enables the CGI configuration for this host only
    # after it has been globally disabled with "a2disconf".
    #Include conf-available/serve-cgi-bin.conf
    </VirtualHost >

    # vim: syntax=apache ts=4 sw=4 sts=4 sr noet

    You need to edit this

    You have no server name, lets give it one while you are here. If you want to call it mywebserver add the line

    ServerName mywebserver before the line ServerAdmin

    Actually you can put your email in the ServerAdmin line as well.

    If your drupal site is not in the /var/www/html then change the DocumentRoot to where it is.

    Move to the line after
    #LogLevel info ssl:warn

    Add the lines

    <Directory /var/www/html >
    AllowOverride All

    (Note you can omit the /html if your website is in /var/www/mywebsite which is also valid)
    Save the file and exit your editor.

  3. Now type service apache2 reload
    This restarts the apache service with all the changes you have made.
  4. Check your drupal site and clean urls should now pass.


    If your site is meant to point at a domain (its a production or live site) you need to go one step further

    For a domain

    cp /etc/apache2/sites-available/000-default.conf /etc/apache2/sites-available/
    This creates a version of your default vhosts file.
    Then edit

    ServerName to
    ServerAlias to
    ServerAdmin to your email address
    DocumentRoot to where your website hosting is installed (usually /var/www/html but can be in a home directory e.g. /home/user/mywebsite

    Then save

    Then type


    Service apache2 reload

    Your site should be ready to work or go live