Hello, friends. In this post, you will learn how to install Polr on Ubuntu 20.04
On the project website, we find the following definition of Polr:
Polr is a quick, modern, and open-source link shortener. It allows you to host your own URL shortener, to brand your URLs, and to gain control over your data. It’s also GPLv2+ licensed.
Polr allows you to host your own URL shortener, and get control of statistics, it is a very easy-to-use tool, with a modern and intuitive interface, in addition, this tool has a powerful API.
Currently, it is very fashionable for brands to use this type of service to distribute their links in a fast and readable way. In addition, this allows you to control the number of times it is clicked on.
Install Polr on Ubuntu 20.04
Polr allows us to host it on our server for personalized service. But being created in PHP and needing MariaDB as database manager, we have to configure a LAMP server on our computer.
So, install LAMP on Ubuntu 20.04 with our tutorial.
Also, install these packages that contain PHP modules that are required by Polr as well as other packages to complete the tutorial.
php php-pdo php-mysql php-mbstring php-tokenizer php-tokenizer php-json php-curl unzip git
When you install them you can continue.
Creating the database and user for Polr
Now with MariaDB ready, it is necessary to create the structure that will allow Polr to use it without problems. This involves creating the database as well as the user that Polr will use to manage the data.
So, access the MariaDB shell:
sudo mysql -u root -p
And with these commands, create the database and the user.
CREATE DATABASE polrdb; GRANT ALL PRIVILEGES on polrdb.* TO 'polruser'@'localhost' IDENTIFIED BY 'password'; FLUSH PRIVILEGES;
Replace the fields with the ones you want and the password has to be guarded and strong.
Exit the MariaDB shell
exit;
Install Composer on Ubuntu 20.04
The installation of Polr will be done with Composer. So we have to install it.
To do this, download it from the project servers and “compile” it with the PHP command.
sudo curl -sS https://getcomposer.org/installer | php
This will originate a composer.phar
file which will be like the Composer executable. To make the installation global, move it to /usr/local/bin/
.
sudo mv composer.phar /usr/local/bin/composer
Download and install Polr on Ubuntu 20.04
Now we will proceed to download Polr using git
but first create the directory where it will be hosted.
sudo mkdir -p /var/www/polr
Assign the current user as the owner of the folder:
sudo chown -R $USER:$USER /var/www/polr
Then, download Polr by running:
sudo git clone https://github.com/cydrobolt/polr.git --depth=1 /var/www/polr Cloning into '/var/www/polr'... remote: Enumerating objects: 221, done. remote: Counting objects: 100% (221/221), done. remote: Compressing objects: 100% (204/204), done. remote: Total 221 (delta 9), reused 115 (delta 0), pack-reused 0 Receiving objects: 100% (221/221), 2.37 MiB | 4.18 MiB/s, done. Resolving deltas: 100% (9/9), done.
After that, access the generated folder named polr
and with the help of Composer, perform the installation:
cd /var/www/polr sudo composer install --no-dev -o
Now, rename the .env.setup
file to .env
to apply the default configuration.
sudo cp .env.setup .env
Next, assign the folder to belong to the Apache user. Also, set the necessary permissions.
sudo chown -R www-data:www-data /var/www/polr/ sudo chmod -R 755 /var/www/polr/
Creating a new VirtualHost for Polr
To access Polr correctly, it is necessary to create a new VirtualHost.
First, disable and delete the default one.
sudo rm -r /etc/apache2/sites-available/000-default.conf sudo a2dissite 000-default.conf removing dangling symlink /etc/apache2/sites-enabled/000-default.conf
After this, create a new configuration file for Polr.
sudo nano /etc/apache2/sites-enabled/polr.conf
And add the following:
<VirtualHost *:80> ServerName polr.osradar.test DocumentRoot "/var/www/polr/public" <Directory "/var/www/polr/public"> Require all granted Options Indexes FollowSymLinks AllowOverride All Order allow,deny Allow from all </Directory> ErrorLog ${APACHE_LOG_DIR}/error.log CustomLog ${APACHE_LOG_DIR}/access.log combined </VirtualHost>
Replace the value of ServerName
with the name of your domain. Save the changes and close the editor.
To apply all changes, enable the new site, the rewrite module, and restart Apache.
sudo a2ensite polr.conf sudo a2enmod rewrite sudo systemctl restart apache2
Complete the installation using the web interface
Now open a web browser and visit http://your-server
and you will see the installation screen.
At first, you will have to define the database parameters.
Further down you have other settings you can define such as shortening permissions.
Also, you will have to define an admin account with its password. And you can start the installation script.
Note: In case you get an error when starting the installation, run the command sudo php artisan migrate
.
In the end, you can continue the installation and you will see the Polr main screen.
So, enjoy it.
Conclusion
In this post, you have met such a useful tool as Polr. This link shortener that we can take full advantage of on our server is easy to install on Ubuntu 20.04 and this post is proof of that.