PhpMyAdmin

出自 Arch Linux 中文维基

phpMyAdmin是一個基於網頁的,幫助管理MySQL數據庫的Apache/PHP前端。

安裝[編輯 | 編輯原始碼]

安裝 軟件包 phpmyadmin

運行[編輯 | 編輯原始碼]

PHP[編輯 | 編輯原始碼]

確保PHP的MySQL擴展已經被啟用。

你也可以啟用 extension=bz2extension=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
注意: 默認情況下,每個可以訪問Web服務器的人都可以通過這個URL訪問phpMyAdmin登錄頁面。要改變此設置,編輯/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假設為pmacontrolpass 假設為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所需的權限,執行如下的查詢:

注意: 確保將所有的pmapmapass替換為在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 的版本相對應,適用於老版本的主題無法使用。

參見[編輯 | 編輯原始碼]