Ricerca nel sito web

Come installare PhpMyAdmin con Let's Encrypt SSL gratuito su Ubuntu 22.04


Questo tutorial esiste per queste versioni del sistema operativo

  • Ubuntu 22.04 (Jammy Jellyfish)
  • Ubuntu 11.04 (Natty Narwhal)

Su questa pagina

  1. Prerequisiti
  2. Installa Nginx, MariaDB e PHP
  3. Installa phpMyAdmin
  4. Configura database MariaDB
  5. Configura Nginx per phpMyAdmin
  6. Proteggi phpMyAdmin con Let's Encrypt SSL
  7. Accedi a phpMyAdmin
  8. Conclusione

phpMyAdmin è un'applicazione gratuita, open source e basata sul Web utilizzata per la gestione dei database tramite un browser Web. Fornisce un'interfaccia web semplice e intuitiva che aiuta gli amministratori di database a eseguire diverse attività, gestire account utente e privilegi, importare ed esportare dati, eseguire istruzioni SQL e molto altro. È scritto in PHP che offre agli utenti principianti la possibilità di interagire con i loro database MySQL.

In questo tutorial spiegheremo come installare phpMyAdmin con Nginx su Ubuntu 22.04.

Prerequisiti

  • Un server che esegue Ubuntu 22.04.
  • Un nome di dominio valido è indirizzato al tuo server.
  • Una password di root è configurata sul tuo server.

Installa Nginx, MariaDB e PHP

Innanzitutto, dovrai installare il server web Nginx, MariaDB, PHP e altre estensioni PHP richieste nel tuo server. Puoi installarli tutti con il seguente comando:

apt-get install nginx mariadb-server php php-cli php-mysql php-mbstring php-zip php-gd php-json php-curl php-fpm -y

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

Installa phpMyAdmin

Per impostazione predefinita, il pacchetto phpMyAdmin è disponibile nel repository predefinito di Ubuntu 22.04. Puoi installarlo semplicemente eseguendo il seguente comando:

apt-get install phpmyadmin -y

Poiché stiamo utilizzando il server Web Nginx, puoi semplicemente premere TAB e quindi INVIO per ignorare questo prompt. Ti verrà chiesto di configurare un database da utilizzare per phpMyAdmin.

Seleziona Sì e premi Invio per continuare. Ti verrà chiesto di scegliere e confermare una password per l'applicazione phpMyAdmin come mostrato di seguito:

Fornisci la password desiderata e premi Invio per completare l'installazione.

Configura database MariaDB

Per impostazione predefinita, MariaDB non è protetto. Quindi proteggi MariaDB e imposta la password di root di MariaDB con il seguente comando:

mysql_secure_installation

Rispondi a tutte le domande come mostrato di seguito:

Enter current password for root (enter for none): 
Set root password? [Y/n] Y
New password: 
Re-enter new 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] Y

Dopo aver protetto MariaDB, si consiglia di creare un utente separato per connettere phpMyAdmin e gestire il database.

Per fare ciò, accedi alla shell MariaDB con il seguente comando:

mysql -u root -p

Fornisci la tua password di root quando richiesto, quindi crea un nuovo utente con il seguente comando:

MariaDB [(none)]> create user  identified by 'password';

Quindi, concedi tutti i privilegi all'utente con il seguente comando:

MariaDB [(none)]> grant all privileges on *.* to  with grant option;

Quindi, svuota i privilegi ed esci dalla shell MariaDB usando il seguente comando:

MariaDB [(none)]> flush privileges;
MariaDB [(none)]> exit;

Una volta terminato, puoi procedere al passaggio successivo.

Configura Nginx per phpMyAdmin

Successivamente, dovrai creare un blocco del server host virtuale Nginx per ospitare phpMyAdmin. Puoi crearlo usando il seguente comando:

nano /etc/nginx/conf.d/phpmyadmin.conf

Aggiungi le seguenti righe:

server {
  listen 80;
  listen [::]:80;
  server_name phpmyadmin.example.com;
  root /usr/share/phpmyadmin/;
  index index.php index.html index.htm index.nginx-debian.html;

  access_log /var/log/nginx/phpmyadmin_access.log;
  error_log /var/log/nginx/phpmyadmin_error.log;

  location / {
    try_files $uri $uri/ /index.php;
  }

  location ~ ^/(doc|sql|setup)/ {
    deny all;
  }

  location ~ \.php$ {
    fastcgi_pass unix:/run/php/php8.1-fpm.sock;
    fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
    include fastcgi_params;
    include snippets/fastcgi-php.conf;
  }

  location ~ /\.ht {
    deny all;
  }
}

Salva e chiudi il file. Quindi, controlla Nginx per eventuali errori di sintassi con il seguente comando:

nginx -t

Dovresti ottenere il seguente output:

nginx: the configuration file /etc/nginx/nginx.conf syntax is ok
nginx: configuration file /etc/nginx/nginx.conf test is successful

Infine, riavvia il servizio Nginx per applicare le modifiche:

systemctl restart nginx

Puoi anche controllare lo stato di Nginx usando il seguente comando:

systemctl status nginx

Dovresti vedere il seguente output:

? nginx.service - A high performance web server and a reverse proxy server
     Loaded: loaded (/lib/systemd/system/nginx.service; enabled; vendor preset: enabled)
     Active: active (running) since Sun 2022-06-12 04:37:05 UTC; 6s ago
       Docs: man:nginx(8)
    Process: 20020 ExecStartPre=/usr/sbin/nginx -t -q -g daemon on; master_process on; (code=exited, status=0/SUCCESS)
    Process: 20021 ExecStart=/usr/sbin/nginx -g daemon on; master_process on; (code=exited, status=0/SUCCESS)
   Main PID: 20022 (nginx)
      Tasks: 2 (limit: 2292)
     Memory: 2.6M
        CPU: 33ms
     CGroup: /system.slice/nginx.service
             ??20022 "nginx: master process /usr/sbin/nginx -g daemon on; master_process on;"
             ??20023 "nginx: worker process" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" ""

Jun 12 04:37:05 ubuntu systemd[1]: Starting A high performance web server and a reverse proxy server...
Jun 12 04:37:05 ubuntu systemd[1]: Started A high performance web server and a reverse proxy server.

Successivamente, modifica la proprietà e l'autorizzazione della directory phpMyAdmin:

chown -R www-data:www-data /usr/share/phpmyadmin/
chmod -R 755

Proteggi phpMyAdmin con Let's Encrypt SSL

Prima di iniziare, dovrai installare il client Certbot per scaricare e installare Let's Encrypt SSL.

Innanzitutto, aggiungi il repository Certbot con il seguente comando:

add-apt-repository ppa:ahasenack/certbot-tlssni01-1875471

Successivamente, aggiorna il repository e installa il client Certbot utilizzando il seguente comando:

apt-get update -y
apt-get install certbot python3-certbot-nginx -y

Una volta installato Certbot, esegui il seguente comando per scaricare e installare Let's Encrypt SSL per il tuo dominio:

certbot --nginx -d phpmyadmin.example.com

Ti verrà chiesto di fornire la tua email e di accettare i termini di servizio come mostrato di seguito:

Saving debug log to /var/log/letsencrypt/letsencrypt.log
Plugins selected: Authenticator nginx, Installer nginx
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 phpmyadmin.example.com
Waiting for verification...
Cleaning up challenges
Deploying Certificate to VirtualHost /etc/nginx/sites-enabled/phpmyadmin

Successivamente, seleziona se reindirizzare o meno il traffico HTTP su HTTPS:

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

Digita 2 e premi Invio per completare l'installazione.

Redirecting all traffic on port 80 to ssl in /etc/nginx/sites-enabled/phpmyadmin

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

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

IMPORTANT NOTES:
 - Congratulations! Your certificate and chain have been saved at:
   /etc/letsencrypt/live/phpmyadmin.example.com/fullchain.pem
   Your key file has been saved at:
   /etc/letsencrypt/live/phpmyadmin.example.com/privkey.pem
   Your cert will expire on 2022-09-12. To obtain a new or tweaked
   version of this certificate in the future, simply run certbot again
   with the "certonly" option. To non-interactively renew *all* of
   your certificates, run "certbot renew"
 - If you like Certbot, please consider supporting our work by:

   Donating to ISRG / Let's Encrypt:   https://letsencrypt.org/donate
   Donating to EFF:                    https://eff.org/donate-le

Accedi a phpMyAdmin

Ora apri il tuo browser web e digita l'URL https://phpmyadmin.eample.com. Verrai reindirizzato alla pagina di accesso di phpMyAdmin:

Fornisci il nome utente e la password dell'amministratore e fai clic sul pulsante Vai. Dovresti vedere la dashboard predefinita di phpMyAdmin nella pagina seguente:

Conclusione

Congratulazioni! hai installato correttamente phpMyAdmin e lo hai protetto con Let's Encrypt SSL su Ubuntu 22.04. Ora puoi connetterti a phpMyAdmin, gestire i tuoi database ed eseguire diverse attività tramite il browser web.