How to Install Shlink on MXLinux

Shlink is a self-hosted URL shortener that lets you create short and memorable links for your website or social media accounts. In this tutorial, we will guide you through the process of installing Shlink on MXLinux latest.

Prerequisites

Before you begin, make sure that you have:

Step 1 - Install Required Dependencies

First of all, you need to install some dependencies on your server. Open the terminal and run the following command to install the required packages:

sudo apt update
sudo apt install curl zip unzip wget mariadb-server mariadb-client nginx php-fpm php-mbstring php-mysql php-xml php-gd php-curl php-zip

The above command will install Nginx as the web server, MariaDB as the database server, and PHP as the scripting language.

Step 2 - Create a Database

Next, you need to create a new database and user for Shlink. Open the MariaDB console and log in with the following command:

sudo mysql -u root -p

Enter the MariaDB root password when prompted, and then create a new database and user with the following commands:

CREATE DATABASE shlink_db;
GRANT ALL PRIVILEGES ON shlink_db.* TO 'shlink_user'@'localhost' IDENTIFIED BY 'password';
FLUSH PRIVILEGES;
EXIT;

In the above commands, replace shlink_db, shlink_user, and password with your desired database name, username, and password.

Step 3 - Install Shlink

Now, it's time to install Shlink on your server. First, download the latest version of Shlink using the following command:

cd /var/www/
sudo curl -sS https://getshlink.io | sudo bash -s stable

The above command will download and extract the Shlink files to the /var/www/shlink directory.

Next, let's configure Shlink. Run the following command to copy the example configuration file and make the necessary changes:

cd /var/www/shlink/
sudo cp .env.example .env
sudo nano .env

In the .env file, update the database connection details with the following:

DATABASE_URL=mysql://shlink_user:password@localhost/shlink_db

Save and close the file by pressing CTRL+X, Y, and ENTER.

Step 4 - Configure Nginx

Next, we need to configure Nginx as the web server for Shlink. Run the following command to create a new Nginx server block:

sudo nano /etc/nginx/sites-available/shlink.conf

Add the following configuration to the file:

server {
    listen 80;
    listen [::]:80;

    server_name your-domain.com;

    return 301 https://$host$request_uri;
}

server {
    listen 443 ssl;
    listen [::]:443 ssl;

    server_name your-domain.com;

    ssl_certificate /path/to/your/cert.pem;
    ssl_certificate_key /path/to/your/key.pem;

    root /var/www/shlink/public;
    index index.php;

    location / {
        try_files $uri $uri/ /index.php?$query_string;
    }

    location ~ [^/]\.php(/|$) {
        fastcgi_split_path_info ^(.+?\.php)(/.*)$;
        if (!-f $document_root$fastcgi_script_name) {
            return 404;
        }

        include fastcgi_params;
        fastcgi_index index.php;
        fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
        fastcgi_param PATH_INFO $fastcgi_path_info;
        fastcgi_param HTTPS on;
        fastcgi_pass unix:/run/php/php7.X-fpm.sock; # Replace X with your PHP version
    }
}

In the above configuration, replace your-domain.com, /path/to/your/cert.pem and /path/to/your/key.pem with your actual domain name and SSL certificate paths.

Save and close the file by pressing CTRL+X, Y, and ENTER.

Next, create a symbolic link of the above configuration to the sites-enabled directory:

sudo ln -s /etc/nginx/sites-available/shlink.conf /etc/nginx/sites-enabled/

Finally, restart the Nginx service to apply the new changes:

sudo systemctl restart nginx

Step 5 - Initialize Shlink Database

Before running Shlink, you need to initialize the database with the default schema. Open the terminal and navigate to the Shlink directory using the following command:

cd /var/www/shlink/

Then, run the following command:

bin/doctrine-migrations migrations:migrate

This command will create the necessary tables and records in the database.

Step 6 - Test Shlink

Now, open your web browser and enter your domain name in the address bar. You should see the Shlink homepage. Congratulations! You have successfully installed Shlink on MXLinux.

Conclusion

In this tutorial, you learned how to install Shlink on MXLinux latest. If you face any issues during the installation process, feel free to ask for help in the comment section below.

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!