Practical Usage of Symbolic Links

Symbolic links work kind of like shortcuts in Windows.  I have found a couple of very useful scenarios.  The first is my local development environment.  For Linux users, it is best practice to keep all your files in your user folder.  For me, this is mainly to keep my system directories clean and to make backup of my files easier.  This leads me to my first usage:

1. Managing Development Files for Apache

Apache is looking for my files in the /var/www directory.  I want to keep my development files in my user directory.  To solve this I create a link to my development folders and store them in /var/www.  For example, if I wanted to run drupal local, which I do.  I create a link to drupal in /var/www like so:

ln -s /home/boz/public_html/drupal /var/www/drupal

ln is the command, "-s" means symbolic link, as opposed to a hard link, followed by the source directory and the new link.  Now I can access my drupal site in apache while maintaining my development files from my user directory.

2. Managing Multisite Configuration in Drupal

Drupal allows you to run as many domains as you like while sharing the same core Drupal files.  Included in my development cycle is the creation of a test site for my clients to look over my work and make sure everything good to go before we publish the site.  If I haven't transfered the domain for their site to my host then I usually just use a subdomain of this site for the testing i.e.  Drupal's multisite configuration is based on directories named after the domains they correspond to.  I don't want to maintain two different Drupal directories for the same project and so I create a symbolic link on my host servers between the test site domain directory and the target domain directory.  Here's is an example that I used on my most recent project for the website

ln -s /drupal/sites/ /drupal/sites/

Now when the domain is transfered I can just point it to the drupal folder and all is good.  The test site and the production site use the same files and the same database.

How do use Symbolic Links?

comments powered by Disqus

© Balanced Scale Media, LLC. All right reserved.