phpMyAdmin
phpMyAdmin 是一个基于 Web 的工具,用于帮助管理 MariaDB 或 MySQL 数据库,主要使用 PHP 编写,并以 GNU GPL 许可证发布。
安装
安装 phpmyadmin 软件包。
运行
PHP
确保 PHP 的 mariadb 和 iconv 扩展已启用。
可选地,您可以启用 extension=bz2 和 extension=zip 以获得压缩支持。
open_basedir,请确保将 /usr/share/webapps 和 /etc/webapps 添加到 /etc/php/php.ini 中的 open_basedir。请参阅 PHP#Configuration。Apache
按照 Apache HTTP Server#PHP 文章中的说明设置 Apache 以使用 PHP。
创建 Apache 配置文件
/etc/httpd/conf/extra/phpmyadmin.conf
Alias /phpmyadmin "/usr/share/webapps/phpMyAdmin"
<Directory "/usr/share/webapps/phpMyAdmin">
DirectoryIndex index.php
AllowOverride All
Options FollowSymlinks
Require all granted
</Directory>
并将其包含在 /etc/httpd/conf/httpd.conf 中
# phpMyAdmin configuration Include conf/extra/phpmyadmin.conf
/etc/httpd/conf/extra/phpmyadmin.conf。例如,如果您只想从同一台机器访问它,请将 Require all granted 替换为 Require local。请注意,这将禁止连接到远程服务器上的 PhpMyAdmin。如果您仍然希望安全地访问远程服务器上的 PhpMyAdmin,您可能需要考虑设置 OpenSSH#Encrypted SOCKS tunnel。在更改 Apache 配置文件后,重启 httpd.service。
Lighttpd
配置 Lighttpd 时,请确保它能够提供 PHP 文件并且 mod_alias 已启用。
将以下 PhpMyAdmin 的别名添加到配置中
alias.url = ( "/phpmyadmin" => "/usr/share/webapps/phpMyAdmin/")
Nginx
确保设置 nginx#FastCGI 并使用 nginx#Server blocks 以简化管理。
首选通过子域名访问 phpMyAdmin,例如 https://pma.domain.tld
/etc/nginx/sites-available/pma.domain.tld
server {
server_name pma.domain.tld;
; listen 80; # also listen on http
; listen [::]:80;
listen 443 ssl http2;
listen [::]:443 ssl http2;
index index.php;
access_log /var/log/nginx/pma.access.log;
error_log /var/log/nginx/pma.error.log;
# Allows limiting access to certain client addresses.
; allow 192.168.1.0/24;
; allow my-ip;
; deny all;
root /usr/share/webapps/phpMyAdmin;
location / {
try_files $uri $uri/ =404;
}
error_page 404 /index.php;
location ~ \.php$ {
try_files $uri $document_root$fastcgi_script_name =404;
fastcgi_split_path_info ^(.+\.php)(/.*)$;
fastcgi_pass unix:/run/php-fpm/php-fpm.sock;
fastcgi_index index.php;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
include fastcgi_params;
fastcgi_param HTTP_PROXY "";
fastcgi_param HTTPS on;
fastcgi_request_buffering off;
}
}
或通过子目录访问,例如 https://domain.tld/phpMyAdmin
/etc/nginx/sites-available/domain.tld
server {
server_name domain.tld;
listen 443 ssl http2;
listen [::]:443 ssl http2;
index index.php;
access_log /var/log/nginx/domain.tld.access.log;
error_log /var/log/nginx/domain.tld.error.log;
root /srv/http/domain.tld;
location / {
try_files $uri $uri/ =404;
}
location /phpMyAdmin {
root /usr/share/webapps/phpMyAdmin;
}
# Deny static files
location ~ ^/phpMyAdmin/(README|LICENSE|ChangeLog|DCO)$ {
deny all;
}
# Deny .md files
location ~ ^/phpMyAdmin/(.+\.md)$ {
deny all;
}
# Deny setup directories
location ~ ^/phpMyAdmin/(doc|sql|setup)/ {
deny all;
}
#FastCGI config for phpMyAdmin
location ~ /phpMyAdmin/(.+\.php)$ {
try_files $uri $document_root$fastcgi_script_name =404;
fastcgi_split_path_info ^(.+\.php)(/.*)$;
fastcgi_pass unix:/run/php-fpm/php-fpm.sock;
fastcgi_index index.php;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
include fastcgi_params;
fastcgi_param HTTP_PROXY "";
fastcgi_param HTTPS on;
fastcgi_request_buffering off;
}
}
配置
主配置文件位于 /usr/share/webapps/phpMyAdmin/config.inc.php。
定义远程 MySQL 服务器
如果 MySQL 服务器是远程主机,请将以下行附加到配置文件
$cfg['Servers'][$i]['host'] = 'example.com';
使用设置脚本
要允许使用 phpMyAdmin 设置脚本(例如 https:///phpmyadmin/setup),请确保 /usr/share/webapps/phpMyAdmin 对 http 用户 可写
# mkdir /usr/share/webapps/phpMyAdmin/config # chown http:http /usr/share/webapps/phpMyAdmin/config # chmod 750 /usr/share/webapps/phpMyAdmin/config
添加 blowfish_secret 密码
需要输入一个唯一的 32 个字符长的字符串,才能完全使用 phpMyAdmin 使用的 blowfish 算法,从而防止出现消息 ERROR: The configuration file now needs a secret passphrase (blowfish_secret)
/usr/share/webapps/phpMyAdmin/config.inc.php
$cfg['blowfish_secret'] = '...';
启用配置存储
默认情况下,诸如表链接、更改跟踪、PDF 创建和书签查询等额外选项被禁用,并在主页上显示 The phpMyAdmin configuration storage is not completely configured, some extended features have been deactivated. 。
controluser,pmapass 作为 controlpass。在 /usr/share/webapps/phpMyAdmin/config.inc.php 中,取消注释(删除前导的 "//"),并在需要时将其更改为您所需的凭据
/usr/share/webapps/phpMyAdmin/config.inc.php
/* User used to manipulate with storage */ // $cfg['Servers'][$i]['controlhost'] = 'my-host'; // $cfg['Servers'][$i]['controlport'] = '3306'; $cfg['Servers'][$i]['controluser'] = 'pma'; $cfg['Servers'][$i]['controlpass'] = 'pmapass'; /* Storage database and tables */ $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]['table_uiprefs'] = 'pma__table_uiprefs'; $cfg['Servers'][$i]['tracking'] = 'pma__tracking'; $cfg['Servers'][$i]['userconfig'] = 'pma__userconfig'; $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';
设置数据库
有两种选项可用于创建所需的表
- 使用 PhpMyAdmin 导入
/usr/share/webapps/phpMyAdmin/sql/create_tables.sql。 - 在命令行中执行
mysql -u root -p < /usr/share/webapps/phpMyAdmin/sql/create_tables.sql。
设置数据库用户
要为 controluser 应用所需的权限,请执行以下查询
pma 和 pmapass 实例替换为在 config.inc.php 中设置的值。如果您要为远程数据库设置此项,则还必须将 localhost 更改为正确的主机。GRANT USAGE ON mysql.* TO 'pma'@'localhost' IDENTIFIED BY 'pmapass';
GRANT SELECT (
Host, User, Select_priv, Insert_priv, Update_priv, Delete_priv,
Create_priv, Drop_priv, Reload_priv, Shutdown_priv, Process_priv,
File_priv, Grant_priv, References_priv, Index_priv, Alter_priv,
Show_db_priv, Super_priv, Create_tmp_table_priv, Lock_tables_priv,
Execute_priv, Repl_slave_priv, Repl_client_priv
) ON mysql.user TO 'pma'@'localhost';
GRANT SELECT ON mysql.db TO 'pma'@'localhost';
GRANT SELECT ON mysql.host TO 'pma'@'localhost';
GRANT SELECT (Host, Db, User, Table_name, Table_priv, Column_priv)
ON mysql.tables_priv TO 'pma'@'localhost';
为了使用书签和关系功能,请设置以下权限
GRANT SELECT, INSERT, UPDATE, DELETE ON phpmyadmin.* TO 'pma'@'localhost';
重新登录以确保新功能已激活。
启用模板缓存
编辑 /usr/share/webapps/phpMyAdmin/config.inc.php 以添加以下行
$cfg['TempDir'] = '/tmp/phpmyadmin';
移除 config 目录
配置完成后,移除临时配置目录。这也将抑制来自 Web 界面的警告
# rm -r /usr/share/webapps/phpMyAdmin/config
安装主题
主题位于 /usr/share/webapps/phpMyAdmin/themes。您可以在 https://www.phpmyadmin.net/themes/ 找到新主题
您可以简单地下载并解压新主题,它将在 phpmyadmin 刷新后生效。但是,您必须为正确版本的 phpmyadmin 下载主题,旧版本的主题将无法工作。