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.
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:
nginx
: a lightweight and fast HTTP and reverse proxy server.php7-fpm
: a PHP FastCGI Process Manager that manages users' PHP processes.php7-mysql
: PHP extension for MySQL / MariaDB.php7-intl
: PHP extension for internationalization functions.php7-mbstring
: PHP extension for multibyte strings.php7-curl
: PHP extension for curl functions.php7-json
: JSON support for PHP.curl
: used to download and extract the YOURLS package.mysql-client
: command-line client for MySQL / MariaDB.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.
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.
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.
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.
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.
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!