PhpMyAdmin
phpMyAdmin是一个基于网页的,帮助管理MySQL数据库的Apache/PHP前端。
安装[编辑 | 编辑源代码]
安装软件包 phpmyadmin包。
运行[编辑 | 编辑源代码]
PHP[编辑 | 编辑源代码]
确保PHP的MySQL扩展已经被启用。
你也可以启用 extension=bz2
和 extension=zip
扩展以支持压缩。
open_basedir
,/usr/share/webapps
和 /etc/weppapps/
必须加入到/etc/php/php.ini
中的open_basedir
。参考 PHP#配置[损坏的链接:无效的章节]。Apache[编辑 | 编辑源代码]
按照Apache HTTP Server#PHP设置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
。例如,你只想从本地访问phpMyAdmin,将Require all granted
改为Require local
。注意,这将禁止远程访问phpMyAdmin,如果你想安全地远程访问phpMyAdmin,你可以设置一个加密的SOCKS通道。修改了 Apache 配置文件之后,restart httpd.service
。
Lighttpd[编辑 | 编辑源代码]
配置Lighttpd,确保能正常使用PHP,并且启用mod_alias
。
在配置文件中为phpmyadmin加入下列alias:
alias.url = ( "/phpmyadmin" => "/usr/share/webapps/phpMyAdmin/")
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安装脚本(例如 http://localhost/phpmyadmin/setup ),确保http
用户可以写入/usr/share/webapps/phpMyAdmin
。
# mkdir /usr/share/webapps/phpMyAdmin/config # chown http:http /usr/share/webapps/phpMyAdmin/config # chmod 750 /usr/share/webapps/phpMyAdmin/config
添加blowfish_secret passphrase[编辑 | 编辑源代码]
需要设置一个唯一的32位的字符串从而充分地使用blowfish算法,从而避免……(配置文件现在需要一个短语密码)的错误。
(blowfish_secret):
/usr/share/webapps/phpMyAdmin/config.inc.php
$cfg['blowfish_secret'] = '...';
启用配置存储[编辑 | 编辑源代码]
例如table linking,change tracking,PDF creation,bookmarking queries的附加功能默认是被禁用的,并且会提示The phpMyAdmin configuration storage is not completely configured, some extended features have been deactivated.
controluser
假设为pma,controlpass
假设为pmapass。在/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';
重新登录以启用新特性。
启用templates catching[编辑 | 编辑源代码]
在/usr/share/webapps/phpMyAdmin/config.inc.php
添加如下行:
$cfg['TempDir'] = '/tmp/phpmyadmin'
移除配置目录[编辑 | 编辑源代码]
当配置完成之后,可以移除临时配置目录,这也会抑制来自网页交互的警告:
# rm -r /usr/share/webapps/phpMyAdmin/config
安装主题[编辑 | 编辑源代码]
主题的位置在 /usr/share/webapps/phpMyAdmin/themes
。你可以在 https://www.phpmyadmin.net/themes/ 找到新主题。
直接下载并将主题提取到相应位置,在 phpmyadmin 刷新之后它将正常工作。然而,你下载的主题必须与 phpmyadmin 的版本相对应,适用于老版本的主题无法使用。