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

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

# apt update && sudo apt -y upgrade

# 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

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

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

Download using curl and run the Composer installer.

# curl -sS https://getcomposer.org/installer | 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.

# 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

CREATE DATABASE polr;

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

EXIT;

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

# mkdir -p /var/www/example.com

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

# git clone https://github.com/cydrobolt/polr.git — depth=1 /var/www/example.com

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

# cd /var/www/example.com

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/example.com/
# chmod -R 755 /var/www/example.com/

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

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

# nano /etc/apache2/sites-available/example.com.conf

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

<VirtualHost *:80>
ServerName [server IP] or example.com
ServerAlias example.com
DocumentRoot “/var/www/example.com/public”
<Directory “/var/www/example.com/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>

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

# a2ensite example.com.conf

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 http://example.com/setup 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 https://www.hostnextra.com