How to Install Shlink on Manjaro

Shlink is a URL shortener software that can be self-hosted. It allows you to shorten and share your links privately.

In this tutorial, we will be installing Shlink on Manjaro.

Prerequisites

Before we start, make sure you have the following installed:

Step 1: Download Shlink

First, we need to download the Shlink code from Github. You can do this by running the following command:

wget https://github.com/shlinkio/shlink/releases/download/vX.X.X/shlink_X.X.X.tar.gz

Replace "X.X.X" with the version number you want to download.

Step 2: Unpack Shlink

Next, we need to unpack the downloaded file. You can do this by running the following command:

tar -xzf shlink_X.X.X.tar.gz

Step 3: Install Dependencies

Shlink requires some dependencies that we need to install before we can start using it. Run the following command to install these dependencies:

sudo pacman -S php php-fpm php-gd php-intl php-mcrypt php-pdo php-mysql php-curl php-redis redis mariadb

Step 4: Configure MariaDB

We need to create a new database and user for Shlink to use. Run the following commands to create a new database and user:

sudo mysql -u root -p

Enter your MySQL password.

CREATE DATABASE shlink;
CREATE USER 'shlink_user'@'localhost' IDENTIFIED BY 'shlink_password';
GRANT ALL PRIVILEGES ON shlink.* TO 'shlink_user'@'localhost';
FLUSH PRIVILEGES;
exit;

Replace "shlink_user" and "shlink_password" with your preferred values.

Step 5: Configure Shlink

We need to configure Shlink before we can start using it. Navigate to the Shlink directory and open the config/autoload directory. Rename the "local.php.dist" file to "local.php".

cd shlink-X.X.X
mv config/autoload/local.php.dist config/autoload/local.php

Open the "local.php" file and update the "database" section with the following:

// database connection options
'database' => [
    'driver' => 'pdo_mysql',
    'host' => 'localhost',
    'port' => '3306',
    'dbname' => 'shlink',
    'user' => 'shlink_user',
    'password' => 'shlink_password',
    'charset' => 'utf8mb4',
],

Replace "shlink_user" and "shlink_password" with your database user and password.

Step 6: Configure Apache or Nginx

We need to configure our web server to serve Shlink. If you are using Apache, create a new virtual host configuration file:

sudo nano /etc/httpd/conf/extra/shlink.conf

Add the following code:

<VirtualHost *:80>
    ServerName shlink.local
    DocumentRoot /path/to/shlink/public

    <Directory /path/to/shlink/public>
        AllowOverride all
        Require all granted
    </Directory>
</VirtualHost>

Replace "/path/to/shlink" with the path where you have installed Shlink.

If you are using Nginx, create a new server block:

sudo nano /etc/nginx/conf.d/shlink.conf

Add the following code:

server {
    listen 80;
    server_name shlink.local;

    root /path/to/shlink/public;
    index index.php;

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

    location ~ \.php$ {
        include fastcgi_params;
        fastcgi_pass unix:/run/php-fpm/php7.4-fpm.sock;
        fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
        fastcgi_param APPLICATION_ENV development;

        fastcgi_split_path_info ^(.+\.php)(/.+)$;
        fastcgi_index index.php;
    }
}

Replace "/path/to/shlink" with the path where you have installed Shlink.

Step 7: Start Shlink

We are now ready to start Shlink. Navigate to the Shlink directory and run the following command:

bin/cli db migrate --no-interaction

This will migrate the database.

Next, start the PHP server:

php -S 0.0.0.0:8080 -t public/

You can now access Shlink by navigating to "http://localhost:8080" in your web browser.

Conclusion

You have now successfully installed Shlink on Manjaro. You can start shortening your URLs privately using this application.

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!