How to Install YOURLS on Alpine Linux Latest

In this tutorial, we will guide you through the steps to install YOURLS on Alpine Linux Latest. YOURLS, also known as Your Own URL Shortener, is a free open-source link shortener PHP script that allows users to create short links forwards to longer URLs.

Prerequisites

Step 1: Install Required Dependencies

Before we can begin installing YOURLS, we need to install several dependencies. Log into your server via SSH and type the following command:

sudo apk add nginx php7-fpm php7-mysql php7-intl php7-mbstring php7-curl php7-json curl mysql-client

This command installs the following packages:

Step 2: Download and Extract YOURLS

In this step, we will download the latest version of YOURLS from the official website using the curl command and extract the downloaded package. Execute the following commands:

mkdir /var/www
cd /var/www
curl -sSL https://github.com/YOURLS/YOURLS/archive/master.zip -o yourls.zip
unzip yourls.zip
rm yourls.zip
mv YOURLS-master yourls

The above commands create a new directory named yourls in /var/www and place the extracted YOURLS files from the downloaded ZIP archive.

Step 3: Configure Nginx Server Block for YOURLS

Yous must instruct the Nginx web server how to serve our YOURLS website. In this step, we will create an Nginx virtual host configuration file to handle the YOURLS requests. Execute the following commands:

sudo vi /etc/nginx/conf.d/yourls.conf

Add the following code block to the file:

server {
    listen 80;
    listen [::]:80;
    server_name example.com;
    root /var/www/yourls;
    index index.php index.html;
    access_log /var/log/nginx/yourls-access.log;
    error_log /var/log/nginx/yourls-error.log;

    location / {
        try_files $uri $uri/ /yourls-loader.php$is_args$args;
    }

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

Make sure to replace example.com with your domain name.

Step 4: Configure YOURLS

In this step, we will configure the YOURLS installation. Execute the following commands:

cd /var/www/yourls/
cp user/config-sample.php user/config.php
vi user/config.php

Configure the config.php file with database details as per the given configuration:

//Database settings:
define( 'YOURLS_DB_NAME', 'yourls_db' );
define( 'YOURLS_DB_USER', 'yourls_user' );
define( 'YOURLS_DB_PASS', 'yourls_password' );
define( 'YOURLS_DB_HOST', 'localhost' );
define( 'YOURLS_DB_PREFIX', 'yourls_' );

//Admin user credentials (only required for install)
//Replace the default username and password with secure login credentials
define( 'YOURLS_USER', 'yourls_admin_user' );
define( 'YOURLS_PASS', 'yourls_admin_password' );

Replace the values for YOURLS_DB_NAME, YOURLS_DB_USER, YOURLS_DB_PASS, YOURLS_USER, and YOURLS_PASS as required. Make sure to use a strong and complex password for the admin user.

Step 5: Create a Database and User for YOURLS

In this step, we will create a MySQL/MariaDB database and user for YOURLS. Connect to your database using a MySQL client such as the command-line or phpMyAdmin:

mysql -u root -p

Type the password when prompted.

CREATE DATABASE yourls_db;
CREATE USER 'yourls_user'@'localhost' IDENTIFIED BY 'yourls_password';
GRANT ALL PRIVILEGES ON yourls_db.* TO 'yourls_user'@'localhost';
FLUSH PRIVILEGES;
exit

This command will create a new database named yourls_db, a new user named yourls_user with password yourls_password and grants all privileges on the yourls_db database to the user. Make sure to replace the values for yourls_db, yourls_user, and yourls_password with the values you have set in the config.php file.

Step 6: Test YOURLS Installation

We have completed the YOURLS installation process. Open your web browser and enter your domain name in the address bar to access your YOURLS installation. Now, you can create short links using your own online URL shortener.

Conclusion

In this tutorial, we have explained the step-by-step process of installing YOURLS on Alpine Linux with the Nginx web server, PHP, and MySQL/MariaDB database. Now you can start using your own URL shortening service to manage your links efficiently.

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!