Symbolic Links and Apache

I previously posted about a trick that I used to get frequently updated files to be mirrored on my website. However, I’ve come to realize that my method was needlessly circuitous. It turns out that Apache (the HTTP server that I and most of the internet use) support symbolic links!

All of my essays, reviews, etc. are on my server, but I don’t want my source files to be public. However, I want to share the PDFs of finished works to be available on my website. Symbolic links allow me to specify a particular file in a private directory, and make only that file available for all to see on my site. The syntax to generate a symbolic link is

ln -s /path/to/private/directory/file.pdf /path/to/public/directory/file.pdf

Once the link is made, we need to to set up Apache to follow the link. To do this, find the configuration file called httpd.conf and add the following lines to the file:

Options FollowSymLinks Indexes
AllowOverride None

After updating the configuration file, restart Apache. For me, the command is

sudo /ect/init.d/apache2 restart

At this point, the symbolic link will likely still not work. The problem that I ran into was that the parent directories of the private directory containing the file I wanted to make public didn’t have their permissions set properly. The permissions must allow “others” to execute the directories. The permissions can be modified using

sudo chmod o+x /path/to/directory

With that done, file.pdf is available on my website. Best of all, any changes that I make to my private copy are automatically reflected on the website. And I don’t need to rely on 3rd party software.

Will Rosenbaum

Saarbrücken, Germany

comments powered by Disqus