How to install Polr Link Shortener on Debian 10

How to install Polr Link Shortener on Debian 10

Polr is a free open source URL shortener that allows you to host your own link shortener. It is written in PHP and Lumen and uses MariaDB to store its data. With Polr, you can create new links or find existing links without breaking existing code.

In this tutorial, we will show you how to install Polr Link Shortener software on a Debian 10 server.

prerequisites

  • A server running Debian 10.
  • A valid domain name pointing to the server IP. In this tutorial, we will use the pollr.example.com domain.
  • A root password is configured on your server.

getting Started

Before you start, it’s a good idea to update your system to the latest version. You can use the following command to update the system:

apt-get update -y apt-get upgrade -y

After updating the system, restart it to implement the changes.

Install LAMP server

First, you will need to install the Apache web server, MariaDB server, PHP, and other packages in your system. You can install all components with:

apt-get install apache2 mariadb-server libapache2-mod-php php php-pdo php-mysql php-mbstring php-tokenizer php-json php-curl git wget unzip -y

Once all packages are installed, start the Apache and MariaDB services and have them start after the system reboots.

systemctl start apache2 systemctl start mariadb systemctl enable apache2 systemctl enable mariadb

When you are done, you can proceed to the next step.

Configure MariaDB database

By default, MariaDB root password is not configured in Debian 10. Therefore, you need to set it up first.

To do this, log in to the MariaDB shell using the following command:

mysql

After logging in, set your MariaDB root password using the following command:

MariaDB [(none)]> SET PASSWORD FOR 'root'@'localhost' = PASSWORD("newpassword");

Next, create a database and user for Polr using the following command:

MariaDB [(none)]> CREATE DATABASE polrdb; MariaDB [(none)]> GRANT ALL ON polrdb.* TO 'polr' IDENTIFIED BY 'password';

Next, refresh the privileges and exit from the MariaDB shell using the following command:

MariaDB [(none)]> FLUSH PRIVILEGES; MariaDB [(none)]> EXIT;

When you are done, you can proceed to the next step.

Install composer

Next, you will need to install Composer on your system. Composer is a PHP dependency manager for installing all PHP dependencies for your project.

First, download Composer using the following command:

php -r "copy('https://getcomposer.org/installer', 'composer-setup.php');"

Next, you will need to verify the data integrity of the downloaded script by comparing the SHA-384 hash of the script to the latest hash.

To do this, download the signature of the latest Composer installer from the Git repository and store it in a variable named HASH:

HASH="$(wget -q -O - https://composer.github.io/installer.sig)"

Next, verify the installation script using the following command:

php -r "if (hash_file('SHA384', 'composer-setup.php') === '$HASH') { echo 'Installer verified'; } else { echo 'Installer corrupt'; unlink('composer-setup.php'); } echo PHP_EOL;"

If the hash values ​​match, you will see the following output:

Installer verified

Finally, install Composer using the following command:

php composer-setup.php --install-dir=/usr/local/bin --filename=composer

After the installation is complete, you should see the following output:

All settings correct for using Composer
Downloading...
Composer (version 1.9.2) successfully installed to: /usr/local/bin/composer
Use it: php /usr/local/bin/composer

When you are done, you can proceed to the next step.

Installation poll

First, download the latest version of Polr from the Git repository to the Apache web root:

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

After downloading, change directory to poll and install all required dependencies using the following command:

cd polr composer install --no-dev -o

Next, enable the web-based installer by renaming the following files:

mv .env.setup .env

Next, give the poll directory the appropriate permissions as follows:

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

When you are done, you can proceed to the next step.

Configure Apache for polling

Next, you will need to create an Apache virtual host profile for Polr. You can create it using:

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

Add the following lines:


     ServerAdmin [email protected]
     DocumentRoot /var/www/html/polr/public
     ServerName polr.example.com

     
          Options FollowSymlinks
          AllowOverride All
          Require all granted
     

     ErrorLog ${APACHE_LOG_DIR}/polr_error.log
     CustomLog ${APACHE_LOG_DIR}/polr_access.log combined


Save and close the file when you are finished. Then, enable the Apache virtual host file and rewrite the module using the following command:

a2ensite polr.conf a2enmod rewrite

Finally, restart the Apache service to implement the changes:

systemctl restart apache2

At this point, Polr is installed and configured. You can now proceed to the next step.

Access Polling Web Interface

Now, open your web browser and enter the URL http://polr.example.com. You will be redirected to the Polr setup wizard as follows:

Application settings

Administrator account

reCaptcha settings

Provide your database information, application settings, administrator account settings, and click installation Button. When the installation is complete, you will see the following page:

Polling setup is complete

Click on log in Button. You will be redirected to the Polr login page:

Polling login

Provide your administrator username, password, and click log in Button. You should see the following page:

Poll link shortener

Shorten link

Now click administrator => Dashboard In the upper right corner. You should see the Polling dashboard on the following pages:

Admin console

Let’s Encrypt Free SSL Secure Polling

First, you need to install the Certbot Let’s Encrypt client to download and install the SSL certificate for your domain.

You can use the following command to install:

apt-get install python-certbot-apache -y

After the installation is complete, you can run the following command to install “Let’s Encrypt Certificate” for your domain poll.example.com.

certbot --apache -d polr.example.com

During the installation process, you will be asked to provide an email address and accept the terms of service as follows:

Saving debug log to /var/log/letsencrypt/letsencrypt.log
Plugins selected: Authenticator apache, Installer apache
Enter email address (used for urgent renewal and security notices) (Enter 'c' to
cancel): [email protected]

- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
Please read the Terms of Service at
https://letsencrypt.org/documents/LE-SA-v1.2-November-15-2017.pdf. You must
agree in order to register with the ACME server at
https://acme-v02.api.letsencrypt.org/directory
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
(A)gree/(C)ancel: A

- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
Would you be willing to share your email address with the Electronic Frontier
Foundation, a founding partner of the Let's Encrypt project and the non-profit
organization that develops Certbot? We'd like to send you email about our work
encrypting the web, EFF news, campaigns, and ways to support digital freedom.

- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
(Y)es/(N)o: Y
Obtaining a new certificate
Performing the following challenges:
http-01 challenge for polr.example.com
Enabled Apache rewrite module
Waiting for verification...
Cleaning up challenges
Created an SSL vhost at /etc/apache2/sites-available/polr-le-ssl.conf
Deploying Certificate to VirtualHost /etc/apache2/sites-available/polr-le-ssl.conf
Enabling available site: /etc/apache2/sites-available/polr-le-ssl.conf

Please choose whether or not to redirect HTTP traffic to HTTPS, removing HTTP access.
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
1: No redirect - Make no further changes to the webserver configuration.
2: Redirect - Make all requests redirect to secure HTTPS access. Choose this for
new sites, or if you're confident your site works on HTTPS. You can undo this
change by editing your web server's configuration.
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
Select the appropriate number [1-2] then [enter] (press 'c' to cancel): 2

Next, enter 2 And hit Enter Download and install a free SSL certificate for your domain. Once the installation is successfully completed. You should get the following output:

Enabled Apache rewrite module
Redirecting vhost in /etc/apache2/sites-enabled/polr.conf to ssl vhost in /etc/apache2/sites-available/
polr-le-ssl.conf

- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
Congratulations! You have successfully enabled https://polr.example.com

You should test your configuration at:
https://www.ssllabs.com/ssltest/analyze.html?d=polr.example.com
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -

Your Polr website is now protected with “Let’s Encrypt” free SSL. You can access it using the URL https://polr.example.com.

in conclusion

Congratulations! You have successfully installed Polr on your Debian 10 server and secured it with Let’s Encrypt SSL. You can now host your own link shortener using the Polr web interface. If you have any questions, feel free to ask me.

Source

Sidebar