Polr è un abbreviatore 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 abbreviatore di URL, personalizzare i tuoi URL e ottenere il controllo sui tuoi dati. Fornisce un sacco di funzionalità tra cui API robuste, inoltro URL, permessi di personalizzazione, temi e altro ancora.
In questo post, ti mostreremo come installare Polr con Apache e Let's Encrypt SSL su Ubuntu 20.04.
Prerequisiti
- Un server che esegue Ubuntu 20.04.
- Un nome di dominio valido puntato all'IP del tuo server.
- Sul server è configurata una password di root.
Per iniziare
Innanzitutto, aggiorna i pacchetti di sistema alla versione aggiornata eseguendo il comando seguente:
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';
Quindi, svuota i privilegi ed esci da MariaDB con il seguente comando:
MariaDB [(none)]> FLUSH PRIVILEGES;
MariaDB [(none)]> EXIT;
Una volta terminato, puoi procedere al passaggio successivo.
Installa Composer
Successivamente, dovrai installare Composer nel tuo server per installare le dipendenze PHP richieste per Polr.
Esegui il comando seguente 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
Quindi, sposta il binario Composer nella posizione di sistema utilizzando il comando seguente:
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 Polr
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
Quindi, 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 [email protected] 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
Quindi, riavvia il servizio Apache per applicare le modifiche:
systemctl restart apache2
È ora possibile 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 ubuntu2004 systemd[1]: Starting The Apache HTTP Server...
Accedi all'interfaccia web di Polr
Ora puoi accedere all'interfaccia web di Polr utilizzando l'URL http://polr.example.com.
Fornisci 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 fai clic su Installa pulsante. Una volta installato Polr, dovresti visualizzare la seguente schermata:
Clicca sulla home page. Dovresti vedere la dashboard di Polr nella schermata seguente:
Secure Polr con Let's Encrypt Free SSL
Innanzitutto, dovrai installare il client Certbot Let's 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 comando seguente per installare il certificato Let's 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 e-mail e di accettare i termini del 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): [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
Quindi, 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 Let's Encrypt SSL gratuito. Puoi accedervi utilizzando l'URL https://polr.example.com.
Conclusione
Nella guida sopra, hai imparato come installare Polr con Apache e Let's Encrypt SSL sul server Ubuntu 20.04. Ora puoi ospitare il tuo abbreviatore di link usando Polr. Sentiti libero di chiedermi se hai domande.