Your Own URL Shortener – YOURLS tutorial

yourls logoTwitter has definitely promoted a new service along the years, the URL shorteners…..Instead of sharing long URLs that restricted the number of tags we could set and the actual content, URL shorteners have helped to maximize the available 140 characters by providing a short new URL (as a redirection) to the long one.


But URL Shorteners has also improved in a general manner the sharing of long URL for SMS, Emails, or actually anywhere, where reducing the URL could save time. (If I cannot copy/paste a long URL, I’ll use my own URL shortener)

If you don’t want to depends on 3rd party service and wish to have your own URL shortener, YOURLS is probably the most popular one.

YOURLS - Screenshot

YOURLS, for Your Own URL Shortener has many benefits:

– Free and OpenSource,

– Could be use as Private (For you only) or Public (Anybody can create short links)

– Customized URL

– Bookmarklets to easily shorten and share links (On Twitter, Facebook, Tumblr)

– Got some stats (Historical click reports, referrers tracking, visitors geo-localization

– Clea interface (In Ajax)

Plugin architecture

– Easy to install

YOURLS - stats screenshot



YOURLS do not require much, only Apache with mod_rewrite enabled, PHP in version 5.2 or greater and MySQL in version 5 or greater.

1) Download YOURLS in your /var/www folder

You can download the latest stable archive here, or directly download the current master branch from git (What I’ll do)

cd /var/www
git clone git://

If you prefer to use the stable version (1.7 as of the date of this post), you can simply run


Don’t forget to unzip the archive if you have downloaded the stable version

2) Copy configuration file and fill the required information

cd /var/www/YOURLS
cp user/config-sample.php user/config.php

You can edit the config.php with nano for example

nano user/config.php

Your will need to define:

– MySQL user/pass and database. You can use PHPMyAdmin to easily create one.

– YOURLS installation URL, to set the URL you want to point your YOURLS service

– Languages, English per default, but you can set one of the following languages.

– Set a random secret hash (for cookies)

– Username(s) and password(s), you can allow several users

And this should be enough to start, you can modify more settings and add your own if you want.

3) Change ownership of your YOURLS folder to apache user (www-data) to avoid read/write permissions.

chown -R www-data:www-data /var/www/YOURLS

4) Enable Apache mod rewrite (if not done yet)

a2enmod rewrite
/etc/init.d/apache2 restart

5) Go to http://YourIP/YOURLS/admin to finalize the installation

YOURLS - Installation

6) Set automatic update

If like me you use the version directly from the git repository, you may also want to get latest update regularly. You can simply add a cron job to do it.

crontab -e

and at the end of the file, paste:

0 0 * * * cd /var/www/YOURLS && git pull -q master

This will update your YOURLS folder every day at 0:0 (midnight).

For more information, I recommend you to read the official wiki.


Loves to discover web-based apps to install on his own server@home and write articles about it


Add a comment