Install YOURLS – Your Own URL Shortener on Ubuntu 20.04|18.04 Linux

Posted on 13 views

This guide will help you install YOURLS (Your Own URL Shortener) on Ubuntu 20.04|18.04 LTS server. YOURLS is a free and open source set of PHP scripts that will allow you to run Your Own URL Shortener.

YOURLS allows you to have full control over your data, detailed stats, analytics, plugins, and more. It has the following set of features

  • It is completely free and Open Source software.
  • Private (your links only) or Public (everybody can create short links, fine for an intranet)
  • Sequential or custom URL keyword
  • Handy bookmarklets to easily shorten and share links
  • Awesome stats: historical click reports, referrers tracking, visitors geo-location
  • Neat Ajaxed interface
  • Terrific Plugin architecture to easily implement new features
  • Cool developer API
  • Full jsonp support
  • Friendly installer
  • Sample files to create your own public interface and more

YOURLS Server requirements

  • Nginx / Apache (httpd) version 2.4 or greater, with mod_rewrite enabled
  • PHP version 5.3 or greater
  • MySQL version 5.0 or greater
  • PHP cURL extension

Follow these steps to setup YOURLS on your Ubuntu 20.04|18.04 Linux.

Step 1: Install PHP and cURL extension

YOURLS requires PHP installed on the host system for it to run. Install PHP on your Ubuntu 20.04|18.04 using the following commands

sudo apt update
sudo apt install -y php php-fpm php-cli php-mysql php-zip php-gd php-mbstring php-curl php-xml php-pear php-bcmath

Step 2: Install MariaDB

Download and install MariaDB database server:

sudo apt -y install mariadb-server

Once you have installed MariaDB, create a database and user for YOURLS.

GRANT ALL PRIVILEGES ON yourls.* TO 'yourls'@'localhost' IDENTIFIED BY "StrongPassword";

Step 3: Download and install YOURLS

We’ll put YOURLS download to the /srvdirectory. You can place the content in any directory you want your web server to load from.

cd /srv
git clone

Copy user/config-sample.php to user/config.php

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

Set database connection

 ** MySQL settings - You can get this info from your web host

/** MySQL database username */
define( 'YOURLS_DB_USER', 'yourls' );

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

/** 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 '' */
define( 'YOURLS_DB_HOST', 'localhost' );

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

Set website URL for YOURLS

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

Set your Timezone GMT offset

** Server timezone GMT offset */
define( 'YOURLS_HOURS_OFFSET', '+3' );

Add Username(s) and password(s) allowed to access the site. The Passwords can either be in plain text or as encrypted hashes. YOURLS will auto encrypt plain text passwords in this file

/** 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 for more information */
$yourls_user_passwords = array(
  'admin' => 'AdminPassword',
  'jmutai' => 'MyStrongPassword',
   // You can have one or more 'login'=>'password' lines

You can tweak other settings to your liking. When done save and close the file.

Step 4: Download and configure Nginx

My web server of choice is Nginx but you can use Apache. Install Nginx on Ubuntu 18.04 by running the command:

sudo apt install -y nginx

Create a new configuration /etc/nginx/conf.d/yourls.conf file with the contents below

  listen 80;
  root /srv/YOURLS;
  index index.php index.html index.htm;
  listen [::]:80;
  location / 
    try_files $uri $uri/ /yourls-loader.php$is_args$args;

  location ~ \.php$ 
    try_files $uri =404;
    fastcgi_split_path_info ^(.+\.php)(/.+)$;
    fastcgi_index index.php;
    fastcgi_param  SCRIPT_FILENAME  $document_root$fastcgi_script_name;
    fastcgi_pass unix:/var/run/php/php7.2-fpm.sock;
    include fastcgi_params;

Check nginx syntax to ensure it is OK

#  nginx -t
nginx: the configuration file /etc/nginx/nginx.conf syntax is ok
nginx: configuration file /etc/nginx/nginx.conf test is successful

Give Nginx web user ownership to /srv/YOURLS  directory.

sudo chown -R www-data:www-data /srv/YOURLS

Restart nginx service

sudo systemctl restart nginx

Finally, open the URL to finish YOURLS setup.


Click on “Install YOURLS” to start the installation. It will do checks and setup database, you should get a success message for the actions


Click on “YOURLS Administration Page” link to access the admin dashboard. Login with any of the user accounts added earlier.


You should get to the Admin page.


To shorten a URL, input it in the “Enter the URL” box, then click “Shorten The URL” to get a short version of the URL.


Thanks for using our guide to install YOURLS – Your Own URL Shortener on Ubuntu 18.04 Bionic Beaver Linux. Stay tuned for more How to Guides.


Gravatar Image
A systems engineer with excellent skills in systems administration, cloud computing, systems deployment, virtualization, containers, and a certified ethical hacker.