phpMyAdmin 是一个广泛使用的基于 Web 的 MySQL 数据库管理工具。为了确保数据库信息的安全,必须对 phpMyAdmin 进行适当的安全配置。以下是一些关键的安全配置要点:
apache
<Directory "/usr/share/phpMyAdmin">
Order Deny,Allow
Deny from all
Allow from 192.168.1.0/24
Allow from 203.0.113.1
</Directory>
nginx
location /phpmyadmin {
allow 192.168.1.0/24;
allow 203.0.113.1;
deny all;
}
apache
<VirtualHost *:443>
SSLEngine on
SSLCertificateFile /path/to/your/certificate.crt
SSLCertificateKeyFile /path/to/your/private.key
DocumentRoot /usr/share/phpMyAdmin
</VirtualHost>
nginx
server {
listen 443 ssl;
server_name yourdomain.com;
ssl_certificate /path/to/your/certificate.crt;
ssl_certificate_key /path/to/your/private.key;
root /usr/share/phpMyAdmin;
}
/phpmyadmin
)更改为不易猜测的路径,以减少被攻击的风险。apache
Alias /newpath /usr/share/phpMyAdmin
<Directory /usr/share/phpMyAdmin>
Options FollowSymlinks
DirectoryIndex index.php
AllowOverride None
Require all granted
</Directory>
nginx
location /newpath {
alias /usr/share/phpMyAdmin;
index index.php;
}
sql
CREATE USER 'pmauser'@'localhost' IDENTIFIED BY 'strongpassword';
GRANT ALL PRIVILEGES ON *.* TO 'pmauser'@'localhost';
FLUSH PRIVILEGES;
.htaccess
文件进一步加强安全:
apache
AuthType Basic
AuthName "Restricted Access"
AuthUserFile /path/to/.htpasswd
Require valid-user
.htpasswd
文件:
bash
htpasswd -c /path/to/.htpasswd username
config.inc.php
中禁用不必要的功能,如导出、导入等:
php
$cfg['Export']['lock_tables'] = true;
$cfg['Import']['allow_interrupt'] = false;
php
$cfg['Logging'] = true;
$cfg['LogFile'] = '/var/log/phpmyadmin.log';
通过以上措施,可以显著提高 phpMyAdmin 的安全性,保护数据库信息不被未授权访问和攻击。