How to Install Shlink on Alpine Linux Latest

This tutorial will guide you through the installation of Shlink on Alpine Linux Latest. Shlink is a self-hosted URL shortener that allows you to track clicks and gather analytics.

Prerequisites

Before proceeding with the installation, you will need to have the following prerequisites:

Step 1: Update and upgrade your system

Before installing Shlink, update and upgrade your system to the latest packages to avoid any potential issues.

sudo apk update
sudo apk upgrade

Step 2: Install required packages

Shlink requires several packages to be installed on your system. Use the following command to install them:

sudo apk add --no-cache \
  php8 \
  php8-curl \
  php8-dom \
  php8-fileinfo \
  php8-fpm \
  php8-gettext \
  php8-gd \
  php8-intl \
  php8-json \
  php8-mbstring \
  php8-mysqli \
  php8-openssl \
  php8-pdo \
  php8-pdo_mysql \
  php8-session \
  php8-simplexml \
  php8-tokenizer \
  php8-xml \
  php8-xmlwriter \
  php8-zip \
  mysql-client

Once completed, verify that all packages are installed correctly by running:

php8 -v

Step 3: Install Shlink

Download the latest Shlink release from the official website using the following command:

sudo wget https://github.com/shlinkio/shlink/releases/latest/download/shlink.phar -O /usr/local/bin/shlink

Then, give the executable permission to the file:

sudo chmod +x /usr/local/bin/shlink

Step 4: Configure Shlink

To configure Shlink, create a new directory to store the configuration file:

sudo mkdir /etc/shlink

Then, use your preferred text editor to create a new configuration file:

sudo vi /etc/shlink/config.yaml

Copy and paste the following YAML code to the file:

# Connection settings.
URL_SHORTENER_DB_DRIVER: pdo_mysql
URL_SHORTENER_DB_HOST: localhost
URL_SHORTENER_DB_USER: <enter username>
URL_SHORTENER_DB_PASSWORD: <enter password>
URL_SHORTENER_DB_NAME: shlink

# Base URL used to build short URLs when none is provided.
BASE_URL: http://<enter_your_ip_here>

# API key settings.
# Note: Replace the key with a random string of characters.
API_KEY_LENGTH: 32
API_KEY_REGENERATE_AFTER: '1 month'
API_KEY_CHARACTERS_WHITELIST: '[\dA-Za-z]'

# QR code settings.
GENERATE_QR_CODES: true
ENABLE_INSECURE_QR_CODES: false

# Logging settings.
LOGGER_NAME: shlink
LOGGER_LEVEL: INFO
LOGGER_PROCESSORS: ['shlink.processor.request_data', 'shlink.processor.content_negotiation']

# Database settings.
DATABASE_CHARSET: utf8mb4
DATABASE_COLLATION: utf8mb4_general_ci

# Cache settings.
CACHE_HOST: app
CACHE_PORT: 6379
CACHE_TTL: 7200

# Visit settings.
TRACK_VISITS: true
CHECK_VISITS_THRESHOLD: 10
KILL_VISITS_THRESHOLD: 100

Make sure to replace the placeholders with actual values.

Step 5: Start the Shlink service

Now that everything is configured, start the Shlink service using the following command:

sudo shlink openapi:start

Step 6: Test Shlink

To ensure that Shlink is running correctly, access the web interface by opening your web browser and navigating to:

http://<enter_your_ip_here>:8080

You should see a login page. Use the following credentials to log in:

Conclusion

You have successfully installed Shlink on Alpine Linux Latest. You can now begin creating short URLs and tracking clicks. Happy URL shortening!

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!