Setting up Drupal sites on Fink AMP with virtual hosts

Needless to say, the reason for setting up AMP is to run Drupal on it. And setting up a virtual host is really useful.

Virtual host?

A virtual host (also referred to as vhost) allows you to access a resource (i.e. a website in this case) in arbitrary names. For example, if you have a Drupal site set up (let's call it 'site1') without a virtual host, they are most likely accessible from a web browser by the URL 'http://localhost/site1'. By setting up a virtual host, you can make the site accessible with pretty much any URL you like, for example 'http://site1.dev'.

Overview of the process:

  1. Edit apache's config file
  2. Create and edit a new virtual host config file
  3. Create a directory and settings.php for the site for Drupal
  4. Edit hosts file
  5. Reboot apache

Prerequisites:

  • You need to set up AMP using Fink*
  • You have installed Drupal before**

*You can set up virtual hosts with Apache that is not installed by Fink. But if you are following this instruction step-by-step, this is required.

**If you want to know how to set up vhosts but not using Drupal, simply skip Step 4. I highly recommend using Drupal though, especially if you are a PHP developer :p

Assumptions:

  • You have AMP installed on Mac OSX version 10.5 (directory structure is different from the previous versions)
  • You chose the default directory for Fink installation (which is '/sw/')
  • You are installing Drupal under /sw/var/www/drupal6
  • We are setting up a Drupal site called 'drupalsite' locally, which is accessible from the browser by the URL 'http://drupalsite.dev'
  • You know how to use vi

So the actual steps:

1. Edit apache's config file

Open the terminal and enter the following command.

sudo vi /sw/etc/apache2/apache2.conf

This opens the config file with the vi text editor.

Make sure the following line is uncommented (i.e. there is no '#' sign at the beginning of the line). If you can't find the line, add it to the config file.

Include /sw/etc/apache2/sites-enabled/

 

2. Create and edit a new virtual host config file

In terminal, enter the following command to create a copy of an existing file:

cd /sw/etc/apache2/sites-available
sudo cp default drupalsite.dev

Things you want to edit in this file:

  • Add the following lines under <VirtualHost *>
    ServerName drupalsite.dev
    DocumentRoot /sw/var/www/drupal6
  • Under <Directory /sw/var/www/> Change 'AllowOverride NONE' to 'AllowOverride ALL'
  • comment out RedirectMatch by adding '#'
    # RedirectMatch ^/$ /apache2-default/

     

After saving and closing the file, run the following command:

sudo a2ensite drupalsite.dev

3. Create a directory and settings.php for the site for Drupal

Create a copy of 'default' folder and its content (i.e. default.settings.php). Rename the folder to drupalsite.dev and also rename and edit the settings file accordingly.

4. Edit hosts file

Hosts file associates host names and IP addresses. Here, you will edit the file to tell your computer to look at 127.0.0.1 (which is your machine) when access to a URL 'drupalsite.dev' is detected. A more detailed explanation on hosts file

Enter the following command in terminal to open the file:

sudo vi /etc/hosts

...and add the following line:

127.0.0.1 drupalsite.dev

 

5. Reboot apache

Run the following command in terminal

sudo apache2ctl restart