Introduction
Polr is a free and open-source link shortener written in PHP and Lumen. It allows you to quickly host your own URL shortener. It's significant features include a management dashboard, detailed link analytics, and an API. This tutorial will guide you through the process of installing Polr on CentOS 8.
Prerequisites
This tutorial requires a Rcs Cloud Compute instance with CentOS 8 and root access, and a valid domain name pointing to your server.
Install Apache
Polr requires a web server, a MySQL database, and PHP. For this tutorial we will be using the Apache web server.
Install the Apache web server.
dnf install httpd -y
systemctl enable httpd.serviceOpen ports 80 (HTTP) and 443 (HTTPS) through the firewall to be able 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 --reloadCreate a new Apache configuration file for the Polr installation.
nano /etc/httpd/conf.d/polr.confPaste the following snippet into the newly created file, replacing example.com with your own domain name.
<VirtualHost *:80>
ServerName example.com
ServerAlias 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 the PHP modules required by Polr.
dnf install php php-xml php-pdo php-mysqlnd php-mbstring php-tokenizer php-json php-curl -yInstall MySQL & Create a Database
Polr stores data in an SQL database. Install and enable the MySQL server.
dnf install mysql-server -y
systemctl enable mysqld.service
systemctl start mysqld.serviceSecure the MySQL installation installation by running the provided script.
mysql_secure_installationWhen prompted for a root password, choose a safe password and proceed through 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] YLogin to the MySQL console.
mysql -u root -pWhen asked for a password, enter the root password created earlier. Once you are logged in to the console, create a new database for Polr.
mysql>CREATE DATABASE polr;Create a new database user and grant it privileges to the created database. You can replace username and password with the 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;Exit the MySQL console.
mysql>exitInstall 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=1Move the downloaded files to the root of the webserver.
mv ./polr/.[!.]* . && mv ./polr/* . && rm -rf polrDownload the Composr package. This is required to install dependencies.
curl -sS https://getcomposer.org/installer | phpInstall the dependencies with Composr.
php composer.phar install --no-dev -oCopy the provided configuration file to enable the web-based installer.
cp .env.setup .envSet 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 .envStart the Apache web server.
systemctl start httpd.serviceComplete the installation
Navigate to example.com/setup to launch the web-based Polr installer and enter the required information. Use the MySQL credentials created earlier for database configuration. Once you have submitted the setup form, the Polr installation will be completed.