How to Install Shlink on EndeavourOS

Shlink is a free and open-source URL shortener that allows you to easily create and manage short URLs for your website or project. In this tutorial, we will show you how to install Shlink on EndeavourOS.

Prerequisites

Before you begin, make sure that your system is up to date with the latest packages:

sudo pacman -Syu

You will also need to have the following installed:

Step 1: Install PHP Dependencies

To install the required PHP dependencies for Shlink, run the following command:

sudo pacman -S php php-apcu php-curl php-intl php-mbstring php-redis php-sqlite

Step 2: Install Composer

Composer is a package manager for PHP that is used to install and manage Shlink's dependencies.

To install Composer, run the following commands:

cd /tmp
sudo pacman -S php-composer

Step 3: Install and Configure MariaDB

Shlink uses a database to store its URL data. We will use MariaDB in this tutorial, but you can also use MySQL.

To install MariaDB, run the following command:

sudo pacman -S mariadb

After installation, start the MariaDB service and enable it to start at boot time:

sudo systemctl start mariadb
sudo systemctl enable mariadb

Once MariaDB is running, run the following command to secure it:

sudo mysql_secure_installation

Follow the prompts to secure your MariaDB installation.

Now, create a new database for Shlink:

sudo mysql -u root -p

Enter your MariaDB root password when prompted, and then run the following SQL query to create a new database named shlink:

CREATE DATABASE shlink;

Create a new user named shlink_user and grant it full permissions on the shlink database:

GRANT ALL ON shlink.* TO 'shlink_user'@'localhost' IDENTIFIED BY 'your-password-here';

Replace your-password-here with a strong password.

Flush the privileges and exit the MariaDB shell:

FLUSH PRIVILEGES;
EXIT;

Step 4: Install Shlink

First, create a new directory to install Shlink:

sudo mkdir /var/www/shlink

Next, navigate to the new directory:

cd /var/www/shlink

Now, use Composer to download and install Shlink:

sudo composer create-project shlinkio/shlink shlink --prefer-dist --no-dev

This may take a few minutes to complete.

Step 5: Configure Apache or Nginx

We will use Apache as the web server for this tutorial.

Create a new Apache virtual host configuration file for Shlink:

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

Add the following lines to the configuration file:

<VirtualHost *:80>
     ServerName your-domain.com

     DocumentRoot /var/www/shlink/public

     <Directory /var/www/shlink/public>
         AllowOverride All
         Require all granted
     </Directory>

     ErrorLog ${APACHE_LOG_DIR}/shlink-error.log
     CustomLog ${APACHE_LOG_DIR}/shlink-access.log combined
</VirtualHost>

Replace your-domain.com with your actual domain name.

Save and close the file.

Enable the new virtual host and restart Apache:

sudo a2ensite shlink.conf
sudo systemctl restart httpd

Step 6: Configure Shlink

Copy the sample configuration file and edit it:

cd /var/www/shlink
cp .env.dist .env
nano .env

Set the following configuration options in the file:

DATABASE_URL="mysql://shlink_user:your-password-here@localhost/shlink"
SECRET_KEY="an-encryption-secret-key-here"

Replace your-password-here with the password you set earlier in Step 3.

Set a strong, unique encryption secret key for your Shlink installation.

Save and close the file.

Step 7: Initialize Shlink

Now, initialize the Shlink database using Doctrine:

cd /var/www/shlink
sudo ./bin/cli db:init

This will create the necessary database tables.

Finally, generate a JWT authentication key using the following command:

sudo ./bin/cli api-key:generate

This will print a new authentication key. Copy it down somewhere safe.

Step 8: Test Shlink

Now that you have installed and configured Shlink, it's time to test it.

Open your web browser and navigate to your domain. If everything is working correctly, you should see the Shlink home page.

You can then start creating and managing short URLs using the Shlink web interface.

Congratulations! You have successfully installed and configured Shlink on EndeavourOS.

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!