The sys admin's daily grind: Yourls

Short Story


Without TinyURL.com and similar URL shortening services, many Twitter postings would only have enough space left for "Look at this." But if you run a web server yourself, you might prefer to grow your own shortener.

By Charly Kühnast

Identi.ca and Twitter are currently driving demand for URL shortening services; 140 characters just doesn't give you enough space to waste 60 characters on a web address. Even in normal email, it can make sense to use a URL shortener if an embedded URL reaches the maximum line length of 80 characters. TinyURL.com, which recently acquired MakeAShorterLink.com, can squash these behemoths.

I prefer to run my own short-name generator for the same reason I run my own web, mail, antispam, and other services: Services I host myself are inherently preferable. And the learning effect is useful, even if things go wrong from time to time.

For my experiments on live URLs, I used Yourls (Your Own URL Shortener). This tool is available as a lean ZIP package from the Yourls download page [1] and requires Apache with PHP and Mod_Rewrite as well as MySQL. To begin my tests, I manually created a user and database in MySQL and relied on Yourls to create the required tables during the installation.

After unpacking the files, I dropped them into a directory on my web server. In an ideal world, you would have your own (virtual) web server for Yourls. The server should have as short a name as possible, of course (I'll never understand why makeashorterlink.com was popular). Here, I used the domain charly.in, which I recently registered at a LUG party in one of my more boisterous moments.

Next, I copied config-sample.php from the includes directory to config.php and entered my MySQL connection data, paths, and passwords for the admin area. The Yourls root directory has to be writable for the web server at least during the installation; this is where it stores a .htaccess file with the rewriting rules. The installation started when I accessed http://charly.in/admin and entered the password I had defined previously. At the end of the installation, the installer checks that the required software packages are in place, and you can then click to start Yourls.

Short but Good

The simple, but functional web interface offers both normal URL shortening as well as the ability to assign short names of your own design. This is a really practical feature if you ask me, because it lets you keep the same name to access web pages that shift locations frequently. The Yourls admin interface provides detailed reporting on the program's activities (Figure 1). Access counters with history, referrer trails, and a simple geolocation function based on IP addresses is more than I would have expected from so lean a tool.

Figure 1: The Yourls interface shows usage statistics - in this case, from Charly's shortening service at charly.in.

On the other hand, there is no denying that work is still in progress on Yourls; I had to protect the subdirectories manually against outside interference. Despite this, the shortener gives me more independence from third-party service providers, and I decided to let it live on in a cozy corner of my server.

INFO
[1] Yourls: http://www.yourls.org
THE AUTHOR

Charly Kühnast is a Unix operating system administrator at the Data Center in Moers, Germany. His tasks include firewall and DMZ security and availability. He divides his leisure time into hot, wet, and eastern sectors, where he enjoys cooking, freshwater aquariums, and learning Japanese, respectively.