How To Install Polr on Ubuntu 18.04

Polr is a free open source link shortening tool written in PHP and Lumen. This allows you to quickly host your own URL shortener. Its important features include dashboard, detailed link analytics and API. This guide will walk you through the process of installing Polr on CentOS 8.

Install Apache

Polr requires a web server as well as PHP and a MySLQ database. This tutorial will use the Apache web server, but you can choose any one that suits you.

Update repositories:

apt-get update

Install Apache web server:

apt-get install apache2 -y

Disable the default Apache site configuration and then you need to remove the default Apache index.html file

a2dissite 000-default.conf
rm /var/www/html/index.html

Next, you need to create a new Apache configuration file in order to subsequently install Polr

nano /etc/apache2/sites-available/polr.conf

Paste the current snippet into the file you created. Replace domain_example with your own domain name

<VirtualHost *:80>
    ServerName domain_example
    ServerAlias domain_example
    DocumentRoot "/var/www/html/public"
    <Directory "/var/www/html/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>

Turn this configuration

a2ensite polr.conf

Polr requires Apache to have mod_rewrite enabled. Enable Apache rewrite module

a2enmod rewrite

Restart the Apache service

systemctl restart apache2.service

Install PHP

Polr requires PHP and a number of PHP modules. Install PHP and PHP modules required by Polr

dnf install php php-xml php-pdo php-mysqlnd php-mbstring php-tokenizer php-json php-curl -y

Install MySQL and create a database

Polr stores data in a SQL database. Install and enable MySQL server

apt-get install mysql-server -y

Secure your MySQL installation by running the provided script

mysql_secure_installation

When prompted for the root password, choose a secure password and proceed with the installation

Would you like to setup VALIDATE PASSWORD plugin? [Y/N] N
New password: <Your Password>
Re-enter new password: <Your 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

Log into the MySQL console

mysql -u root -p

When prompted for a password, enter the root password you created earlier. After logging into the console, create a new database for Polr

mysql>CREATE DATABASE polr;

Create a new database user and grant him privileges for the created database. You can replace username and password with any username and password of your choice

mysql>GRANT ALL PRIVILEGES on polr.* to 'username'@'localhost' identified by 'password';
mysql>FLUSH PRIVILEGES;

Close the MySQL console

mysql>exit

Install Polr

Clone the Polr repository from Github

cd /var/www/html
git clone https://github.com/cydrobolt/polr.git --depth=1

Move the downloaded files to the root of the web server

mv ./polr/.[!.]* . && mv ./polr/* . && rm -rf polr

Download the Composr package. This is required to install dependencies.

curl -sS https://getcomposer.org/installer | php
apt-get install unzip -y

Install dependencies using Composr

php composer.phar install --no-dev -o

Copy the provided config file to enable the web installer

cp .env.setup .env

Set the appropriate file permissions

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

Start the Apache web server

systemctl start httpd.service

Was this article helpful?

Related Articles

Leave A Comment?