How to Install YOURLS on CentOS 7

Want your very own server? Get our 1GB memory, Xeon V4, 25GB SSD VPS for £10.00 / month. Get a Cloud Server

YOURLS stands for Your Own URL Shortener. It is a small set of PHP scripts that will allow you to run your own URL shortening service. If you use YOURLS you own your data and don't need to rely on third party services. It's also a great way to add branding to your short URLs, instead of using the same public URL shortener everyone uses. Some of its features are listed below:

Private (your links only) or Public (everybody can create short links, fine for an intranet)

Sequential or custom URL keyword

Handy bookmarklets to easily shorten and share links

Awesome stats: historical click reports, referrers tracking, visitors geo-location

Neat Ajaxed interface

Terrific Plugin architecture to easily implement new features

Cool developer API

Full jsonp support

Friendly installer

Sample files to create your own public interface and more.

Requirements

To install YOURLS you don't have to own any special kind of hardware all you'll need to follow this guide is a CentOS 7 server and a domain that points to yourserverIP address and a root user. You can switch to root user from non root user using sudo -i command.

Update System

It is recommended to update your system and available packages before going through the installation process. The command below will do the job for you.

yum -y update

Installing Apache Web Server

Once the system is updated, you can install the dependencies required. To install YOURLS you will need to install the Apache web server along with MaraiDB and PHP with a few extensions.

Run the following command to install the Apache web server.

yum -y install httpd

Now you can start Apache and enable it to start at boot time, using the following commands.

systemctl start httpd.service systemctl enable httpd.service

You can check the status of Apache web server using the following command.

systemctl status httpd

You should see following output:

[root@sajid ~]# systemctl status httpd ● httpd.service - The Apache HTTP Server Loaded: loaded (/usr/lib/systemd/system/httpd.service; enabled; vendor preset: disabled) Active: active (running) since Tue 2017-02-14 04:03:54 UTC; 49s ago Docs: man:httpd(8) man:apachectl(8) Main PID: 10593 (httpd) Status: "Total requests: 0; Current requests/sec: 0; Current traffic: 0 B/sec" CGroup: /system.slice/httpd.service ├─10593 /usr/sbin/httpd -DFOREGROUND ├─10594 /usr/sbin/httpd -DFOREGROUND ├─10595 /usr/sbin/httpd -DFOREGROUND ├─10596 /usr/sbin/httpd -DFOREGROUND ├─10597 /usr/sbin/httpd -DFOREGROUND └─10598 /usr/sbin/httpd -DFOREGROUND Feb 14 04:03:54 ip-172-31-16-231 systemd[1]: Starting The Apache HTTP Server... Feb 14 04:03:54 ip-172-31-16-231 systemd[1]: Started The Apache HTTP Server.

We will need to install MariaDB for database purposes for YOURLS. MariaDB 5.5 is shipped in the default CentOS 7 repository, so just run this command to install MariaDB.

yum -y install mariadb-server

Now you'll have to start the MariaDB service and enable it to start at the boot time like we have done before for apache server, to do so please run following command.

systemctl start mariadb.service systemctl enable mariadb.service

You can check status of mariaDB using this below given command and you should see following output.

systemctl status mariadb.service

[root@ip-172-31-16-231 ~]# systemctl status mariadb.service ● mariadb.service - MariaDB database server Loaded: loaded (/usr/lib/systemd/system/mariadb.service; enabled; vendor preset: disabled) Active: active (running) since Tue 2017-02-14 04:05:52 UTC; 22s ago Main PID: 10736 (mysqld_safe) CGroup: /system.slice/mariadb.service ├─10736 /bin/sh /usr/bin/mysqld_safe --basedir=/usr └─10893 /usr/libexec/mysqld --basedir=/usr --datadir=/var/lib/mysql --plugin-dir=/usr/lib64/mysql/plugin --log-error=/var/log/ma... Feb 14 04:05:50 ip-172-31-16-231 mariadb-prepare-db-dir[10657]: The latest information about MariaDB is available at http://mariadb.org/. Feb 14 04:05:50 ip-172-31-16-231 mariadb-prepare-db-dir[10657]: You can find additional information about the MySQL part at: Feb 14 04:05:50 ip-172-31-16-231 mariadb-prepare-db-dir[10657]: http://dev.mysql.com Feb 14 04:05:50 ip-172-31-16-231 mariadb-prepare-db-dir[10657]: Support MariaDB development by buying support/new features from MariaDB Feb 14 04:05:50 ip-172-31-16-231 mariadb-prepare-db-dir[10657]: Corporation Ab. You can contact us about this at sales@mariadb.com. Feb 14 04:05:50 ip-172-31-16-231 mariadb-prepare-db-dir[10657]: Alternatively consider joining our community based development effort: Feb 14 04:05:50 ip-172-31-16-231 mariadb-prepare-db-dir[10657]: http://mariadb.com/kb/en/contributing-to-the-mariadb-project/ Feb 14 04:05:50 ip-172-31-16-231 mysqld_safe[10736]: 170214 04:05:50 mysqld_safe Logging to '/var/log/mariadb/mariadb.log'. Feb 14 04:05:50 ip-172-31-16-231 mysqld_safe[10736]: 170214 04:05:50 mysqld_safe Starting mysqld daemon with databases from /var/lib/mysql Feb 14 04:05:52 ip-172-31-16-231 systemd[1]: Started MariaDB database server.

We recommend you make sure that this installation is secure and to do so run following command.

mysql_secure_installation

You'll be asked to provide root password so enter appropriate password and answer yes to all questions by pressing Y.

Enter current password for root (enter for none): Just press the Enter button 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

Now you'll have to create a database for YOURLS so please follow the instructions.

mysql -u root -p

You'll be asked to enter password so simply enter a password and now execute the following queries to create a new database.

CREATE DATABASE yourls;

The above query will create a database named yourls. For the database you can use any name you prefer in the place of yourls. Make sure that you use semicolon at the end of each query as a query always ends with a semicolon.

Once the database is created you can create a new user and grant the required permissions to the user for the database.

CREATE USER 'yourls_user'@'localhost' IDENTIFIED BY 'StrongPassword';

The above query will create a user with username yourls_user. You can use any preferred username instead of yourls_user. Replace StrongPassword with a strong password.

Now provide the appropriate privileges to your database user over the database you have created. Run the following query to do so.

GRANT ALL PRIVILEGES ON yourls.* TO 'yourls_user'@'localhost';

Now run the following query to immediately apply the changes on the database privileges.

FLUSH PRIVILEGES;

Now you can exit from MariaDB prompt using following command. \q .

We will have to install PHP 7.1. To do so run following commands as shown below.

yum -y install epel-release

rpm -Uvh https://mirror.webtatic.com/yum/el7/webtatic-release.rpm

Now use this command to install PHP 7.1 and required extensions.

yum install -y mod_php71w php71w-mysqlnd php71w-common

Next you'll have to restart your apache web server to load new components that we just configured and use following command to restart apache web server.

systemctl restart httpd.service

Install YOURLS

Once we have installed all the dependencies required by the YOURLS then now we can install YOURLS from github repository so we will have to first install git on our server use this command to do so.

yum -y install git

Next go to web root directory and download latest version of YOURLS from github repository as shown below.

cd /var/www/html/

git clone https://github.com/YOURLS/YOURLS.git

You'll need to change proper ownership of it and you can do so with the following command.

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

You have downloaded YOURLS successfully now you'll need to configure this so configure it using below given process.

cd YOURLS

cp user/config-sample.php user/config.php

chown apache:apache user/config.php

You'll need to edit configuration file and you can to that using any text editor, we will use here nano text editor and you can also install it if you don't have already installed yum -y install nano

nano user/config.php

Please find these below given lines in configuration 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',

Now change these lines in accordance with:

define( 'YOURLS_DB_USER', 'yourls_user' ); define( 'YOURLS_DB_PASS', 'StrongPassword' ); define( 'YOURLS_DB_NAME', 'yourls' ); define( 'YOURLS_SITE', 'http://example.com' ); define( 'YOURLS_COOKIEKEY', 'fmoi4jfsjfasfjlkfjalfgcggjkihdgfjjgdfolsfmwemlgjhgigjgitjaaewesfsdfsdogmbnsin' ); // Use a long string consists of random characters. $yourls_user_passwords = array( 'username1' => 'password1', // Use your own username and password.

Save the file and exit from the text editor.

Create Virtual Host

You'll need to create a virtual host to complete the installation process and you can create a virtual host file using below shown process:

nano /etc/httpd/conf.d/yourls.conf

Add the content below to the the file to create a virtual host. Please change server name, server admin and server alias with your domain details.

<VirtualHost *:80> ServerAdmin admin@example.com DocumentRoot /var/www/html/YOURLS/ ServerName yourls.example.com ServerAlias www.yourls.example.com <Directory /var/www/html/YOURLS/> Options FollowSymLinks AllowOverride All Order allow,deny allow from all </Directory> ErrorLog /var/log/httpd/yourls.example.com-error_log CustomLog /var/log/httpd/yourls.example.com-access_log common </VirtualHost>

You'll need to restart the apache web server to apply changes that we just configured and we can restart our server using systemctl restart httpd .

Finally you'll have to modify firewall rules so if in case you don't have firewalld services installed on your server then you can install it using yum -y install firewalld and you can start it using systemctl start firewalld

Next run these below given commands to modify the firewalld rules.

firewall-cmd --zone=public --permanent --add-service=http

firewall-cmd --reload

Web Access

Open up your favorite web browser and visit http://yourdomain.com/admin and click on Install YOURLS link to finish the installation.

HP_NO_IMG/data/uploads/users/744ed2f1-2baa-42b2-b09d-ad15a2ae3934/2126828734.png" alt="" />

Click on YOURLS Administration Page to continue and you'll see admin user interface, please use username and password and finally click on login button.

HP_NO_IMG/data/uploads/users/744ed2f1-2baa-42b2-b09d-ad15a2ae3934/2072977773.png" alt=" " />

HP_NO_IMG/data/uploads/users/744ed2f1-2baa-42b2-b09d-ad15a2ae3934/688003602.png" alt=" " />

Conclusion

In this tutorial you have learned how to install YOURLS on CentOS 7 and you can also analyze your data using YOURLS.