Install YOURLS on CentOS 7: A Step-by-Step Guide
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
Step 1: System Update
Begin by logging in as a sudo user. Then, execute the following commands to bring your system up to date:
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:
sudo yum install httpd -y
Disable the default Apache welcome page with the following command:
sudo sed -i 's/^/#&/g' /etc/httpd/conf.d/welcome.conf
Ensure Apache doesn’t reveal directory listings to users:
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:
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:
cat <
Step 3.2: Install MariaDB Server and Client
Now install both the MariaDB server and client components using the following YUM command:
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:
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:
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:
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:
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:
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:
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:
sudo cp user/config-sample.php user/config.php
sudo chown apache:apache user/config.php
Edit the configuration file using the vi
editor:
sudo vi user/config.php
Update the following lines to reflect your database and domain settings:
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:
:wq!
Step 5.3: Set Up a Virtual Host
Create a virtual host configuration for the YOURLS application:
cat <
Step 5.4: Restart Apache
Restart the Apache service to apply all changes:
sudo systemctl restart httpd.service
Step 5.5: Open HTTP Traffic in Firewall
Allow HTTP service through the firewall and reload it:
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:
sudo chown -R root:root /var/www/html/YOURLS
To perform upgrades or install plugins later, restore Apache ownership as needed:
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.