Introduction
YOURLS (Your Own URL Shortener) is an open source URL shortening and data analytics application.
We will cover the process of installing YOURLS on a CentOS 8 server.
Installation
Just follow the steps below:
- Update the system
sudo dnf install epel-release -y
sudo dnf clean all && sudo dnf update -y
- Install httpd web server
sudo dnf install httpd -y
- Remove the Apache welcome page
sudo sed -i 's/^/#&/g' /etc/httpd/conf.d/welcome.conf
- Prevent Apache from exposing files in visitors browsers
sudo sed -i "s/Options Indexes FollowSymLinks/Options FollowSymLinks/" /etc/httpd/conf/httpd.conf
- Start then enable httpd
sudo systemctl start httpd && sudo systemctl enable httpd
- Install mariadb
sudo dnf install mariadb mariadb-server -y
- Start and enable mariadb
sudo systemctl start mariadb.service && sudo systemctl enable mariadb.service
- Secure the installation of MariaDB
mysql_secure_installation
Answer the questions you get and don’t forget to provide a root password.
- Log into mysql shell as a root with:
mysql -u root -p
- Create a database yourls_db, a database user yourls_user, and the database user’s password as shown below.
CREATE DATABASE yourls_db DEFAULT CHARACTER SET UTF8 COLLATE utf8_unicode_ci;
CREATE USER 'yourls_user'@'localhost' IDENTIFIED BY 'unixcopPassword';
GRANT ALL PRIVILEGES ON yourls_db.* TO 'yourls_user'@'localhost' IDENTIFIED BY 'unixcopPassword' WITH GRANT OPTION;
FLUSH PRIVILEGES;
\q;
- Install php and necessary required extensions and packages with running the commands below:
sudo dnf -y install yum-utils
sudo dnf -y install https://dl.fedoraproject.org/pub/epel/epel-release-latest-8.noarch.rpm
sudo dnf -y install https://rpms.remirepo.net/enterprise/remi-release-8.rpm
dnf module reset php #run this with root user
sudo dnf module install php:remi-7.3
sudo yum install wget git php php-bcmath php-json php-xml php-common php-curl php-intl php-zip php-imap php-pear php-cgi php-mbstring php-gd php-mysqlnd php-gettext -y
- Install YOURLS with git.
cd /var/www/html/
sudo git clone https://github.com/YOURLS/YOURLS.git
sudo chown -R apache:apache /var/www/html/YOURLS
- Configure YOURLS with running the commands below
cd YOURLS
sudo cp user/config-sample.php user/config.php
sudo chown apache:apache user/config.php
- Also modify some values in the file config.php
vim /var/www/html/YOURLS/user/config.php
- Find the below lines in config.php file
define( 'YOURLS_DB_USER', 'your db user name' );
define( 'YOURLS_DB_PASS', 'your db password' );
define( 'YOURLS_DB_NAME', 'yourls' );
define( 'YOURLS_SITE', 'http://your-own-domain-here.com' );
define( 'YOURLS_COOKIEKEY', 'modify this text with something random' );
$yourls_user_passwords = array(
'username' => 'password',
- Replace them one by one as follow:
define( 'YOURLS_DB_USER', 'yourls_user' );
define( 'YOURLS_DB_PASS', 'unixcopPassword' );
define( 'YOURLS_DB_NAME', 'yourls_db' );
define( 'YOURLS_SITE', 'http://yourls.unixcop.com' );
define( 'YOURLS_COOKIEKEY', 'ueejdmbsfffgsjskwnxsjssxiejdoedchcvg' ); // Use a long string consists of random characters.
$yourls_user_passwords = array(
'unixcop' => 'unixcopPassword', // Use your own username and password.
- Then Save and quit
- Create a virtual host for YOURLS
vim /etc/httpd/conf.d/yourls.conf
- Then add the following
<VirtualHost *:80>
ServerAdmin admin@unixcop.com
DocumentRoot /var/www/html/YOURLS/
ServerName yourls.unixcop.com
ServerAlias www.yourls.unixcop.com
<Directory /var/www/html/YOURLS/>
Options FollowSymLinks
AllowOverride All
Order allow,deny
allow from all
</Directory>
ErrorLog /var/log/httpd/yourls.unixcop.com-error_log
CustomLog /var/log/httpd/yourls.unixcop.com-access_log common
</VirtualHost>
- Restart httpd
sudo systemctl restart httpd
- Allow http ports on the firewall
sudo firewall-cmd --zone=public --permanent --add-service=http
sudo firewall-cmd --reload
- Go to your web browser to http://yourls.unixcop.com/admin or http://IP_address/admin then click Install YOURLS as shown below in the screenshot.

- Check that everything is ok and checked right or green light then press ENTER to get proceed.

- You will be redirected to the login page as shown below .. provide your username and password you modified in the config.php file.

- The below screenshot shows your Dashboard

- Enjoy with YOURLS.
Conclusion
That’s it ..
We illustrated how to install YOURLS YOURLS (Your Own URL Shortener)in CentOS 8 Server.