How to Install Polr on Ubuntu 20.04 with LAMP

In this article, we’ll explain how to install Polr on Ubuntu 20.04 with LAMP.

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 has a robust API (Application Programming Interface) that allows you to create links programmatically. It is released under the GNU General Public License v2.0, and it comes with a wide range of features that allow you to customize permissions, URL forwarding, and themes.


  • An Ubuntu 20.04 installed dedicated server or KVM VPS.
  • A root user access or normal user with administrative privileges.

Install Polr on Ubuntu 20.04 with LAMP

1. Keep the server updated

Update the package repository index, and upgrade the installed packages.

# apt update && sudo apt -y upgrade

2. Install Apache webserver

# apt install apache2 -y

In case, you enabled firewall and firewall block requests of the apache web server, open a port in the firewall.

# ufw allow 80/tcp

# ufw allow 443/tcp

# ufw reload

Start and enable apache2 service.

# systemctl start apache2 && systemctl enable apache2

3. Enable Apache mod_rewrite feature.

Enable the Apache mod_rewrite module. Polr requires it to craft user-friendly URLs.

# a2enmod rewrite

Restart the Apache web server to load the new modules and extensions.

# systemctl restart apache2

4. Install PHP

Here we are installing the default PHP version 7.4 and other modules for web deployments using the following command:

# apt install php php-pdo php-mysql php-mbstring php-tokenizer php-json php-curl -y

5. Install PHP Composer

Download using curl and run the Composer installer.

# curl -sS | php

To use Composer globally composer.phar to /usr/local/bin/ using following command.

# mv -f composer.phar /usr/local/bin/composer

Verify the Composer is working using following command:

# composer -V

The PHP Composer tool is now in place, but before installing Polr, you’ll create a database and a user account next.

6. Install MariaDB

# apt install mariadb-server mariadb-client -y

The default configuration of the MariaDB will not be secured. Let’s secured the installation using the following command:

# mysql_secure_installation

Once the script gets executed, it will ask multiple questions.

It will ask you to enter the current password for root (enter for none):

Then enter yes/y to the following security questions:

Set a root password? [Y/n]: y
Remove anonymous users? : y
Disallow root login remotely? : y
Remove test database and access to it? : y
Reload privilege tables now? : y

Login in to mysql

# mysql -u root -p

Now, create Polr database and user


GRANT ALL PRIVILEGES on polr.* TO ‘polr_user’@’localhost’ identified by ‘EXAMPLE_PASSWORD’;


7. Install Polr

Create a separate sub-directory for your Polr site under the Apache root directory /var/www.

# mkdir -p /var/www/

Next, use git to clone the Polr installation package from GitHub.

# git clone — depth=1 /var/www/

Use Linux cd command to navigate to the /var/www/ directory.

# cd /var/www/

Then, run the composer command below to install Polr.

# composer install — no-dev -o

Create a new configuration file by copying the default .env.setup file that ships with Polr to .env.

# cp .env.setup .env

Assign the appropriate ownership and permissions to the Polr files and directories.

# chown -R www-data:www-data /var/www/
# chmod -R 755 /var/www/

Your package is now installed. But before you run it, create a virtual host configuration file for your Polr application.

8. Create a Virtual Host File

create a new virtual host file for your Polr site under the /etc/apache2/sites-available/ directory.

# nano /etc/apache2/sites-available/

Then, add the information below into the file. Replace with the correct domain name or public IP address of your server.

<VirtualHost *:80>
ServerName [server IP] or
DocumentRoot “/var/www/”
<Directory “/var/www/”>
Require all granted
Options Indexes FollowSymLinks
AllowOverride All
Order allow,deny
Allow from all
ErrorLog ${APACHE_LOG_DIR}/error.log
CustomLog ${APACHE_LOG_DIR}/access.log combined

Save and close the file. Then, enable the configuration file you’ve just created using the a2ensite command.

# a2ensite

Then, restart the Apache webserver to load the new settings.

# systemctl restart apache2

Apache can now server your Polr website from the newly created virtual host file.

That’s it. The installation has been completed successfully.

Navigate to your browser and open URL or server IP.

You should see a web page for finalizing the setup, as shown below.

Modify database username and password and necessary fields.

In case you experience a problem when running the setup script, run the command below to initialize the database structure manually.

# php artisan migrate

In this article, we have explain how to install Polr on Ubuntu 20.04 with LAMP.




HostnExtra was founded in 2016. All of our servers are located in the continental United States and United Kingdom. View more details

Love podcasts or audiobooks? Learn on the go with our new app.

Recommended from Medium

The importance of utilising tools for internal processes

Native, Hybrid, or Web Apps: What Is the Best Approach for Lasting Success?

Creator of the Week: Veterinarian’s app for bird farmers

Introduction to Soba Platform — How Soba can fix the inefficiencies in the current music market.

Golang: Event-driven architecture

Service Mesh and Cookpad

Opening Jupyter Notebook From Any Desired Location

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store
HostnExtra Technologies

HostnExtra Technologies

HostnExtra was founded in 2016. All of our servers are located in the continental United States and United Kingdom. View more details

More from Medium

SOC147 — SSH Scan activity

HTB Vpn on Kasm using KALI made easy.

ssh and login to your ssh KASM server

Why Multi-Factor Authentication Is Critical To Stopping Hackers From Getting Into Your Accounts

API gateway and Its Invokation with Lamda