Symbolic Links for Development and Production Servers

Tech Add comments

I use a config file for most of my PHP projects–and it’s filled with variable declarations and constants I need throughout the site. I have to reference the config file in almost every one of my files for my site, and it might look something like

include_once('Library/WebServer/Documents/Gorilla/includes/config.inc');

The problem is, if I’m developing on one machine and uploading to another, the chances are the path will be different, like

/var/www/gorilla/includes/config.inc

So, instead of doing a global file/replace on every one of my files, or writing some weird “decider script” that used a $_SERVER variable to point to the right config file, I’m using the unix command “ln.” It’ll work for the Mac and other Linux flavors, and it’s saved me a ton of headaches.

ln -s /Library/WebServer/Documents/Gorilla /var/www/gorilla

The ln is “make links,” and the “-s” creates a symbolic link that allows you to reference the first link through the second. Make sure you have at least the base directory already (in this case “var”.) Now when you upload to your production server you won’t have to change hard-coded links to match your system. Just reference the production link, like

include_once('/var/www/gorilla/includes/config.inc')

and your development server uses the symbolic link to access your development file at /Library/WebServer/Documents/Gorilla/includes/config.inc.

[Slashdot] [Digg] [Reddit] [del.icio.us] [Facebook] [Technorati] [Google] [StumbleUpon]

Leave a Reply

WP Theme & Icons by N.Design Studio
Entries RSS Comments RSS Log in