DEV Community

Cover image for Create your own URL shortener!
Benedikt Schächner for Technology Schächner

Posted on • Originally published at

Create your own URL shortener!

Today we come to a very interesting topic in the field of HomeServer.

If you like our articles, we would appreciate a Like & Comment❤️

We want to install our own URL shortener on our HomeSever. This means that shortened links can then be reached under your domain/desired name. There are several options here, e.g. you can also generate the shortened links randomly or provide them with numbers. But more on that. You can do it!

Or do you like to test it first?
Then try it below


First we create the databases and users again. To do that, let's switch to first

and then create the database with

and then the user with

CREATE USER 'yourlsuser'@'localhost' IDENTIFIED BY 'password';
and the corresponding password.

We'll give this to you

GRANT ALL PRIVILEGES ON yourls.* TO 'yourlsuser'@'localhost';
the permissions and load them as well


Now we can do that

leave again.

Download Yourls

Now let's switch

cd /tmp
Into the temporary directory we also download YOURLS with

sudo wget

We'll unpack that
and move it to the /var/www/ directory

sudo mv YOURLS-1.9.1 /var/www/
If we want, we can also add the folder

cd /var/www/
sudo mv YOURLS-1.9.1 yourls

config file

Now we have to go to the directory

cd yourls/user
switch and copy the config file there with

cp config-sample.php config.php
We now have to edit this with

sudo nano config.php
Here we need to adjust the following values:

define( 'YOURLS_DB_USER', 'yourlsuser' );
In the line above we need to enter our database user.

In the following line the database password

define( 'YOURLS_DB_PASS', 'password');
and the name of the database

define( 'YOURLS_DB_NAME', 'yourls' );

define( 'YOURLS_SITE', '' );
we have to enter our desired domain.

With ctrl + w we can also search for the following value:

$yourls_user_passwords = [
A user and a password are already specified below, which must be changed to the desired values.


Now we need to set the permissions again with

sudo chown -R www-data:www-data /var/www/yourls

sudo chmod -R 775 /var/www/yourls

Apache2 config file

We have to take these with us

sudo nano /etc/apache2/apache2.conf

There we search again with ctrl + w

We need all of these values, except for the area with <Directory /var/www/> from

AllowOverride None
Enter fullscreen mode Exit fullscreen mode


Enter fullscreen mode Exit fullscreen mode


We insert the following block above the area with <Directory /var/www/>:

<Directory /var/www/yourls/>
         Options Indexes FollowSymLinks
         Require all granted
virtual host
Now we create a virtual host with

sudo nano /etc/apache2/sites-available/yourls.conf
and add the following content:

<VirtualHost *:80>
     DocumentRoot "/var/www/yourls"

     <Directory "/var/www/yourls">
         Require all granted
         Options Indexes FollowSymLinks
         Order allow deny
         Allow from all

    ErrorLog ${APACHE_LOG_DIR}/error.log
    CustomLog ${APACHE_LOG_DIR}/access.log combined

Enter fullscreen mode Exit fullscreen mode

Of course, as always, we have to take this file with us

sudo a2ensite yourls.conf

Now we also start the web server

sudo service apache2 restart

sudo systemctl restart apache2.service

Now we can go into the browser to configuration!

This can be done by opening the domain (only if we have defined an A record or AAAA record) /admin or ip/admin in the browser.

Here we go!


Do you want a certificate for this instance?

This is what you get with our article:

Make NextCloud accessible from the Internet and an SSL certificate or https for our cloud and other web installations - Schächner

Thanks for reading,

Top comments (3)

thomasbnt profile image
Thomas Bnt

Hello ! Don't hesitate to put colors on your codeblock like this example for have to have a better understanding of your code 😎

console.log('Hello world!');
Enter fullscreen mode Exit fullscreen mode

Example of how to add colors and syntax in codeblocks

schbenedikt profile image
Benedikt Schächner

Thanks for the tip, hope it works now!

thomasbnt profile image
Thomas Bnt

A better post with colors, goood! 🙌🏼