Ricerca nel sito web

Come installare Polr URL Shortener su Ubuntu 20.04


Su questa pagina

  1. Prerequisiti
  2. Per iniziare
  3. Installa Apache, MariaDB e PHP
  4. Crea un database per Polr
  5. Installa Compositore
  6. Installa Polr
  7. Configura Apache per Polr
  8. Accedi all'interfaccia Web Polr
  9. Secure Polr con Lets Encrypt SSL gratuito
  10. Conclusione

Polr è un accorciatore di URL gratuito e open source scritto in PHP. Fornisce un'interfaccia semplice e intuitiva per creare e gestire i collegamenti. Puoi ospitare il tuo accorciatore di URL, contrassegnare i tuoi URL e ottenere il controllo sui tuoi dati. Fornisce un sacco di funzionalità tra cui API robuste, inoltro URL, personalizzazione delle autorizzazioni, temi e altro ancora.

In questo post, ti mostreremo come installare Polr con Apache e Lets Encrypt SSL su Ubuntu 20.04.

Prerequisiti

  • Un server che esegue Ubuntu 20.04.
  • Un nome di dominio valido indicato con l'IP del tuo server.
  • Sul server è configurata una password di root.

Iniziare

Innanzitutto, aggiorna i pacchetti di sistema alla versione aggiornata eseguendo il seguente comando:

apt-get update -y

Una volta aggiornati tutti i pacchetti, puoi procedere al passaggio successivo.

Installa Apache, MariaDB e PHP

Innanzitutto, dovrai installare il server Apache, il database MariaDB, PHP e altre estensioni PHP sul tuo server. Puoi installarli tutti con il seguente comando:

apt-get install apache2 mariadb-server php libapache2-mod-php libapache2-mod-wsgi php-gd php-curl php-xml php-xmlrpc php-curl php-imagick php-mbstring php-zip php-intl -y

Una volta installati tutti i pacchetti, puoi procedere al passaggio successivo.

Crea un database per Polr

Polr utilizza MariaDB/MySQL come database back-end. Quindi dovrai creare un database e un utente per Polr.

Innanzitutto, accedi a MariaDB con il seguente comando:

mysql

Una volta effettuato l'accesso, creare un database e un utente con il seguente comando:

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

Successivamente, scarica i privilegi ed esci da MariaDB con il seguente comando:

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

Al termine, puoi procedere al passaggio successivo.

Installa Compositore

Successivamente, dovrai installare Composer nel tuo server per installare le dipendenze PHP richieste per Polr.

Eseguire il seguente comando per installare Composer:

curl -sS https://getcomposer.org/installer | php

Dovresti ottenere il seguente output:

All settings correct for using Composer
Downloading...

Composer (version 2.1.3) successfully installed to: /root/composer.phar
Use it: php composer.phar

Successivamente, sposta il file binario di Composer nella posizione di sistema utilizzando il seguente comando:

mv composer.phar /usr/local/bin/composer

Successivamente, verifica la versione di Composer utilizzando il seguente comando:

composer -V

Dovresti vedere il seguente output:

Do not run Composer as root/super user! See https://getcomposer.org/root for details
Continue as root/super user [yes]? yes
Composer version 2.1.3 2021-06-09 16:31:20

Installa Pol

Successivamente, dovrai scaricare l'ultima versione di Polr dal repository Git. Puoi scaricarlo con il seguente comando:

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

Una volta completato il download, cambia la directory in Polr e installa tutte le dipendenze richieste con il seguente comando:

cd /var/www/html/polr
composer install --no-dev -o

Successivamente, copia il file dell'ambiente di esempio con il seguente comando:

cp .env.setup .env

Quindi, imposta l'autorizzazione corretta per la directory Polr con il seguente comando:

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

Una volta terminato, puoi procedere al passaggio successivo.

Configura Apache per Polr

Successivamente, dovrai creare un file di configurazione dell'host virtuale Apache per Polr. Puoi crearlo con il seguente comando:

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

Aggiungi le seguenti righe:

<VirtualHost *:80>
ServerAdmin 
DocumentRoot /var/www/html/polr/public
ServerName polr.example.com
<Directory /var/www/html/polr/public/>
Options FollowSymLinks
AllowOverride All
Order allow,deny
allow from all
</Directory>
ErrorLog /var/log/apache2/polr-error_log
CustomLog /var/log/apache2/polr-access_log common
</VirtualHost>

Salva e chiudi il file, quindi abilita il file dell'host virtuale Apache e riscrivi il modulo con il seguente comando:

a2enmod rewrite
a2ensite polr.conf

Successivamente, riavvia il servizio Apache per applicare le modifiche:

systemctl restart apache2

Ora puoi verificare lo stato del servizio Apache utilizzando il seguente comando:

systemctl status apache2

Dovresti ottenere il seguente output:

? apache2.service - The Apache HTTP Server
     Loaded: loaded (/lib/systemd/system/apache2.service; enabled; vendor preset: enabled)
     Active: active (running) since Thu 2021-06-17 12:09:42 UTC; 16s ago
       Docs: https://httpd.apache.org/docs/2.4/
    Process: 27602 ExecStart=/usr/sbin/apachectl start (code=exited, status=0/SUCCESS)
   Main PID: 27617 (apache2)
      Tasks: 6 (limit: 2353)
     Memory: 26.6M
     CGroup: /system.slice/apache2.service
             ??27617 /usr/sbin/apache2 -k start
             ??27618 /usr/sbin/apache2 -k start
             ??27619 /usr/sbin/apache2 -k start
             ??27620 /usr/sbin/apache2 -k start
             ??27621 /usr/sbin/apache2 -k start
             ??27622 /usr/sbin/apache2 -k start

Jun 17 12:09:42 ubunt4 systemd[1]: Starting The Apache HTTP Server...

Accedi all'interfaccia Web di Polr

È ora possibile accedere all'interfaccia web di Polr utilizzando l'URL http://polr.example.com.

Fornire il nome del database, il nome utente, la password, le impostazioni dell'applicazione, l'URL Polr, il nome utente dell'amministratore, l'e-mail, la password e fare clic sul pulsante Installa. Una volta installato Polr, dovresti ottenere la seguente schermata:

Fare clic sulla pagina iniziale. Dovresti vedere la dashboard di Polr nella schermata seguente:

Proteggi Polr con Lets Encrypt SSL gratuito

Innanzitutto, dovrai installare il client Certbot Lets Encrypt per scaricare e installare il certificato SSL per il tuo dominio.

Puoi installarlo con il seguente comando:

apt-get install python3-certbot-apache -y

Una volta installato, puoi eseguire il seguente comando per installare il certificato Lets Encrypt per il tuo dominio polr.example.com.

certbot --apache -d polr.example.com

Durante l'installazione, ti verrà chiesto di fornire il tuo indirizzo email e di accettare i termini di servizio come mostrato di seguito:

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): 

- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
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

Successivamente, digita 2 e premi Invio per scaricare e installare un certificato SSL gratuito per il tuo dominio. Una volta che l'installazione è stata completata con successo. Dovresti ottenere il seguente 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
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -

Il tuo sito Web Polr è ora protetto con Lets Encrypt SSL gratuito. Puoi accedervi utilizzando l'URL https://polr.example.com.

Conclusione

Nella guida sopra, hai imparato come installare Polr con Apache e Lets Encrypt SSL sul server Ubuntu 20.04. Ora puoi ospitare il tuo abbreviatore di link utilizzando Polr. Non esitate a chiedermi se avete domande.