So installierst du PhpMyAdmin mit kostenlosem Let’s Encrypt SSL unter Ubuntu 22.04

phpMyAdmin ist eine kostenlose, quelloffene und webbasierte Anwendung, mit der du Datenbanken über einen Webbrowser verwalten kannst. Sie bietet eine einfache und benutzerfreundliche Weboberfläche, mit der Datenbankadministratoren verschiedene Aufgaben durchführen, Benutzerkonten und Berechtigungen verwalten, Daten importieren und exportieren, SQL-Anweisungen ausführen und vieles mehr. Sie ist in PHP geschrieben und ermöglicht es auch Anfängern, mit ihren MySQL-Datenbanken zu interagieren.

In diesem Tutorium erklären wir, wie du phpMyAdmin mit Nginx auf Ubuntu 22.04 installierst.

Voraussetzungen

  • Ein Server, auf dem Ubuntu 22.04 läuft.
  • Ein gültiger Domainname ist auf deinem Server angegeben.
  • Ein Root-Passwort ist auf deinem Server eingerichtet.

Installiere Nginx, MariaDB und PHP

Zuerst musst du den Nginx Webserver, MariaDB, PHP und andere benötigte PHP-Erweiterungen auf deinem Server installieren. Du kannst sie alle mit dem folgenden Befehl installieren:

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

Sobald alle Pakete installiert sind, kannst du mit dem nächsten Schritt fortfahren.

phpMyAdmin installieren

Standardmäßig ist das phpMyAdmin-Paket im Standard-Repository von Ubuntu 22.04 verfügbar. Du kannst es installieren, indem du einfach den folgenden Befehl ausführst:

apt-get install phpmyadmin -y

Während der Installation wirst du aufgefordert, den Webserver auszuwählen (siehe unten):

PHPMyAdmin installieren

Da wir den Nginx-Webserver verwenden, kannst du einfach TAB und dann ENTER drücken, um diese Aufforderung zu umgehen. Du wirst aufgefordert, eine Datenbank zu konfigurieren, die phpMyAdmin verwenden soll.

configure PHPMyAdmin

Wähle Ja und drücke Enter, um fortzufahren. Du wirst aufgefordert, ein Passwort für die phpMyAdmin Anwendung zu wählen und zu bestätigen (siehe unten):

MySQL-Anwendungspasswort

Gib das gewünschte Passwort ein und drücke die Eingabetaste, um die Installation abzuschließen.

MariaDB-Datenbank konfigurieren

Standardmäßig ist die MariaDB nicht gesichert. Daher musst du die MariaDB sichern und das MariaDB Root-Passwort mit dem folgenden Befehl festlegen:

mysql_secure_installation

Beantworte alle Fragen wie unten gezeigt:

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

Nachdem du die MariaDB gesichert hast, solltest du einen eigenen Benutzer anlegen, um dich mit phpMyAdmin zu verbinden und die Datenbank zu verwalten.

Melde dich dazu mit folgendem Befehl in der MariaDB-Shell an:

mysql -u root -p

Gib dein Root-Passwort ein, wenn du dazu aufgefordert wirst, und erstelle dann einen neuen Benutzer mit dem folgenden Befehl:

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

Als Nächstes erteilst du dem Benutzer mit folgendem Befehl alle Berechtigungen:

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

Lösche die Berechtigungen und verlasse die MariaDB-Shell mit folgendem Befehl:

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

Wenn du damit fertig bist, kannst du mit dem nächsten Schritt fortfahren.

Nginx für phpMyAdmin konfigurieren

Als Nächstes musst du einen virtuellen Nginx-Host-Serverblock erstellen, um phpMyAdmin zu hosten. Du kannst ihn mit dem folgenden Befehl erstellen:

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

Füge die folgenden Zeilen ein:

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

Speichere und schließe die Datei. Überprüfe dann Nginx mit folgendem Befehl auf Syntaxfehler:

nginx -t

Du solltest die folgende Ausgabe erhalten:

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

Starte abschließend den Nginx-Dienst neu, um die Änderungen zu übernehmen:

systemctl restart nginx

Du kannst den Nginx-Status auch mit dem folgenden Befehl überprüfen:

systemctl status nginx

Du solltest die folgende Ausgabe sehen:

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

Als Nächstes änderst du die Eigentümerschaft und die Berechtigung für das phpMyAdmin-Verzeichnis:

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

phpMyAdmin mit Let’s Encrypt SSL sichern

Bevor du beginnst, musst du den Certbot-Client installieren, um Let’s Encrypt SSL herunterzuladen und zu installieren.

Füge zunächst das Certbot-Repository mit dem folgenden Befehl hinzu:

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

Als Nächstes aktualisierst du das Repository und installierst den Certbot-Client mit dem folgenden Befehl:

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

Sobald Certbot installiert ist, führe den folgenden Befehl aus, um Let’s Encrypt SSL für deine Domain herunterzuladen und zu installieren:

certbot --nginx -d phpmyadmin.example.com

Du wirst aufgefordert, deine E-Mail-Adresse anzugeben und die Nutzungsbedingungen zu akzeptieren (siehe unten):

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): hitjethva@gmail.com

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

Als Nächstes wählst du aus, ob der HTTP-Datenverkehr auf HTTPS umgeleitet werden soll oder nicht:

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

Gib 2 ein und drücke Enter, um die Installation abzuschließen.

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

Zugriff auf phpMyAdmin

Öffne nun deinen Webbrowser und gib die URL https://phpmyadmin.eample.com ein. Du wirst auf die phpMyAdmin Anmeldeseite weitergeleitet:

PHPMyAdmin Login

Gib deinen Admin-Benutzernamen und dein Passwort ein und klicke auf die Schaltfläche “ Go“. Auf der folgenden Seite solltest du das Standard-Dashboard von phpMyAdmin sehen:

PHPMyAdmin Web Interface

Fazit

Glückwunsch! Du hast phpMyAdmin erfolgreich installiert und mit Let’s Encrypt SSL auf Ubuntu 22.04 gesichert. Du kannst dich jetzt mit phpMyAdmin verbinden, deine Datenbanken verwalten und verschiedene Aufgaben über den Webbrowser erledigen.

Das könnte dich auch interessieren …