How to Install Shlink on Elementary OS Latest

Shlink is a free and open-source URL shortener written in PHP that allows you to shorten URLs and track clicks. In this tutorial, we will guide you through the installation process of Shlink on Elementary OS Latest.

Before you start, make sure your system is up-to-date. Open the terminal and update your system by running the following command:

sudo apt-get update && sudo apt-get upgrade

Step 1 - Install LAMP Stack

Shlink requires a LAMP (Linux, Apache, MySQL, and PHP) stack to be installed on your system. If you don't have a LAMP stack installed, you can install it by running the following command:

sudo apt-get install lamp-server^

During the installation, you will be prompted to enter a MySQL root password. Enter a strong password and confirm it. Once the installation is complete, test the LAMP stack by creating a test PHP file:

sudo nano /var/www/html/info.php

Add the following code to the file and save it:

<?php

phpinfo();

?>

Now, access the file in your web browser by entering http://<your-server-IP>/info.php. You should see the PHP information page.

Step 2 - Install Composer and Git

Shlink uses Composer, a dependency manager for PHP, to manage its dependencies. We need to install Composer to install Shlink. Run the following command to install Composer:

sudo apt-get install composer

Shlink is also hosted on Github, so we need Git to download Shlink. Run the following command to install Git:

sudo apt-get install git

Step 3 - Clone the Shlink Repository

Now, we will clone the Shlink repository from Github. Navigate to the /var/www/html/ directory:

cd /var/www/html/

Clone the Shlink repository by running the following command:

sudo git clone https://github.com/shlinkio/shlink.git

Step 4 - Install Shlink

Now that we have cloned the Shlink repository, we can install it using Composer. Navigate to the Shlink directory:

cd shlink/

Run the following command to install Shlink:

sudo composer install --no-dev --optimize-autoloader

During the installation, you will be prompted to enter your MySQL database details, such as the username, password, and database name. Enter the details and confirm the installation.

Once the installation is complete, run the following command to create the tables in the database:

sudo php bin/cli migrate

Step 5 - Configure Apache

We have installed Shlink, but we need to configure Apache to serve it. Open the Apache configuration file:

sudo nano /etc/apache2/sites-available/000-default.conf

Add the following lines to the file:

<VirtualHost *:80>
        ServerName shlink.local
        DocumentRoot /var/www/html/shlink/public
        <Directory /var/www/html/shlink/public>
                AllowOverride All
        </Directory>
        ErrorLog ${APACHE_LOG_DIR}/error.log
        CustomLog ${APACHE_LOG_DIR}/access.log combined
</VirtualHost>

Save and exit the file.

Enable the rewrite module by running the following command:

sudo a2enmod rewrite

Restart Apache by running the following command:

sudo systemctl restart apache2

Step 6 - Access Shlink

You have successfully installed Shlink on your Elementary OS Latest system. Open your web browser and enter http://shlink.local to access Shlink. You will see the Shlink login page. Enter your email and password to log in.

Congratulations, you have successfully installed Shlink on your Elementary OS Latest system. You can now use Shlink to shorten URLs and track clicks.

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!