用Docker安装
phpMyAdmin comes with a Docker official image, which you can easily deploy. You can download it using:
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
允许您在登录表单上输入数据库服务器主机名。
参见
PMA_HOST
Hostname or IP address of the database server to use.
参见
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可用。
参见
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_USER
和 PMA_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:
<?php
$cfg['Export']['csv_columns'] = true;
You can also use it to define server configuration instead of using the environment variables listed in Docker环境变量:
<?php
/* Override Servers array */
$cfg['Servers'] = [
1 => [
'auth_type' => 'cookie',
'host' => 'mydb1',
'port' => 3306,
'verbose' => 'Verbose name 1',
],
2 => [
'auth_type' => 'cookie',
'host' => 'mydb2',
'port' => 3306,
'verbose' => 'Verbose name 2',
],
];
参见
有关配置选项的详细说明,请参阅 设置。
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:
docker run --name myadmin -d -e PMA_HOST=dbhost -p 8080:80 phpmyadmin/phpmyadmin
To connect phpMyAdmin to more servers use:
docker run --name myadmin -d -e PMA_HOSTS=dbhost1,dbhost2,dbhost3 -p 8080:80 phpmyadmin/phpmyadmin
To use arbitrary server option:
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:
docker run --name phpmyadmin -d --link mysql_db_server:db -p 8080:80 phpmyadmin/phpmyadmin
Running with additional configuration:
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:
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.
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:
phpmyadmin:
image: phpmyadmin/phpmyadmin
container_name: phpmyadmin
environment:
- PMA_ARBITRARY=1
restart: always
ports:
- 8080:80
volumes:
- /sessions
- ~/docker/phpmyadmin/config.user.inc.php:/etc/phpmyadmin/config.user.inc.php
- /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:
frontend http
bind *:80
option forwardfor
option http-server-close
### NETWORK restriction
acl LOCALNET src 10.0.0.0/8 192.168.0.0/16 172.16.0.0/12
# /phpmyadmin
acl phpmyadmin path_dir /phpmyadmin
use_backend phpmyadmin if phpmyadmin LOCALNET
backend phpmyadmin
mode http
reqirep ^(GET|POST|HEAD)\ /phpmyadmin/(.*) \1\ /\2
# phpMyAdmin container IP
server localhost 172.30.21.21:80
When using traefik, something like following should work:
defaultEntryPoints = ["http"]
[entryPoints]
[entryPoints.http]
address = ":80"
[entryPoints.http.redirect]
regex = "(http:\\/\\/[^\\/]+\\/([^\\?\\.]+)[^\\/])$"
replacement = "$1/"
[backends]
[backends.myadmin]
[backends.myadmin.servers.myadmin]
url="http://internal.address.to.pma"
[frontends]
[frontends.myadmin]
backend = "myadmin"
passHostHeader = true
[frontends.myadmin.routes.default]
rule="PathPrefixStrip:/phpmyadmin/;AddPrefix:/"
You then should specify PMA_ABSOLUTE_URI
in the docker-compose configuration:
version: '2'
services:
phpmyadmin:
restart: always
image: phpmyadmin/phpmyadmin
container_name: phpmyadmin
hostname: phpmyadmin
domainname: example.com
ports:
- 8000:80
environment:
- PMA_HOSTS=172.26.36.7,172.26.36.8,172.26.36.9,172.26.36.10
- PMA_VERBOSES=production-db1,production-db2,dev-db1,dev-db2
- PMA_USER=root
- PMA_PASSWORD=
- PMA_ABSOLUTE_URI=http://example.com/phpmyadmin/