phpMyAdmin Installation und sicherer Zugriff
Schritt-fur-Schritt phpMyAdmin Installation auf Apache und Nginx, SSL-Konfiguration, Benutzerverwaltung, IP-Einschraenkungen und Sicherheitshaertung.
Inhaltsverzeichnis
phpMyAdmin Installation und sicherer Zugriff
phpMyAdmin ist eine Open-Source-PHP-Anwendung zur Verwaltung von MySQL- und MariaDB-Datenbanken uber einen Webbrowser. Sie konnen Datenbanken erstellen, Tabellen verwalten, SQL-Abfragen ausfuhren und Benutzerberechtigungen uber die grafische Oberflache verwalten. Diese Anleitung behandelt Installation, Apache- und Nginx-Konfiguration, SSL-Einrichtung und Sicherheitshaertung.
Voraussetzungen
Vor der Installation von phpMyAdmin muss Folgendes bereitstehen:
- Ubuntu 20.04/22.04 oder Debian 11/12
- MySQL 8.0+ oder MariaDB 10.5+
- PHP 7.4+ (empfohlen: PHP 8.1+)
- Apache 2.4+ oder Nginx 1.18+
# Systemaktualisierung
apt update && apt upgrade -y
# PHP und erforderliche Module
apt install -y php php-mysql php-mbstring php-zip php-gd php-json php-curl
# PHP-Version pruefen
php -v
phpMyAdmin installieren
Installation uber den Paketmanager
# phpMyAdmin installieren
apt install -y phpmyadmin
Wahrend der Installation:
- Webserver-Auswahl:
apache2oderlighttpd(bei Nginx nichts auswaehlen) - Datenbank mit
dbconfig-commonkonfigurieren:Yes - Passwort fur phpMyAdmin festlegen
Manuelle Installation (Empfohlen)
Die manuelle Installation bietet die neueste Version und mehr Kontrolle:
# Neueste Version herunterladen
cd /tmp
wget https://www.phpmyadmin.net/downloads/phpMyAdmin-latest-all-languages.tar.gz
# Archiv entpacken
tar xzf phpMyAdmin-latest-all-languages.tar.gz
# In Web-Verzeichnis verschieben
mv phpMyAdmin-*-all-languages /var/www/html/phpmyadmin
# Eigentuemer setzen
chown -R www-data:www-data /var/www/html/phpmyadmin
chmod -R 755 /var/www/html/phpmyadmin
# Konfigurationsdatei erstellen
cp /var/www/html/phpmyadmin/config.sample.inc.php /var/www/html/phpmyadmin/config.inc.php
Blowfish-Secret generieren
# Zufaelligen 32-Zeichen-Schluessel generieren
openssl rand -base64 32
# config.inc.php bearbeiten
nano /var/www/html/phpmyadmin/config.inc.php
// Generierten Schluessel hier einfuegen
$cfg['blowfish_secret'] = 'ZUFAELLIGEN_SCHLUESSEL_HIER_EINFUEGEN';
// Temp-Verzeichnis setzen
$cfg['TempDir'] = '/tmp/phpmyadmin';
# Temp-Verzeichnis erstellen
mkdir -p /tmp/phpmyadmin
chown www-data:www-data /tmp/phpmyadmin
Apache-Konfiguration
Virtual Host erstellen
nano /etc/apache2/sites-available/phpmyadmin.conf
<VirtualHost *:80>
ServerName pma.example.com
DocumentRoot /var/www/html/phpmyadmin
<Directory /var/www/html/phpmyadmin>
Options FollowSymLinks
DirectoryIndex index.php
AllowOverride All
Require all granted
</Directory>
ErrorLog ${APACHE_LOG_DIR}/phpmyadmin_error.log
CustomLog ${APACHE_LOG_DIR}/phpmyadmin_access.log combined
</VirtualHost>
# Site aktivieren
a2ensite phpmyadmin.conf
a2enmod rewrite
systemctl reload apache2
HTTP-Basic-Auth-Schutz
# .htpasswd-Datei erstellen
htpasswd -c /etc/apache2/.htpasswd admin
<Directory /var/www/html/phpmyadmin>
AuthType Basic
AuthName 'phpMyAdmin Access'
AuthUserFile /etc/apache2/.htpasswd
Require valid-user
</Directory>
Nginx-Konfiguration
nano /etc/nginx/sites-available/phpmyadmin
server {
listen 80;
server_name pma.example.com;
root /var/www/html/phpmyadmin;
index index.php;
# HTTP-Auth-Schutz
auth_basic 'phpMyAdmin Access';
auth_basic_user_file /etc/nginx/.htpasswd;
location / {
try_files $uri $uri/ =404;
}
location ~ \.php$ {
include snippets/fastcgi-php.conf;
fastcgi_pass unix:/var/run/php/php8.1-fpm.sock;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
include fastcgi_params;
}
location ~ /\.ht {
deny all;
}
# Sensible Verzeichnisse verbergen
location ~* /(libraries|setup/frames|setup/libs) {
deny all;
return 404;
}
}
# htpasswd fuer Nginx erstellen
apt install -y apache2-utils
htpasswd -c /etc/nginx/.htpasswd admin
# Site aktivieren
ln -s /etc/nginx/sites-available/phpmyadmin /etc/nginx/sites-enabled/
nginx -t
systemctl reload nginx
SSL-Konfiguration
Kostenloses SSL mit Let's Encrypt
# Certbot installieren
apt install -y certbot python3-certbot-apache
# oder fuer Nginx:
apt install -y certbot python3-certbot-nginx
# SSL-Zertifikat fuer Apache erhalten
certbot --apache -d pma.example.com
# SSL-Zertifikat fuer Nginx erhalten
certbot --nginx -d pma.example.com
# Automatische Erneuerung testen
certbot renew --dry-run
Manuelle SSL-Konfiguration (Nginx)
server {
listen 443 ssl http2;
server_name pma.example.com;
root /var/www/html/phpmyadmin;
index index.php;
ssl_certificate /etc/letsencrypt/live/pma.example.com/fullchain.pem;
ssl_certificate_key /etc/letsencrypt/live/pma.example.com/privkey.pem;
ssl_protocols TLSv1.2 TLSv1.3;
ssl_ciphers HIGH:!aNULL:!MD5;
ssl_prefer_server_ciphers on;
# HSTS
add_header Strict-Transport-Security 'max-age=31536000; includeSubDomains' always;
auth_basic 'phpMyAdmin Access';
auth_basic_user_file /etc/nginx/.htpasswd;
location ~ \.php$ {
include snippets/fastcgi-php.conf;
fastcgi_pass unix:/var/run/php/php8.1-fpm.sock;
}
}
# HTTP zu HTTPS umleiten
server {
listen 80;
server_name pma.example.com;
return 301 https://$host$request_uri;
}
Benutzerverwaltung
Dedizierten phpMyAdmin-Benutzer erstellen
-- Mit MySQL/MariaDB verbinden
mysql -u root -p
-- Admin-Benutzer fuer phpMyAdmin erstellen
CREATE USER 'pma_admin'@'localhost' IDENTIFIED BY 'StarkesPasswort123!';
GRANT ALL PRIVILEGES ON *.* TO 'pma_admin'@'localhost' WITH GRANT OPTION;
-- Eingeschraenkten App-Benutzer erstellen
CREATE USER 'app_user'@'localhost' IDENTIFIED BY 'AppPasswort456!';
GRANT ALL PRIVILEGES ON myapp.* TO 'app_user'@'localhost';
FLUSH PRIVILEGES;
Benutzer in config.inc.php einschraenken
// Nur bestimmte Benutzer zulassen
$cfg['Servers'][$i]['AllowDeny']['order'] = 'deny,allow';
$cfg['Servers'][$i]['AllowDeny']['rules'] = [
'deny % from all',
'allow pma_admin from localhost',
'allow app_user from 192.168.1.0/24',
];
// Root-Login blockieren
$cfg['Servers'][$i]['AllowRoot'] = false;
Sicherheitshaertung
IP-Einschraenkung
# Nginx - nur bestimmte IPs zulassen
location / {
allow 192.168.1.0/24;
allow 10.0.0.5;
deny all;
}
# Apache - IP-Einschraenkung
<Directory /var/www/html/phpmyadmin>
Require ip 192.168.1.0/24
Require ip 10.0.0.5
</Directory>
Standard-URL aendern
# phpmyadmin-Verzeichnis umbenennen
mv /var/www/html/phpmyadmin /var/www/html/db_manager_x7k2
# Nginx/Apache-Konfiguration entsprechend aktualisieren
Sitzungssicherheit
// config.inc.php - Sicherheitseinstellungen
$cfg['LoginCookieValidity'] = 1800; // 30 Minuten Sitzungs-Timeout
$cfg['LoginCookieStore'] = 0; // Sitzung beim Schliessen des Browsers loeschen
$cfg['ForceSSL'] = true; // SSL erzwingen
$cfg['Servers'][$i]['ssl'] = true; // MySQL-SSL-Verbindung
$cfg['SendErrorReports'] = 'never';
Setup-Verzeichnis entfernen
# Setup-Verzeichnis nach der Installation entfernen
rm -rf /var/www/html/phpmyadmin/setup
Fail2Ban Brute-Force-Schutz
nano /etc/fail2ban/filter.d/phpmyadmin.conf
[Definition]
failregex = ^<HOST> .* 'POST /phpmyadmin/index.php.*' (401|403)
ignoreregex =
# /etc/fail2ban/jail.local
[phpmyadmin]
enabled = true
port = http,https
filter = phpmyadmin
logpath = /var/log/nginx/phpmyadmin_access.log
maxretry = 5
bantime = 3600
Fehlerbehebung
# PHP-Fehlerprotokolle pruefen
tail -f /var/log/php8.1-fpm.log
# Nginx-Fehlerprotokolle
tail -f /var/log/nginx/error.log
# Apache-Fehlerprotokolle
tail -f /var/log/apache2/phpmyadmin_error.log
# phpMyAdmin-Berechtigungen pruefen
ls -la /var/www/html/phpmyadmin/
# PHP-Module pruefen
php -m | grep -E 'mysql|mbstring|zip'
Fazit
phpMyAdmin ist ein leistungsstarkes Datenbankverwaltungstool, birgt aber ohne ordnungsgemaesse Sicherheitskonfiguration erhebliche Risiken. Verwenden Sie immer SSL, fuegen Sie HTTP-Authentifizierung hinzu, schraenken Sie den Zugriff nach IP ein und aendern Sie die Standard-URL. Mit diesen Massnahmen kann phpMyAdmin sicher auf REXE-Servern eingesetzt werden.
Verwandte Artikel
MySQL und MariaDB Installation: Grundlegende Verwaltung
Schritt-für-Schritt MySQL und MariaDB Installation unter Linux, mysql_secure_installation, Datenbanken und Benutzer erstellen, SQL-Grundbefehle, Remote-Zugriff und Performance-Tuning.
PostgreSQL Installation und Grundlegende Verwaltung
PostgreSQL-Installation auf Ubuntu/Debian und RHEL/CentOS, Benutzer und Datenbanken erstellen, grundlegende SQL-Befehle, Remote-Verbindung konfigurieren und Backup-Strategien. Schritt-fur-Schritt-Anleitung.
Redis und Memcached Installation: Cache-Schicht Leitfaden
Redis und Memcached Installation auf Ubuntu/Debian, Grundbefehle, Persistenz-Einstellungen, TTL-Konfiguration, Redis vs Memcached Vergleich und Anwendungsintegration.