Developing locally - playing with URLs

I have seen too many times that when people install drupal locally, they have no clue about how to set up local URL aliases, so here is my solution, resulting in urls like http://d/5/profile (drupal 5 installation for some profile related project).

The first step is to set up a clean, structured environment for our installations, preferably in our home directory.

File system setup

My structure looks as the following: I created a separate “projects” directory, under which i put the “drupal” directory. Thus ~/projects/drupal contains all the drupal related stuff that im working on. So far so good, but one needs further classifications to separate major versions. Sadly we can’t tag files on the filesystem level (yet), so lets stick to hierarchical taxonomy. Drupal 5 installations go to ~/projects/drupal/5, 6 respectively.

The resulting project structure looks like the following:

balu@codespace:~$ tree -a -d -L 1 -P projects/drupal/*

projects/drupal/5
|-- profile
|-- distro
|-- network
`-- s

projects/drupal/6
|-- s
`-- planetsoc

projects/drupal/contributions
|-- CVS
|-- modules
|-- profiles
`-- sandbox

projects/drupal/Distributions
|-- 5
`-- 6

All the subdirectories in 5 and 6 are drupal installations, separated for the sake of having a clean starting environment for each project (no interference from previous hacks).

Virtual Host setup

Now the next step is to provide short URLs to access these installations. The solution is to symlink our drupal installation to the www root: ln -sf ~/projects/drupal /var/www/d. Using virtual hosts in Apache its very easy to alias urls to custom webroot paths, for example the following configuration in apache will shortcut the “network” drupal 5 installation to http://d/5/network. It also enables Clean URLs (dont forget mod_rewrite).

In ubuntu/debian you can just put it to /etc/apache2/sites-enabled/000-default (lazy solution, will be overwritten probably on system upgrade), or create your own sites file (safer).

<VirtualHost d>
  DocumentRoot /var/www/d
  <Directory /var/www/d/>
    Options Indexes FollowSymLinks MultiViews
    AllowOverride All
  </Directory>
</VirtualHost>

Comments

Post new comment

The content of this field is kept private and will not be shown publicly.