How to Install Polr on Ubuntu 20.04 with LAMP
Tags: polr, ubuntu, linux, hostnextra
Published: 2021-05-17 17:29:14

In this article, we'll explain how to install Polr on Ubuntu 20.04 with LAMP.

<a href="https://polrproject.org/" target="_blank" rel="noopener">Polr</a> 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.
<h4>Prerequisites</h4>
<ul>
 	<li>An Ubuntu 20.04 installed <a href="https://www.hostnextra.com/dedicated-server.html" target="_blank" rel="noopener">dedicated server</a> or <a href="https://www.hostnextra.com/vps-hosting.html" target="_blank" rel="noopener">KVM VPS</a>.</li>
 	<li>A root user access or normal user with administrative privileges.</li>
</ul>
<a href="https://www.hostnextra.com/kb/how-to-install-polr-on-ubuntu-with-lamp/">Install Polr on Ubuntu 20.04 with LAMP</a>
<h4>1. Keep the server updated</h4>
Update the package repository index, and upgrade the installed packages.
<blockquote># apt update &amp;&amp; sudo apt -y upgrade</blockquote>
<h4>2. Install Apache webserver</h4>
<blockquote># apt install apache2 -y</blockquote>
In case, you enabled firewall and firewall block requests of the apache web server, open a port in the firewall.
<blockquote># ufw allow 80/tcp

# ufw allow 443/tcp

# ufw reload</blockquote>
Start and enable apache2 service.
<blockquote># systemctl start apache2 &amp;&amp; systemctl enable apache2</blockquote>
<h4>3. Enable Apache mod_rewrite feature.</h4>
Enable the Apache mod_rewrite module. Polr requires it to craft user-friendly URLs.
<blockquote># a2enmod rewrite</blockquote>
Restart the Apache web server to load the new modules and extensions.
<blockquote># systemctl restart apache2</blockquote>
<h4>4. Install PHP</h4>
Here we are installing the default PHP version 7.4 and other modules for web deployments using the following command:
<blockquote># apt install php php-pdo php-mysql php-mbstring php-tokenizer php-json php-curl -y</blockquote>
<h4>5. Install PHP Composer</h4>
Download using <em>curl</em> and run the <em>Composer</em> installer.
<blockquote># curl -sS https://getcomposer.org/installer | php</blockquote>
To use Composer globally composer.phar to /usr/local/bin/ using following command.
<blockquote># mv -f composer.phar /usr/local/bin/composer</blockquote>
Verify the Composer is working using following command:
<blockquote># composer -V</blockquote>
The PHP Composer tool is now in place, but before installing Polr, you'll create a database and a user account next.
<h4>6. Install MariaDB</h4>
<blockquote># apt install mariadb-server mariadb-client -y</blockquote>
The default configuration of the MariaDB will not be secured. Let's secured the installation using the following command:
<blockquote># mysql_secure_installation</blockquote>
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:
<blockquote>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</blockquote>
Login in to mysql
<blockquote># mysql -u root -p</blockquote>
Now, create Polr database and user
<blockquote>CREATE DATABASE polr;

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

EXIT;</blockquote>
<h4>7. Install Polr</h4>
Create a separate sub-directory for your Polr site under the Apache root directory <em>/var/www</em>.
<blockquote># mkdir -p /var/www/example.com</blockquote>
Next, use git to clone the Polr installation package from GitHub.
<blockquote># git clone https://github.com/cydrobolt/polr.git --depth=1 /var/www/example.com</blockquote>
Use Linux cd command to navigate to the /var/www/example.com directory.
<blockquote># cd /var/www/example.com</blockquote>
Then, run the composer command below to install Polr.
<blockquote># composer install --no-dev -o</blockquote>
Create a new configuration file by copying the default .env.setup file that ships with Polr to .env.
<blockquote># cp .env.setup .env</blockquote>
Assign the appropriate ownership and permissions to the Polr files and directories.
<blockquote># chown -R www-data:www-data /var/www/example.com/
# chmod -R 755 /var/www/example.com/</blockquote>
Your package is now installed. But before you run it, create a virtual host configuration file for your Polr application.
<h4>8. Create a Virtual Host File</h4>
create a new virtual host file for your Polr site under the <em>/etc/apache2/sites-available/</em> directory.
<blockquote># nano /etc/apache2/sites-available/example.com.conf</blockquote>
Then, add the information below into the file. Replace example.com with the correct domain name or public IP address of your server.
<blockquote>&lt;VirtualHost *:80&gt;
ServerName [server IP] or example.com
ServerAlias example.com
DocumentRoot "/var/www/example.com/public"
&lt;Directory "/var/www/example.com/public"&gt;
Require all granted
Options Indexes FollowSymLinks
AllowOverride All
Order allow,deny
Allow from all
&lt;/Directory&gt;
ErrorLog ${APACHE_LOG_DIR}/error.log
CustomLog ${APACHE_LOG_DIR}/access.log combined
&lt;/VirtualHost&gt;</blockquote>
Save and close the file. Then, enable the configuration file you've just created using the a2ensite command.
<blockquote># a2ensite example.com.conf</blockquote>
Then, restart the Apache webserver to load the new settings.
<blockquote># systemctl restart apache2</blockquote>
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 <em>http://example.com/setup</em> or <em>server IP</em>.

You should see a web page for finalizing the setup, as shown below.

<img class="alignnone size-large wp-image-2242" src="https://www.hostnextra.com/kb/wp-content/uploads/2021/05/install-polr-on-ubuntu-1024x514.png" alt="install polr on ubuntu" width="700" height="351" />

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.
<blockquote># php artisan migrate</blockquote>
In this article, we have explain how to install Polr on Ubuntu 20.04 with LAMP.