DEV Community 👩‍💻👨‍💻

Bidhan Khatri
Bidhan Khatri

Posted on • Updated on • Originally published at

How to Install YOURLS on CentOS 7 using NGINX + HTTPS

In this guide, I will explain how to install YOURLS on a Centos7 VPS with MariaDB 10.4, PHP 7.3, and Nginx with HTTPS. YOURLS stands for Your Own URL Shortener. YOURLS is an open-source self-hosted application build with PHP which allows you to run your own URL shortening service.

Also, check! Learn more tweaks in the Wiki documentation.

First Download the latest stable version MariaDB 10.4 on centos 7.

cat <<EOF | sudo tee -a /etc/yum.repos.d/MariaDB.repo
# MariaDB 10.4 CentOS repository list - created 2020-01-03 16:44 UTC
name = MariaDB
baseurl =

yum install MariaDB-server

systemctl start mariadb

systemctl enable mariadb
Enter fullscreen mode Exit fullscreen mode

Once the database server is installed, execute the ‘mysql_secure_installation’ post-installation script to set your MySQL root password and secure the server.

Enter fullscreen mode Exit fullscreen mode

Login to MySQL shell as root and configure the database.

mysql -u root -p
MariaDB [(none)]> CREATE DATABASE yourlsdb;
MariaDB [(none)]> GRANT ALL PRIVILEGES ON yourlsdb.* TO ‘username’@‘localhost' IDENTIFIED BY ‘password’;
MariaDB [(none)]> exit
Enter fullscreen mode Exit fullscreen mode

Now Install PHP 7.3 and require modules.

yum install epel-release yum-utils
yum install
yum-config-manager --enable remi-php73
yum install php php-common php-opcache php-mcrypt php-cli php-gd php-curl php-mysqlnd php-fpm
php -v
Enter fullscreen mode Exit fullscreen mode

Configure PHP-FPM:

Create a new PHP-FPM pool for yourls.

vim /etc/php-fpm.d/yourls.conf
listen = /var/run/php-fpm/php-fpm.sock
listen.allowed_clients =
listen.owner = nginx = nginx
listen.mode = 0666
user = nginx
group = nginx
pm = ondemand
pm.max_children = 50
pm.start_servers = 5
pm.min_spare_servers = 5
pm.max_spare_servers = 35
security.limit_extensions = .php .php3 .php4 .php5
php_admin_value[error_log] = /var/log/php-fpm/www-error.log
Enter fullscreen mode Exit fullscreen mode

Now Restart PHP-FPM

systemctl restart php-fpm
Enter fullscreen mode Exit fullscreen mode

Now Install and configure YOURLS.

yum install git
cd /var/www/html/
git clone
chown -R nginx: /var/www/html/YOURLS
mv /var/www/html/YOURLS/user/config-sample.php /var/www/html/YOURLS/user/config.php

vim /var/www/html/YOURLS/user/config.php
(Replace below lines according to your configuration.)

/** MySQL database username */
define( 'YOURLS_DB_USER', 'username' );

/** MySQL database password */
define( 'YOURLS_DB_PASS', 'password' );

/** The name of the database for YOURLS */
define( 'YOURLS_DB_NAME', 'yourlsdb' );

/** MySQL hostname.
define( 'YOURLS_DB_HOST', 'localhost' );

/** MySQL tables prefix */
define( 'YOURLS_DB_PREFIX', 'yourls_' );
define( 'YOURLS_SITE', '’ );
define('YOURLS_ADMIN_SSL', true);

/** A random secret hash used to encrypt cookies. You don't have to remember it, make it long and complicated.
define( 'YOURLS_COOKIEKEY', ‘0101011’01010x0x0x0x0xx0x0x0xx0asadqw23232dsdsd2e22232 );

$yourls_user_passwords = array(
        'bdnadmin => ‘password123' /* This credential is used for web login later.*/ ,
        // 'username2' => 'password2',   // You can have one or more 'login'=>'password' lines
Enter fullscreen mode Exit fullscreen mode

Install and configure Nginx:

yum install nginx
vim /etc/nginx/conf.d/

server {
        listen 80;
    listen  [::]:80;
        return 301 https://$host$request_uri;
server {
    listen 443 ssl;
    listen  [::]:443 ssl;
    ssl_certificate /etc/nginx/ssl/bundle.crt;
        ssl_certificate_key /etc/nginx/ssl/;
    root   /var/www/html/YOURLS;
        index index.php  index.html index.htm;
    access_log /var/log/nginx/;
    error_log /var/log/nginx/;
    index index.php;

# Rewrites
    location / {
        try_files $uri $uri/ /yourls-loader.php;
        expires 14d;
        add_header Cache-Control 'public';

# PHP Engine
    location ~ \.php$ {
        fastcgi_split_path_info ^(.+\.php)(/.+)$;
        fastcgi_pass unix:/var/run/php-fpm/php-fpm.sock;
        fastcgi_index index.php;
        include fastcgi_params;
        fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
        fastcgi_intercept_errors off;
        fastcgi_buffer_size 16k;
        fastcgi_buffers 4 16k;
Enter fullscreen mode Exit fullscreen mode

Test the Nginx configuration and restart Nginx:

nginx -t
systemctl restart nginx
Enter fullscreen mode Exit fullscreen mode

Final step:

Open**** in your favorite web browser and you should see the YOURLS install screen. Click on the ‘Install YOURLS’ button to populate the database.

Now login to YOURLS Administration Page.
username: bdnadmin
password: password123
Enter fullscreen mode Exit fullscreen mode

Top comments (1)

ozh profile image
྅༻ Ǭɀħ ༄༆ཉ

Neat article. Could you open a PR on to get it listed?

🌚 Friends don't let friends browse without dark mode.

Sorry, it's true.