跳转至内容

phpMyAdmin

来自 ArchWiki

phpMyAdmin 是一个基于Web的工具,用于帮助管理MariaDB或MySQL数据库,主要用PHP编写,并在GNU GPL下分发。

安装

安装 phpmyadmin 包。

运行

PHP

确保PHP的 mariadbiconv 扩展已启用。

可选地,可以启用 extension=bz2extension=zip 以支持压缩。

注意 如果设置了 open_basedir,请确保在 /etc/php/php.iniopen_basedir 中包含 /usr/share/webapps/etc/webapps。参见 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
注意 默认情况下,任何可以访问Apache Web服务器的人都可以通过以下URL看到phpMyAdmin登录页面。要更改此设置,请根据需要编辑 /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/phpMyAdminhttp 用户是可写的。

# mkdir /usr/share/webapps/phpMyAdmin/config
# chown http:http /usr/share/webapps/phpMyAdmin/config
# chmod 750 /usr/share/webapps/phpMyAdmin/config

添加blowfish_secret密码短语

为了完全使用phpMyAdmin使用的blowfish算法,需要输入一个32个字符的唯一字符串,以防止出现消息 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.

注意 此示例假定您希望使用默认用户名 pma 作为 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 应用所需的权限,请执行以下查询:

注意 确保将 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';

重新登录以确保新功能已激活。

启用模板缓存

编辑 /usr/share/webapps/phpMyAdmin/config.inc.php 以添加以下行:

$cfg['TempDir'] = '/tmp/phpmyadmin';

删除配置目录

配置完成后删除临时配置目录。这还将消除Web界面的警告。

# rm -r /usr/share/webapps/phpMyAdmin/config

安装主题

主题位于 /usr/share/webapps/phpMyAdmin/themes。您可以在 https://www.phpmyadmin.net/themes/ 找到新主题。

您可以简单地下载并解压新主题,刷新phpmyadmin后即可工作。但是,您必须下载适用于正确版本的phpmyadmin的主题,旧版本的主题将无法工作。

参见

© . This site is unofficial and not affiliated with Arch Linux.

Content is available under GNU Free Documentation License 1.3 or later unless otherwise noted.