Check yourls.org! Learn more tweaks in the Wiki documentation.

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.

First Download 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
# http://downloads.mariadb.org/mariadb/repositories/
[mariadb]
name = MariaDB
baseurl = http://yum.mariadb.org/10.4/centos7-amd64
gpgkey=https://yum.mariadb.org/RPM-GPG-KEY-MariaDB
gpgcheck=1
EOF
yum install MariaDB-server
systemctl start mariadb
systemctl enable mariadb

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

mysql_secure_connection

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)]> FLUSH PRIVILEGES;
MariaDB [(none)]> exit

Now Install PHP 7.3 and require modules.

yum install epel-release yum-utils
yum install http://rpms.remirepo.net/enterprise/remi-release-7.rpm
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

Configure PHP-FPM:

Create a new PHP-FPM Pool for yourls. vim /etc/php-fpm.d/yourls.conf

[yourls]
listen = /var/run/php-fpm/php-fpm.sock
listen.allowed_clients = 127.0.0.1
listen.owner = nginx
listen.group = 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

Now Restart PHP-FPM

systemctl restart php-fpm

Now Install and configure YOURLS.

yum install git
cd /var/www/html/
git clone https://github.com/YOURLS/YOURLS.git
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', 'https://link.bdn.com.np’ );
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
        );

Install and configure Nginx:

yum install nginx

vim /etc/nginx/conf.d/link.bdn.com.np.conf

server {
        listen 80;
	listen  [::]:80;
        server_name link.bdn.com.np www.link.bdn.com.np;
        return 301 https://$host$request_uri;
}
server {
	listen 443 ssl;
	listen  [::]:443 ssl;
        server_name  link.bdn.com.np www.link.bdn.com.np;
	ssl_certificate /etc/nginx/ssl/bundle.crt;
        ssl_certificate_key /etc/nginx/ssl/bdncom.np.key;
	root   /var/www/html/YOURLS;
        index index.php  index.html index.htm;
	access_log /var/log/nginx/link.bdn.com.np_access.log;
	error_log /var/log/nginx/link.bdn.com.np_error.log;
  	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;
    }
}

Test the Nginx configuration and restart nginx:

nginx -t
systemctl restart nginx

Final step:

Open https://link.bdn.com.np/admin/install.php in your favorite web browser and you should see the YOURLS install screen. Click on the Install YOURLS button to populate the database.

image-center

image-center Login to YOURLS Administration Page. https://link.bdn.com.np/admin
username: bdnadmin
password: password123

image-center

Comments