How To Install Polr on CentOS 8

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, MySQL database and PHP. In this tutorial, we will be using the Apache web server. Install Apache web server.

dnf install httpd -y
systemctl enable httpd.service

Open ports 80 (HTTP) and 443 (HTTPS) through your firewall to access the server from the Internet

sudo firewall-cmd --permanent --zone=public --add-service=http
sudo firewall-cmd --permanent --zone=public --add-service=https
sudo firewall-cmd --reload

Create a new Apache config file to install Polr

nano /etc/httpd/conf.d/polr.conf

Paste the following snippet into the newly created file, replacing it with domain_example.com with your own domain name

<VirtualHost *:80>
    ServerName domain_example.com
    ServerAlias domain_example.com
    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 /var/log/httpd/error.log
    CustomLog /var/log/httpd/access.log combined
</VirtualHost>

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

dnf install mysql-server -y
systemctl enable mysqld.service
systemctl start mysqld.service

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>CREATE USER 'username'@'localhost' identified by 'password';
mysql>GRANT ALL PRIVILEGES on polr.* to 'username'@'localhost';
mysql>FLUSH PRIVILEGES;

Close the MySQL console

mysql>exit

Install Polr

Install git and clone the Polr repository from Github

dnf install git -y
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

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 apache:apache /var/www/html/
chmod -R 755 /var/www/html/
chcon -R -t httpd_sys_rw_content_t storage .env

Start the Apache web server

systemctl start httpd.service

Was this article helpful?

Related Articles

1 Comment