How to install YOURLS on Ubuntu 14.04

install-yourls-on-an-ubuntu-14-04-vpsIn this guide, we will explain how to install YOURLS on an Ubuntu 14.04 VPS with MariaDB, PHP-FPM and Nginx. YOURLS stands for Your Own URL Shortener. YOURLS is an open source self-hosted application build with PHP which allows you to run your own URL shortening service. This guide should work on other Linux VPS systems as well but was tested and written for an Ubuntu 14.04 VPS.

Login to your VPS via SSH

ssh user@vps_IP

Update the system and install necessary packages

[user]$ sudo apt-get update && sudo apt-get -y upgrade
[user]$ sudo apt-get install software-properties-common git nano

Install MariaDB 10.1

To add the MariaDB repository to your sources list and install the latest MariaDB server, run the following commands:

[user]$ sudo apt-key adv --recv-keys --keyserver hkp:// 0xcbcb082a1bb943db
[user]$ sudo add-apt-repository 'deb trusty main'
[user]$ sudo apt-get update
[user]$ sudo apt-get install -y mariadb-server

When the installation is complete, run the following command to secure your installation:

[user]$ mysql_secure_installation

Next, we need to create a database for the YOURLS installation.

[user]$ mysql -uroot -p
MariaDB [(none)]> CREATE DATABASE yourls;
MariaDB [(none)]> GRANT ALL PRIVILEGES ON yourls.* TO 'yourls'@'localhost' IDENTIFIED BY 'yourls_passwd';
MariaDB [(none)]> \q

Install PHP, composer and required PHP modules

To install the latest stable version of PHP version 7 and all necessary modules, run:

[user]$ sudo add-apt-repository -y ppa:ondrej/php-7.0
[user]$ sudo apt-get update
[user]$ sudo apt-get -y install php7.0-fpm php7.0-cli php7.0-mysql php7.0-curl

PHP-FPM configuration

Create a new PHP-FPM pool for your user:

[user]$ sudo nano /etc/php/7.0/fpm/pool.d/your_user.conf
user = your_user
group = your_user
listen = /var/run/php/php7.0-fpm-your_user.sock
listen.owner = your_user = your_user
listen.mode = 0666
pm = ondemand
pm.max_children = 5
pm.process_idle_timeout = 10s
pm.max_requests = 200
chdir = /

Do not forget to change your_user with your username.

Restart PHP-FPM:

[user]$ sudo service php7.0-fpm restart

Clone and configure YOURLS

Create a root directory for the YOURLS installation using the following command:

[user]$ mkdir -p ~/{public_html,logs}

Clone the github repository

[user]$ git clone --branch master ~/

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

[user]$ cp ~/ ~/

Open the user/config.php file and edit the following values

[user]$ nano ~/
/** MySQL database username */
define( 'YOURLS_DB_USER', 'yourls' );

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

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

** If you define it to "http://sho.rt", don't use "http://www.sho.rt" in your browser (and vice-versa) */
define( 'YOURLS_SITE', '' );

/** A random secret hash used to encrypt cookies. You don't have to remember it, make it long and complicated. Hint: copy from **/
define( 'YOURLS_COOKIEKEY', 'fNK$M]~BfF&f0S#{X3P)sMM#A%2)R27D&THBMa8V' );

/** 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(
        'your_username' => 'your_password',
        // 'username2' => 'password2',
        // You can have one or more 'login'=>'password' lines

Install and configure Nginx

Ubuntu 14.04 comes with nginx version 1.4, to install the latest stable version of Nginx version 1.8, run:

[user]$ sudo add-apt-repository -y ppa:nginx/stable
[user]$ sudo apt-get update
[user]$ sudo apt-get -y install nginx

Create a new Nginx server block with the following content:

Need a fast and easy fix?
✔ Unlimited Managed Support
✔ Supports Your Software
✔ 2 CPU Cores
✔ 2 GB RAM
✔ 50 GB PCIe4 NVMe Disk
✔ 1854 GeekBench Score
✔ Unmetered Data Transfer

Now just $43 .99

[user]$ sudo nano /etc/nginx/sites-available/
server {
    listen      80;
    root        /home/your_user/;

    access_log /home/your_user/;
    error_log /home/your_user/;

    index index.php;

    location / {
        try_files $uri $uri/ /yourls-loader.php;
        expires 14d;
        add_header Cache-Control 'public';

    location ~ \.php$ {
        fastcgi_split_path_info ^(.+\.php)(/.+)$;
        fastcgi_pass unix:/var/run/php/php7.0-fpm-your_user.sock;
        fastcgi_index index.php;
        include fastcgi_params;
        fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
        fastcgi_intercept_errors off;
        fastcgi_buffer_size 16k;
        fastcgi_buffers 4 16k;

Do not forget to change your_user with your username.

Activate the server block by creating a symbolic link :

[user]$ sudo ln -s /etc/nginx/sites-available/ /etc/nginx/sites-enabled/

Test the Nginx configuration and restart nginx:

[user]$ sudo nginx -t
[user]$ sudo service nginx restart

Final steps

Open in your favorite web browser and you should see the YOURLS install screen. Click on the ‘Install YOURLS’ button to populate the database.

That’s it. You have successfully installed YOURLS on your Ubuntu 14.04 VPS. For more information about how to manage your YOURLS installation, please refer to the official YOURLS documentation.

Of course you don’t have to do any of this if you use one of our Linux VPS Hosting services, in which case you can simply ask our expert Linux admins to setup this for you. They are available 24×7 and will take care of your request immediately.

PS. If you liked this post please share it with your friends on the social networks using the buttons on the left or simply leave a reply below. Thanks.

2 thoughts on “How to install YOURLS on Ubuntu 14.04”

Leave a Comment