Drupal Needs Mod_Rewrite in Apache2

This one was a real PITA!

When I got Drupal installed anything beyond the home page threw a ‘404’ error. The reason being is that Drupal needs clean URLs enabling and Debian / Apache2 default hasn’t got it enabled. Much reading and experimenting found this process to work:

  1. Add Options All after the

    <IfModule mod_rewrite.c>
    RewriteEngine on

    section

  2. Uncomment the line # RewriteBase /
  3. Insert the following before the last </IfModule tag>

    # Rewrite old-style URLS of the form 'node.php?id=x':
    RewriteCond %{REQUEST_FILENAME} !-f
    RewriteCond %{REQUEST_FILENAME} !-d
    RewriteCond %{QUERY_STRING} ^id=([^&]+)$
    RewriteRule node.php index.php?q=node/view/%1 [L]

    # Rewrite old-style URLs of the form 'module.php?mod=x':
    RewriteCond %{REQUEST_FILENAME} !-f
    RewriteCond %{REQUEST_FILENAME} !-d
    RewriteCond %{QUERY_STRING} ^mod=([^&]+)$
    RewriteRule module.php index.php?q=%1 [L]

    # Rewrite URLs of the form 'index.php?q=x':
    RewriteCond %{REQUEST_FILENAME} !-f
    RewriteCond %{REQUEST_FILENAME} !-d
    RewriteRule ^(.*)$ index.php?q=$1 [L,QSA]

Reference: https://www.drupal.org/node/43783

Building A Droplet LAMP Server

First lesson learned about Digital Ocean; for temporary Droplets using public / private key authentication in SSH for ‘root’ login is not worth it! In fact its a real PITA! But as turning off root access by SSH is strongly recommended there’s really no point anyway. Better to do steps 2 to 7 as a matter of routine.

Once I know that I will keep a Droplet longer term then I will set up an RSA key to authenticate to it using my ‘normal’ account, at least from Braeburn, using the method of configuring public / private key authentication here by running the command ssh-copy-id {remote_host} to install the local machine public key on the remote server.

My build method basically follows this page and this page.

  1. Select the lowest configuration option, nearest available datacentre (London or Amsterdam) and Debian 7.0 x32 as the O/S giving it an appropriate hostname. The root password is emailed, which for a temporary Droplet is fine.
  2. Log in using SSH and use passwd to immediately change the root password to the usual long Rob Roy
  3. Add garrathe as a normal user by running adduser
  4. Configure garrathe as a sudo capable user following the above build page and running visudo and adding the line:

    garrathe ALL=(ALL:ALL) ALL

    in the section

    # User privilege specification
    root ALL=(ALL:ALL) ALL
  5. Log out the root account and log in as me
  6. To make the server more secure open the configuration file

    sudo nano /etc/ssh/sshd_config

    Find the following sections and change the information where applicable:

    Port yyyymmdd
    (use a memorable date e.g. birthday or wedding anniversary)
    Protocol 2
    PermitRootLogin no
    (changing this from yes to no prevents future root login)

    Add these lines to the bottom of the document. AllowUsers will limit login to only the users on that line.

    UseDNS no
    (at this time I’m not sure what this line does?)
    AllowUsers garrathe

  7. Patch using sudo apt-get update to freshen the database of ‘stuff’ followed by an sudo apt-get upgrade to get things patched up to date.
  8. Confirm the name of the packages using apt-cache search {package name}.
  9. Install the AMP using sudo apt-get install apache2 mysql-server php-pear php5-mysql php5 libapache2-mod-php5.
    Info: The last one might be installed by one of the preceding ones and so may be redundante, update when sure.
  10. Confirm that Apache is working by http://{IP address}.
  11. Enter mysql -p in the shell to confirm MySQL is working.
  12. To check whether php is installed and running properly, use sudo nano /var/www/test.php to create a test.php in the /var/www folder with the phpinfo() function exactly as shown:

    # test.php


    Point a browser to http://ip.address/test.php and this should show all your php configuration and default settings.
  13. Optional: To install phpMyAdmin just execute sudo apt-get install phpmyadmin.

Building A Local LAMP Server

This is based on a local VMWare Guest starting with Debian 7.4 (i386) because the server has less than 2GB RAM. Its actually 512MB RAM and 20GB disk, so that it matches the lowest Digital Ocean Droplet configuration. The reason I’m doing this is because I want to move away from CentOS onto Debian longer term.

  1. Download the internet installer as its only about 240MB and boot a new VM from that. Use the text installer UI to install.
  2. Add install options of Web and SQL to the offered list.
  3. Install VMware Tools, but this requires the installation of GCC using apt-get install build-essential.
  4. {Next step is to test Apache and MySQL then update the snapshot}