If you are a web developer you will very often be in the situation where you have to manage a server that has a large number of websites running on it all of which are running the same Content Management System. So far so good, everything is in one place and you know how your server is setup.
But what happens when you find a bug in the CMS system or you need to upgrade all the sites? You probably have a simple proceedure in place that goes something like this:
- Update & Test the development copy of the website.
- Copy the website to a file server into a new directory (named by date or version).
- Upload the files from the file server to the live web server.
The idea being that you always have an exact copy of the files on your live server on a local server, and that you can easily revert to an seralier version should you have to.
(This is assuming you aren’t using a CVS system, just a well organised file system and some good procedures.)
If you only have a couple of websites this isn’t a problem, but if you have 20 or 60 then suddenly you can end up having to deal with a lot of operations. If you host on a Linux server the solution to your problems is called a Symbolic Link. When I think of Symbolic Links I think of Alice in Wonderland and magic tunnels.
Wikipedia describes Symbolic Links like this:
In computing, a symbolic link (often shortened to symlink and also known as a soft link) consists of a special type of file that serves as a reference to another file or directory. Unix-like operating systems in particular often feature symbolic links.
Unlike a hard link, a symbolic link does not point directly to data, but merely contains a symbolic path which an operating system uses to identify a hard link (or another symbolic link). Thus, when a user removes a symbolic link, the file to which it pointed remains unaffected. (In contrast, the removal of a hard link will result in the removal of the file if that file has no other hard links.) Systems can use symbolic links to refer to files even on other mounted file systems. The term orphan refers to a symbolic link whose target does not exist.
Symbolic links operate transparently, which means that their implementation remains invisible to applications. When a program opens, reads, or writes a symbolic link, the operating system will automatically redirect the relevant action to the target of the symlink. However, functions do exist to detect symbolic links so that applications may find and manipulate them.
Users should pay careful attention to the maintenance of symbolic links. Unlike hard links, if the target of a symbolic link is removed, the data vanishes and all links to it become orphans. Conversely, removing a symbolic link has no effect on its target.
Personally I don’t find this very helpful – what it means in practice however is that you can have create what appears to be a directory, but the contents of that directory are stored somewhere completely different. Even better you can create lots of these directories each of which appears unique, but which in fact all point to the same data.
Why have 60 copies of the same identical data and update it 60 times when instead you can update the source data once?
This is screenshot of a Linux directory listing illustrating the symbolically linked directories all pointing to the same files. To update all the CMS systems all you would need to do is update a single directory. This is a very simplified view of course, to run a system like this in real life each website needs its own configuration file(s) etc.
Looking at the file system via FTP you see this:
How to create a Symbolic Link
To create a symbolic link you need access to the command prompt – this will usually be via SSH. I use a small program called putty to do this.
The command is: ln -s source_file myfile where source_file is the file or directory you wish to link to and myfile is the name of the symbolic link you wish to create.
This screenshot shows the commands I use to create the symbolic links in the other examples: