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 的版本相對應,適用於老版本的主題無法使用。