Tutorials  /  Linux Basics

Install YOURLS on CentOS 7: Full Setup Guide

Ccentron Redaktion · July 2025 ·6 min read ·Linux Basics, Tutorial

YOURLS (Your Own URL Shortener) is a free and open source platform designed for shortening URLs and performing detailed link analytics.

This guide walks you through installing YOURLS on a CentOS 7 system.

Requirements

  • CentOS 7 64-bit server
  • User account with sudo privileges
  • A domain name (e.g., example.com) pointing to your server's IP
VM

Matching infrastructure at centron

No hardware needed to follow along: ccloud³ VMs with full root access start at €3.12 per month, billed by the hour and ready in seconds. Rent a cloud server →

Step 1: System Update

Begin by logging in as a sudo user. Then, execute the following commands to bring your system up to date:

Console
sudo yum install epel-release -y
sudo yum clean all && sudo yum update -y && sudo shutdown -r now

Once the system has restarted, log back in using your sudo-enabled account.

Step 2: Install Apache Web Server

Use the YUM package manager to install Apache:

Console
sudo yum install httpd -y

Disable the default Apache welcome page with the following command:

Console
sudo sed -i 's/^/#&/g' /etc/httpd/conf.d/welcome.conf

Ensure Apache doesn't reveal directory listings to users:

Console
sudo sed -i "s/Options Indexes FollowSymLinks/Options FollowSymLinks/" /etc/httpd/conf/httpd.conf

Now, start Apache and configure it to launch automatically with the system:

Console
sudo systemctl start httpd.service
sudo systemctl enable httpd.service

Step 3: Install MariaDB 10.1

To proceed, we will set up the most stable version of MariaDB—version 10.1—on your CentOS 7 server.

Step 3.1: Add the MariaDB 10.1 Repository

Create a YUM repository configuration file for MariaDB 10.1 with the following command:

Code
cat <
cat <

Step 3.2: Install MariaDB Server and Client

Now install both the MariaDB server and client components using the following YUM command:

Console
sudo yum install MariaDB-server MariaDB-client -y

Step 3.3: Start and Enable MariaDB Service

Activate the MariaDB service and configure it to launch on system boot:

Console
sudo systemctl start mariadb.service
sudo systemctl enable mariadb.service

Step 3.4: Secure the MariaDB Installation

Run the following built-in script to enhance MariaDB security:

Console
sudo /usr/bin/mysql_secure_installation

Follow the interactive prompts and provide appropriate responses:

  • Enter current password for root (enter for none): Press Enter
  • Set root password? [Y/n]: Y
  • New password: your-root-password
  • Re-enter new password: your-root-password
  • Remove anonymous users? [Y/n]: Y
  • Disallow root login remotely? [Y/n]: Y
  • Remove test database and access to it? [Y/n]: Y
  • Reload privilege tables now? [Y/n]: Y

Step 3.5: Create YOURLS Database and User

Log into the MariaDB shell as the root user:

Code
mysql -u root -p

Once prompted, enter your MariaDB root password and press Enter.

Inside the MariaDB shell, execute the following SQL statements to create the database and user. Replace the sample credentials with your secure values:

Code
CREATE DATABASE yourls DEFAULT CHARACTER SET UTF8 COLLATE utf8_unicode_ci;
CREATE USER 'yourlsuser'@'localhost' IDENTIFIED BY 'yourpassword';
GRANT ALL PRIVILEGES ON yourls.* TO 'yourlsuser'@'localhost' IDENTIFIED BY 'yourpassword' WITH GRANT OPTION;
FLUSH PRIVILEGES;
EXIT;

Step 4: Install PHP 7.1 and Required Extensions

Begin by setting up PHP version 7.1 along with the necessary modules:

Console
sudo rpm -Uvh https://mirror.webtatic.com/yum/el7/webtatic-release.rpm
sudo yum install -y mod_php71w php71w-mysqlnd php71w-common

Step 5: Install YOURLS

Step 5.1: Download the YOURLS Application

Use Git to retrieve the latest YOURLS source code and place it in the Apache document root:

Console
sudo yum install git -y
cd /var/www/html/
sudo git clone https://github.com/YOURLS/YOURLS.git
sudo chown -R apache:apache /var/www/html/YOURLS
cd YOURLS

Step 5.2: Configure YOURLS

Create and prepare the configuration file:

Console
sudo cp user/config-sample.php user/config.php
sudo chown apache:apache user/config.php

Edit the configuration file using the vi editor:

Console
sudo vi user/config.php

Update the following lines to reflect your database and domain settings:

Code
define( 'YOURLS_DB_USER', 'yourlsuser' );
define( 'YOURLS_DB_PASS', 'yourpassword' );
define( 'YOURLS_DB_NAME', 'yourls' );
define( 'YOURLS_SITE', 'http://example.com' );
define( 'YOURLS_COOKIEKEY', 'fmoi4jfsjfasfjlkfjalfgcggjkihdgfjjgdfolsfmwemlgjhgigjgitjaaewesfsdfsdogmbnsin' );
$yourls_user_passwords = array(
        'username1' => 'password1',

After editing, save and exit:

Code
:wq!

Step 5.3: Set Up a Virtual Host

Create a virtual host configuration for the YOURLS application:

Code
cat <
cat <

Step 5.4: Restart Apache

Restart the Apache service to apply all changes:

Console
sudo systemctl restart httpd.service

Step 5.5: Open HTTP Traffic in Firewall

Allow HTTP service through the firewall and reload it:

Console
sudo firewall-cmd --zone=public --permanent --add-service=http
sudo firewall-cmd --reload

Step 5.6: Complete the Installation via Browser

Open a web browser and go to http://example.com/admin. Click the “Install YOURLS” link to begin setup.

Once installation is successful, navigate to the admin page and log in using:

  • Username: username1
  • Password: password1

Step 5.7: Secure Your Installation

After installation, restrict ownership permissions to enhance security:

Console
sudo chown -R root:root /var/www/html/YOURLS

To perform upgrades or install plugins later, restore Apache ownership as needed:

Console
sudo chown -R apache:apache /var/www/html/YOURLS

Conclusion

You’ve now completed the installation and basic configuration of YOURLS on your CentOS 7 server. From setting up the operating system, Apache, MariaDB, and PHP 7.1 to downloading and securing YOURLS, each step is crucial in ensuring a reliable and secure URL shortening platform.

With the web interface now accessible at http://example.com/admin, you can log in using your configured credentials and start managing short links with powerful built-in analytics features. Don't forget to revert file permissions for added security, and consider enabling HTTPS to further protect your installation.

Jetzt 200 € Guthaben sichern

Testen Sie Ihr Setup auf ccloud³

Registrieren Sie sich in der ccloud³ und erhalten Sie 200 € Startguthaben für Ihr Projekt – z. B. für eine PostgreSQL-VM mit automatischen Backups.

centron Redaktion Technische Redaktion

Das Redaktionsteam von centron schreibt Anleitungen aus dem Betriebsalltag: getestet auf unserer eigenen Plattform, betrieben im Rechenzentrum in Hallstadt bei Bamberg.

Kategorie Linux Basics
Teilen
Noch offene Fragen?

Unser Team hilft Ihnen bei Ihrem konkreten Setup weiter – von Menschen, die die Plattform selbst betreiben.

War dieses Tutorial hilfreich?

Ihre Antwort wird anonym gespeichert und hilft uns, die Tutorials zu verbessern.

Kommentare

Noch keine Kommentare – stellen Sie die erste Frage zu diesem Tutorial.

Zum Kommentieren anmelden

Kommentare stehen centron-Kunden offen. Melden Sie sich in Ihrem Konto an, um eine Frage zu diesem Tutorial zu stellen.

Weiterlesen

Das könnte Sie auch interessieren

Jetzt kostenlos anfangen

Melden Sie sich an und erhalten Sie in den ersten 60 Tagen ein Guthaben von 200 € bei centron.

Dieses Werbeangebot gilt nur für neue Konten. Angebot ausschließlich für Gewerbetreibende.

Jetzt loslegen Sales kontaktieren