用Docker安装

phpMyAdmin comes with a Docker official image, which you can easily deploy. You can download it using:

  1. docker pull phpmyadmin

The phpMyAdmin server will listen on port 80. It supports several ways of configuring the link to the database server, either by Docker’s link feature by linking your database container to db for phpMyAdmin (by specifying --link your_db_host:db) or by environment variables (in this case it’s up to you to set up networking in Docker to allow the phpMyAdmin container to access the database container over the network).

Docker环境变量

您可以使用环境变量配置多个phpMyAdmin功能:

PMA_ARBITRARY

允许您在登录表单上输入数据库服务器主机名。

参见

$cfg['AllowArbitraryServer']

PMA_HOST

Hostname or IP address of the database server to use.

参见

$cfg['Servers'][$i]['host']

PMA_HOSTS

Comma-separated hostnames or IP addresses of the database servers to use.

注解

仅在 PMA_HOST 为空的时候使用。

PMA_VERBOSE

数据库服务器的详细名称。

参见

$cfg['Servers'][$i]['verbose']

PMA_VERBOSES

逗号分隔的数据库服务器的详细名称。

注解

仅在 PMA_VERBOSE 为空的时候使用。

PMA_USER

用于 Config 认证方式 的用户名。

PMA_PASSWORD

用于 Config 认证方式 的密码。

PMA_PORT

要使用的数据库服务器的端口。

PMA_PORTS

要使用的数据库服务器的逗号分隔端口。

注解

仅在 PMA_PORT 为空的时候使用。

PMA_ABSOLUTE_URI

完全可信的路径(https://pma.example.net/),其中的反向代理使phpMyAdmin可用。

参见

$cfg['PmaAbsoluteUri']

HIDE_PHP_VERSION

If defined, this option will hide the PHP version (expose_php = Off). Set to any value (such as HIDE_PHP_VERSION=true).

UPLOAD_LIMIT

If set, this option will override the default value for apache and php-fpm (this will change upload_max_filesize and post_max_size values).

注解

Format as [0-9+](K,M,G) default value is 2048K

PMA_CONFIG_BASE64

If set, this option will override the default config.inc.php with the base64 decoded contents of the variable.

PMA_USER_CONFIG_BASE64

If set, this option will override the default config.user.inc.php with the base64 decoded contents of the variable.

默认情况下,使用 Cookie 认证方式,但如果 PMA_USERPMA_PASSWORD 已设置,则切换到 Config 认证方式

注解

The credentials you need to log in are stored in the MySQL server, in case of Docker image, there are various ways to set it (for example MYSQL_ROOT_PASSWORD when starting the MySQL container). Please check documentation for MariaDB container or MySQL container.

自定义配置

Additionally configuration can be tweaked by /etc/phpmyadmin/config.user.inc.php. If this file exists, it will be loaded after configuration is generated from above environment variables, so you can override any configuration variable. This configuration can be added as a volume when invoking docker using -v /some/local/directory/config.user.inc.php:/etc/phpmyadmin/config.user.inc.php parameters.

Note that the supplied configuration file is applied after Docker环境变量, but you can override any of the values.

For example to change the default behavior of CSV export you can use the following configuration file:

  1. <?php
  2. $cfg['Export']['csv_columns'] = true;

You can also use it to define server configuration instead of using the environment variables listed in Docker环境变量:

  1. <?php
  2. /* Override Servers array */
  3. $cfg['Servers'] = [
  4. 1 => [
  5. 'auth_type' => 'cookie',
  6. 'host' => 'mydb1',
  7. 'port' => 3306,
  8. 'verbose' => 'Verbose name 1',
  9. ],
  10. 2 => [
  11. 'auth_type' => 'cookie',
  12. 'host' => 'mydb2',
  13. 'port' => 3306,
  14. 'verbose' => 'Verbose name 2',
  15. ],
  16. ];

参见

有关配置选项的详细说明,请参阅 设置

Docker Volumes

You can use the following volumes to customize image behavior:

/etc/phpmyadmin/config.user.inc.php

Can be used for additional settings, see the previous chapter for more details.

/sessions/

Directory where PHP sessions are stored. You might want to share this for example when using Signon 认证方式.

/www/themes/

Directory where phpMyAdmin looks for themes. By default only those shipped with phpMyAdmin are included, but you can include additional phpMyAdmin themes (see Custom Themes) by using Docker volumes.

Docker Examples

To connect phpMyAdmin to a given server use:

  1. docker run --name myadmin -d -e PMA_HOST=dbhost -p 8080:80 phpmyadmin/phpmyadmin

To connect phpMyAdmin to more servers use:

  1. docker run --name myadmin -d -e PMA_HOSTS=dbhost1,dbhost2,dbhost3 -p 8080:80 phpmyadmin/phpmyadmin

To use arbitrary server option:

  1. docker run --name myadmin -d --link mysql_db_server:db -p 8080:80 -e PMA_ARBITRARY=1 phpmyadmin/phpmyadmin

You can also link the database container using Docker:

  1. docker run --name phpmyadmin -d --link mysql_db_server:db -p 8080:80 phpmyadmin/phpmyadmin

Running with additional configuration:

  1. docker run --name phpmyadmin -d --link mysql_db_server:db -p 8080:80 -v /some/local/directory/config.user.inc.php:/etc/phpmyadmin/config.user.inc.php phpmyadmin/phpmyadmin

Running with additional themes:

  1. docker run --name phpmyadmin -d --link mysql_db_server:db -p 8080:80 -v /custom/phpmyadmin/theme/:/www/themes/theme/ phpmyadmin/phpmyadmin

Using docker-compose

Alternatively, you can also use docker-compose with the docker-compose.yml from [https://github.com/phpmyadmin/docker](https://github.com/phpmyadmin/docker)\. This will run phpMyAdmin with an arbitrary server - allowing you to specify MySQL/MariaDB server on the login page.

  1. docker-compose up -d

Customizing configuration file using docker-compose

You can use an external file to customize phpMyAdmin configuration and pass it using the volumes directive:

  1. phpmyadmin:
  2. image: phpmyadmin/phpmyadmin
  3. container_name: phpmyadmin
  4. environment:
  5. - PMA_ARBITRARY=1
  6. restart: always
  7. ports:
  8. - 8080:80
  9. volumes:
  10. - /sessions
  11. - ~/docker/phpmyadmin/config.user.inc.php:/etc/phpmyadmin/config.user.inc.php
  12. - /custom/phpmyadmin/theme/:/www/themes/theme/

参见

自定义配置

Running behind haproxy in a subdirectory

When you want to expose phpMyAdmin running in a Docker container in a subdirectory, you need to rewrite the request path in the server proxying the requests.

For example, using haproxy it can be done as:

  1. frontend http
  2. bind *:80
  3. option forwardfor
  4. option http-server-close
  5. ### NETWORK restriction
  6. acl LOCALNET src 10.0.0.0/8 192.168.0.0/16 172.16.0.0/12
  7. # /phpmyadmin
  8. acl phpmyadmin path_dir /phpmyadmin
  9. use_backend phpmyadmin if phpmyadmin LOCALNET
  10. backend phpmyadmin
  11. mode http
  12. reqirep ^(GET|POST|HEAD)\ /phpmyadmin/(.*) \1\ /\2
  13. # phpMyAdmin container IP
  14. server localhost 172.30.21.21:80

When using traefik, something like following should work:

  1. defaultEntryPoints = ["http"]
  2. [entryPoints]
  3. [entryPoints.http]
  4. address = ":80"
  5. [entryPoints.http.redirect]
  6. regex = "(http:\\/\\/[^\\/]+\\/([^\\?\\.]+)[^\\/])$"
  7. replacement = "$1/"
  8. [backends]
  9. [backends.myadmin]
  10. [backends.myadmin.servers.myadmin]
  11. url="http://internal.address.to.pma"
  12. [frontends]
  13. [frontends.myadmin]
  14. backend = "myadmin"
  15. passHostHeader = true
  16. [frontends.myadmin.routes.default]
  17. rule="PathPrefixStrip:/phpmyadmin/;AddPrefix:/"

You then should specify PMA_ABSOLUTE_URI in the docker-compose configuration:

  1. version: '2'
  2. services:
  3. phpmyadmin:
  4. restart: always
  5. image: phpmyadmin/phpmyadmin
  6. container_name: phpmyadmin
  7. hostname: phpmyadmin
  8. domainname: example.com
  9. ports:
  10. - 8000:80
  11. environment:
  12. - PMA_HOSTS=172.26.36.7,172.26.36.8,172.26.36.9,172.26.36.10
  13. - PMA_VERBOSES=production-db1,production-db2,dev-db1,dev-db2
  14. - PMA_USER=root
  15. - PMA_PASSWORD=
  16. - PMA_ABSOLUTE_URI=http://example.com/phpmyadmin/