Skip to content

How To Install YOURLS

YOURLS is an (amazing) open-source software to create your own URL shortening service with your own custom domain. YOURLS stands for Your Own URL Shortener. It’s open-source, just like WordPress.

If you use YOURLS, then you don’t need to depend on a third-party URL shortening service to create short URLs. It’s also a great way to add branding to your short URLs, instead of using the same boring TinyURL or bitly links.

FAQ

But bitly Is Already There, Right?

It is, and I believe it will always be there. But having your personal URL shortening service gives you full control over your URLs. You don’t need to depend on random generated URLs, but you can also generate personalized URLs. Personal branding is really important, and Dustin Hartzler has a great episode about the importance of personal branding.

And What About The Stats & All?

Dude, YOURLS is an entire software to create your own service to create short links, so it gives you very detailed stats about each link and many great features. Plus, if you’re a developer, you can also create a custom plugin.

How To Install

Download YOURLS

First you need to download YOURLS’ latest version from their official Github page. Download the latest .zip version of the software. As of writing, 1.7 is the latest version available in the Github repository.

Create A MySQL Database For YOURLS

This software needs a database to store all the links data, so we need to create a MySQL database for the software. If you have some experience with databases, you can also install it to an existing database. You can create a MySQL database from your hosting panel or cPanel. Create a database , make sure you write down the database name, username and password you’ve just created. We these credentials later in the tutorial.

Create MySQL DatabaseConfigure YOURLS

Before we could upload YOURLS to our web server, we need to configure it.

  • Unzip the YOURLS archive
  • Copy user/config-sample.php to user/config.php
  • Open user/config.php with Notepad and fill following settings

Fill the following part of the file with your database username, password, database name, database host & table prefix for YOURLS. It’s the info that we used while creating our MySQL database.

/** MySQL database username */
define( 'YOURLS_DB_USER', 'your db user name' );

/** MySQL database password */
define( 'YOURLS_DB_PASS', 'your db password' );

/** The name of the database for YOURLS */
define( 'YOURLS_DB_NAME', 'yourls' );

/** MySQL hostname.
 ** If using a non standard port, specify it like 'hostname:port', eg. 'localhost:9999' or '127.0.0.1:666' */
define( 'YOURLS_DB_HOST', 'localhost' );

/** MySQL tables prefix */
define( 'YOURLS_DB_PREFIX', 'yourls_' );

Now scroll down a little cuz we have more stuff to define. You need to fill your website domain or the directory where you have installed YOURS and your GMT timezone.

If you have used www.example.com, then you won’t be able to use the service with www. prefix. In GMT timezone part, all you need to do is put your timezone, such as +5:30 for India.

/** YOURLS installation URL -- all lowercase and with no trailing slash.
 ** If you define it to "http://site.com", don't use "http://www.site.com" in your browser (and vice-versa) */
define( 'YOURLS_SITE', 'http://site.com' );

/** Timezone GMT offset */
define( 'YOURLS_HOURS_OFFSET', 0 );

Now we will set our preferred language for YOURLS dashboard. Define your language in the following lines (Click here for more info):

/** YOURLS language or "locale".
 ** Change this setting to "localize" YOURLS (use a translation instead of the default English). A corresponding .mo file
 ** must be installed in the user/language directory.
 ** See http://yourls.org/translations for more information */
define( 'YOURLS_LANG', '' );

Now let’s scroll a little more for some additional settings. Fill following info in this three-part code:

If you want only to have one pair of short/long URL then don’t touch this field, otherwise change the following to false:

/** Allow multiple short URLs for a same long URL
 ** Set to true to have only one pair of shortURL/longURL (default YOURLS behavior)
 ** Set to false to allow multiple short URLs pointing to the same long URL (bit.ly behavior) */
define( 'YOURLS_UNIQUE_URLS', true );

If you want your admin area to be password protected then don’t change the following value, otherwise jut change it to false:

/** Private means the Admin area will be protected with login/pass as defined below.
 ** Set to false for public usage (eg on a restricted intranet or for test setups)
 ** Read http://yourls.org/privatepublic for more details if you're unsure */
define( 'YOURLS_PRIVATE', true );

Now add some random code to the following field to encrypt cookies. You don’t need to remember this code, so make it long & complicated. You can generate a random code by clicking here.

/** A random secret hash used to encrypt cookies. You don't have to remember it, make it long and complicated. Hint: copy from http://yourls.org/cookie **/
define( 'YOURLS_COOKIEKEY', 'modify this text with something random' );

If you have password protected your admin area, then you will have define some user accounts, which can be defined from the following part:

/** Username(s) and password(s) allowed to access the site. Passwords either in plain text or as encrypted hashes
 ** YOURLS will auto encrypt plain text passwords in this file
 ** Read http://yourls.org/userpassword for more information */
$yourls_user_passwords = array(
    'username' => 'password',
    'username2' => 'password2'   // You can have one or more 'login'=>'password' lines
    );

You can add as many user accounts as you want just by adding more ‘login’=>’password’ lines.

If you’re a developer, then you might wanna turn debugging by defining following part:

/** Debug mode to output some internal information
 ** Default is false for live site. Enable when coding or before submitting a new issue */
define( 'YOURLS_DEBUG', false );

Now scroll down to the URL shortening settings more final steps. Define your URL shortening method in following lines:

  • 36: generates all lowercase keywords (ie: 13jkm)
  • 62: generates mixed case keywords (ie: 13jKm or 13JKm)
/** URL shortening method: 36 or 62 */
define( 'YOURLS_URL_CONVERT', 36 );

Time for the final part of configuration settings. Now we need to define some reserved terms which can’t be used for shortening URLs. Add or remove words in the following part:

/** 
* Reserved keywords (so that generated URLs won't match them)
* Define here negative, unwanted or potentially misleading keywords.
*/
$yourls_reserved_URL = array(
    'prom', 'forgot', 'rex', 'singer', 'duck', 'punk', 'sick', 'may',
);

Upload To Server

Just save the config.php file, and upload the entire YOURLS folder or files to your web server via FTP or File Manager. Just point your browser to http://yoursite.com/admin/ to see your new YOURLS installation in work.

That’s it! Don’t forget to leave your comments…

7 thoughts on “How To Install YOURLS”

Leave a Reply

Your email address will not be published. Required fields are marked *