How to Install Shlink on Arch Linux

Shlink is a URL shortener written in PHP. It is designed to be easy to use and to provide useful analytics on your shortened links. In this tutorial, we will show you how to install Shlink on Arch Linux.

Prerequisites

Before you start, you should have a few things in place:

Step 1: Update the System

Make sure your system is up-to-date. Run the following command to update your system:

sudo pacman -Syu

Step 2: Install Required Packages

To run Shlink, you need to install some additional packages that are not included in the base Arch Linux installation. Run the following command to install the necessary packages:

sudo pacman -S git unzip curl php php-intl php-sqlite php-gd php-zip php-mbstring mariadb

Step 3: Install Composer

Composer is a package manager for PHP. It is used to manage dependencies and install packages required by Shlink. To install Composer, run the following command:

curl -sS https://getcomposer.org/installer | sudo php -- --install-dir=/usr/local/bin --filename=composer

Step 4: Download and Install Shlink

Clone the Shlink repository from GitHub using the following command:

git clone https://github.com/shlinkio/shlink.git /var/www/shlink

Change to the Shlink directory using the following command:

cd /var/www/shlink

Run the following command to install the required dependencies:

sudo composer install --no-dev

Step 5: Configure the Database

Create a new database and user for Shlink using the following commands:

sudo mysql -u root -p
MariaDB> CREATE DATABASE shlink;
MariaDB> CREATE USER 'shlinkuser'@'localhost' IDENTIFIED BY 'password';
MariaDB> GRANT ALL PRIVILEGES ON shlink.* TO 'shlinkuser'@'localhost';
MariaDB> FLUSH PRIVILEGES;
MariaDB> exit;

Create a copy of the .env.dist file and name it .env using the following command:

cp .env.dist .env

Edit the .env file to set the database connection details:

DATABASE_DRIVER=pdo_mysql
DATABASE_NAME=shlink
DATABASE_USER=shlinkuser
DATABASE_PASSWORD=password
DATABASE_HOST=localhost

Step 6: Configure the Web Server

The final step is to configure your web server to serve Shlink. Below is an example of how to configure Apache.

Create a new virtual host configuration file using the following command:

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

Add the following code to the file:

<VirtualHost *:80>
    ServerName your-domain-name.com
    DocumentRoot /var/www/shlink/public

    <Directory "/var/www/shlink/public">
        AllowOverride All
    </Directory>

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

Save and close the file.

Enable the virtual host using the following command:

sudo a2ensite shlink

Restart Apache using the following command:

sudo systemctl restart httpd

Step 7: Complete the Installation

Now that everything is set up, you can complete the installation by running the following command:

sudo php /var/www/shlink/bin/short-code migrate

Conclusion

Shlink is now installed and ready to use. You can access the web interface by entering your server's IP address or domain name in a web browser. If everything is configured correctly, you should see the Shlink dashboard. You can start creating short links and tracking analytics by following the instructions provided in the Shlink documentation.

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!