PhpMyAdmin (简体中文)
phpMyAdmin是一个基于网页的,帮助管理MySQL数据库的Apache/PHP前端。
Contents
安装
安装 软件包 phpmyadmin。
运行
PHP
确保PHP的MySQL扩展已经被启用。
你也可以启用bz2和zip扩展以支持压缩。
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
Lighttpd
配置Lighttpd,确保能正常使用PHP,并且启用mod_alias。
在配置文件中为phpmyadmin加入下列alias:
alias.url = ( "/phpmyadmin" => "/usr/share/webapps/phpMyAdmin/")
Nginx
确保正确配置FastCGI.
子域名
参考nginx#PHP configuration file,为php创建一个单独的配置文件,并使用一个服务器块,例如:
server {
server_name phpmyadmin.<domain.tld>;
root /usr/share/webapps/phpMyAdmin;
index index.php;
include php.conf;
}
子目录
这可以通过https://domain.tld/phpMyAdmin访问phpMyAdmin:
/etc/nginx/sites-available/domain.tld
location /phpMyAdmin {
server_name domain.tld;
listen 443 ssl http2;
root /srv/http/domain.tld;
index index.php;
location / {
try_files $uri $uri/ =404;
}
# 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)$ {
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
fastcgi_pass unix:/run/php-fpm/php-fpm.sock;
fastcgi_index index.php;
include fastcgi.conf;
}
}
配置
主配置文件位于/etc/webapps/phpmyadmin/config.inc.php。
如果MySQL服务器不在本机上,添加如下行:
$cfg['Servers'][$i]['host'] = 'localhost';
使用安装脚本
要使用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):
/etc/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.
在/etc/webapps/phpmyadmin/config.inc.php取消注释(移除开头的//),并按需更改为所需的凭据:
/etc/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所需的权限,执行如下的查询:
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';
In order use the bookmark and relation features, set the following permissions:
GRANT SELECT, INSERT, UPDATE, DELETE ON phpmyadmin.* TO 'pma'@'localhost';
重新登录以启用新功能。
启用templates catching
在/etc/webapps/phpmyadmin/config.inc.php添加如下行:
$cfg['TempDir'] = '/tmp/phpmyadmin'