How to Install YOURLS on Elementary OS

In this tutorial, we will be installing YOURLS, an open-source, self-hosted URL shortener, on the latest version of Elementary OS. Follow the steps below to complete the installation.

Prerequisites

Before we begin, ensure that your Elementary OS system is up to date and has the following packages installed:

You can install these packages by running the following command in your terminal:

sudo apt-get update
sudo apt-get install apache2 php mysql-server php-mysql

Step 1: Download and Configure YOURLS

  1. Download the latest version of YOURLS from the official website by running the following command in your terminal:

    wget https://yourls.org/latest.zip
    
  2. Extract the downloaded zip file using the following command:

    unzip latest.zip -d /var/www/html/
    
  3. Change the ownership of the extracted YOURLS directory using the following command:

    sudo chown -R www-data:www-data /var/www/html/yourls/
    
  4. Rename the user/config-sample.php file to user/config.php using the following command:

    mv /var/www/html/yourls/user/config-sample.php /var/www/html/yourls/user/config.php
    
  5. Open the config.php file using a text editor and add the following configuration settings:

    /** MySQL database username */
    define( 'YOURLS_DB_USER', 'your_mysql_username' );
    
    /** MySQL database password */
    define( 'YOURLS_DB_PASS', 'your_mysql_password' );
    
    /** The name of the database for YOURLS */
    define( 'YOURLS_DB_NAME', 'your_database_name' );
    
    /** MySQL hostname */
    define( 'YOURLS_DB_HOST', 'localhost' );
    
  6. Save and close the config.php file.

Step 2: Create a MySQL Database for YOURLS

  1. Log in to the MySQL command-line interface using the following command:

    mysql -u root -p
    
  2. Enter your MySQL root password when prompted.

  3. Create a new database for YOURLS using the following command:

    create database your_database_name;
    
  4. Create a new MySQL user for YOURLS using the following command:

    create user 'your_mysql_username'@'localhost' identified by 'your_mysql_password';
    
  5. Grant all privileges to the new MySQL user for the newly created database using the following command:

    grant all privileges on your_database_name.* to 'your_mysql_username'@'localhost';
    
  6. Flush the privileges using the following command:

    flush privileges;
    
  7. Exit the MySQL command-line interface by typing exit; and pressing Enter.

Step 3: Configure Apache

  1. Create a new virtual host configuration file for YOURLS using the following command:

    sudo nano /etc/apache2/sites-available/yourls.conf
    
  2. Paste the following configuration code into the file:

    <VirtualHost *:80>
        ServerAdmin admin@yourdomain.com
        DocumentRoot /var/www/html/yourls
    
        <Directory /var/www/html/yourls>
            Options Indexes FollowSymLinks MultiViews
            AllowOverride All
            Order allow,deny
            allow from all
        </Directory>
    
        ErrorLog ${APACHE_LOG_DIR}/yourls_error.log
        CustomLog ${APACHE_LOG_DIR}/yourls_access.log combined
    </VirtualHost>
    
  3. Save and close the file by pressing Ctrl + X, then Y, and finally Enter.

  4. Enable the YOURLS virtual host configuration by running the following command:

    sudo a2ensite yourls.conf
    
  5. Reload the Apache web server using the following command:

    sudo service apache2 reload
    

Step 4: Test YOURLS

  1. Open your web browser and navigate to http://localhost/admin/.

  2. Follow the on-screen instructions to configure and use YOURLS to create short URLs.

Congratulations! You have successfully installed and configured YOURLS on Elementary OS.

If you want to self-host in an easy, hands free way, need an external IP address, or simply want your data in your own hands, give IPv6.rs a try!

Alternatively, for the best virtual desktop, try Shells!