Skip to Content

LAMP and all the trimmings on Ubuntu 'Intrepid Ibex'

Simply documenting my steps in setting up Apache2, PHP5 and MySQL how I like them. In particular, I like public_html user directories to work, and Mod Rewrite to be enabled.

The following gets everything installed and set up. During the MySQL install, you’re asked to set a MySQL root password.

  1. sudo apt-get install mysql-server mysql-client libmysqlclient15-dev
  2. sudo apt-get install apache2
  3. sudo apt-get install php5 libapache2-mod-php5 php5-mysql
  4.  
  5. sudo apt-get install phpmyadmin
  6. sudo a2enmod userdir
  7. sudo a2enmod rewrite
  8.  
  9. sudo /etc/init.d/apache2 restart

After that, setting up virtual hosts is as follows. Here, we’re adding a virtual host called hostexample.lan.

First I add a line to my /etc/hosts file (‘catbus’ is the name of my machine, the third line is the one I’ve added):

  1. 127.0.0.1       localhost
  2. 127.0.1.1       catbus
  3. 127.0.1.1       hostexample.lan

I also create the following directory:

mkdir ~/public_html/hostexample.lan

Then I create the following new file (substitue ‘vi’ for your text editor of choice, eg. ‘gedit’):

sudo vi /etc/apache2/sites-available/hostexample.lan

and I add the following to this new file:

  1. <VirtualHost *:80>
  2.   ServerName hostexample.lan
  3.   DocumentRoot /home/mark/public_html/hostexample.lan
  4.   DirectoryIndex index.php
  5.   <Directory /home/mark/public_html/hostexample.lan>
  6.     AllowOverride all
  7.     Options Indexes FollowSymLinks MultiViews
  8.     Order allow,deny
  9.     Allow from all
  10.   </Directory>
  11.   CustomLog /var/log/apache2/hostexample.lan-access.log combined
  12. </VirtualHost>

After that, I run the following commands:

sudo a2ensite hostexample.lan
sudo /etc/init.d/apache2 restart

And now you should be done. In my case, I’ve used PHPMyAdmin to create a database and database user, and then installed Drupal in my ~/public_html/hostexample.lan directory. Clean URLs (using Mod Rewrite) are working nicely, as is everything else.

I’ve written this up as I’ve gone along, so it may need tweaking in one or two places. I’ll try and repeat this soon with a fresh install to check the details.