phpMyAdmin ist eine beliebte Web-Oberfläche zur Verwaltung von MySQL und MariaDB. Datenbanken, Tabellen und Benutzer lassen sich bequem im Browser verwalten.
Voraussetzungen
- Webserver (Apache oder Nginx)
- PHP 7.4+ (8.x empfohlen)
- MySQL oder MariaDB
Installation unter Ubuntu/Debian
Mit apt
apt update
apt install phpmyadminWährend der Installation: 1. Webserver wählen (apache2 oder manuell für Nginx) 2. dbconfig-common mit Ja bestätigen 3. Passwort für phpMyAdmin-Benutzer festlegen
Apache automatisch konfiguriert
Bei Apache-Auswahl ist phpMyAdmin sofort unter:
http://server-ip/phpmyadminInstallation mit Nginx
PHP-FPM installieren (falls nicht vorhanden)
apt install php-fpm php-mysql php-mbstring php-zip php-gdphpMyAdmin herunterladen
cd /usr/share
wget https://files.phpmyadmin.net/phpMyAdmin/5.2.1/phpMyAdmin-5.2.1-all-languages.tar.gz
tar -xzf phpMyAdmin-5.2.1-all-languages.tar.gz
mv phpMyAdmin-5.2.1-all-languages phpmyadmin
rm phpMyAdmin-5.2.1-all-languages.tar.gzKonfiguration kopieren
cp /usr/share/phpmyadmin/config.sample.inc.php /usr/share/phpmyadmin/config.inc.phpBlowfish Secret setzen
Bearbeiten Sie /usr/share/phpmyadmin/config.inc.php:
$cfg['blowfish_secret'] = 'ZUFAELLIGE_32_ZEICHEN_HIER';Generieren:
openssl rand -base64 32tmp-Verzeichnis erstellen
mkdir /usr/share/phpmyadmin/tmp
chown www-data:www-data /usr/share/phpmyadmin/tmp
chmod 755 /usr/share/phpmyadmin/tmpNginx-Konfiguration
server {
listen 80;
server_name pma.example.com;
root /usr/share/phpmyadmin;
index index.php;
location / {
try_files $uri $uri/ /index.php?$args;
}
location ~ \.php$ {
fastcgi_pass unix:/run/php/php8.2-fpm.sock;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
include fastcgi_params;
}
location ~ /\.ht {
deny all;
}
}nginx -t
systemctl reload nginxErster Login
URL aufrufen
http://server-ip/phpmyadminAnmeldung
- Benutzer: root (oder anderer MySQL-User)
- Passwort: MySQL-Passwort
Absicherung
1. Über HTTPS zugreifen
certbot --nginx -d pma.example.com2. Zugriff einschränken (IP-basiert)
In Nginx:
location / {
allow 192.168.1.0/24;
allow 203.0.113.50;
deny all;
try_files $uri $uri/ /index.php?$args;
}In Apache .htaccess:
Require ip 192.168.1.0/24
Require ip 203.0.113.503. Authentifizierung hinzufügen
Zusätzliche Basic-Auth:
# Passwort-Datei erstellen
htpasswd -c /etc/nginx/.htpasswd pma_adminIn Nginx:
location / {
auth_basic "phpMyAdmin";
auth_basic_user_file /etc/nginx/.htpasswd;
try_files $uri $uri/ /index.php?$args;
}4. URL ändern (obscurity)
Statt /phpmyadmin:
# Symlink mit anderem Namen
ln -s /usr/share/phpmyadmin /var/www/html/db-verwaltung-xyz1235. Root-Login deaktivieren
In config.inc.php:
$cfg['Servers'][$i]['AllowRoot'] = false;Dedizierte Benutzer erstellen
Statt root zu verwenden:
-- In MySQL/MariaDB
CREATE USER 'pma_admin'@'localhost' IDENTIFIED BY 'sicheres_passwort';
GRANT ALL PRIVILEGES ON *.* TO 'pma_admin'@'localhost' WITH GRANT OPTION;
FLUSH PRIVILEGES;Erweiterte Funktionen aktivieren
Konfigurationsspeicher einrichten
Ermöglicht Lesezeichen, SQL-Historie, etc.
mysql -u root -p < /usr/share/phpmyadmin/sql/create_tables.sqlIn config.inc.php:
$cfg['Servers'][$i]['controlhost'] = 'localhost';
$cfg['Servers'][$i]['controlport'] = '';
$cfg['Servers'][$i]['controluser'] = 'pma';
$cfg['Servers'][$i]['controlpass'] = 'pma_passwort';
$cfg['Servers'][$i]['pmadb'] = 'phpmyadmin';
$cfg['Servers'][$i]['bookmarktable'] = 'pma__bookmark';
$cfg['Servers'][$i]['relation'] = 'pma__relation';
$cfg['Servers'][$i]['table_info'] = 'pma__table_info';
$cfg['Servers'][$i]['table_coords'] = 'pma__table_coords';
$cfg['Servers'][$i]['pdf_pages'] = 'pma__pdf_pages';
$cfg['Servers'][$i]['column_info'] = 'pma__column_info';
$cfg['Servers'][$i]['history'] = 'pma__history';
$cfg['Servers'][$i]['recent'] = 'pma__recent';
$cfg['Servers'][$i]['favorite'] = 'pma__favorite';
$cfg['Servers'][$i]['users'] = 'pma__users';
$cfg['Servers'][$i]['usergroups'] = 'pma__usergroups';
$cfg['Servers'][$i]['navigationhiding'] = 'pma__navigationhiding';
$cfg['Servers'][$i]['savedsearches'] = 'pma__savedsearches';
$cfg['Servers'][$i]['central_columns'] = 'pma__central_columns';
$cfg['Servers'][$i]['designer_settings'] = 'pma__designer_settings';
$cfg['Servers'][$i]['export_templates'] = 'pma__export_templates';Updates
Mit apt
apt update
apt upgrade phpmyadminManuell
1. Backup von config.inc.php 2. Neue Version herunterladen 3. Alte Version ersetzen 4. Config wiederherstellen
cd /usr/share
wget https://files.phpmyadmin.net/phpMyAdmin/5.2.2/phpMyAdmin-5.2.2-all-languages.tar.gz
tar -xzf phpMyAdmin-5.2.2-all-languages.tar.gz
mv phpmyadmin phpmyadmin.old
mv phpMyAdmin-5.2.2-all-languages phpmyadmin
cp phpmyadmin.old/config.inc.php phpmyadmin/
chown -R www-data:www-data phpmyadminHäufige Probleme
"Access denied for user 'root'@'localhost'"
MySQL 8+ nutzt auth_socket für root:
ALTER USER 'root'@'localhost' IDENTIFIED WITH mysql_native_password BY 'neues_passwort';
FLUSH PRIVILEGES;"The phpMyAdmin configuration storage is not completely configured"
Konfigurationsspeicher einrichten (siehe oben).
Blank page oder 500-Fehler
# PHP-Fehler prüfen
tail /var/log/nginx/error.log
tail /var/log/php8.2-fpm.log
# Berechtigungen prüfen
chown -R www-data:www-data /usr/share/phpmyadminSession-Timeout zu kurz
In config.inc.php:
$cfg['LoginCookieValidity'] = 3600;Alternative: Adminer
Adminer ist eine leichtgewichtige Alternative - nur eine PHP-Datei:
wget https://www.adminer.org/latest.php -O /var/www/html/adminer.phpZugriff: http://server/adminer.php
Fazit
phpMyAdmin ist praktisch für Datenbank-Verwaltung, aber ein Sicherheitsrisiko wenn nicht richtig abgesichert. Nutzen Sie immer HTTPS, beschränken Sie den Zugriff auf bestimmte IPs, und vermeiden Sie root-Logins. Für einfache Anforderungen ist Adminer eine gute Alternative.