Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Sub-URI support based on config option PMA_SUB_URI_BASE #353

Draft
wants to merge 2 commits into
base: master
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
47 changes: 46 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -138,7 +138,51 @@ See the following links for config file information:

## Usage behind a reverse proxy

Set the variable ``PMA_ABSOLUTE_URI`` to the fully-qualified path (``https://pma.example.net/``) where the reverse proxy makes phpMyAdmin available.
Set the variable ``PMA_ABSOLUTE_URI`` to the fully-qualified path (``https://pma.example.net/``) where the reverse proxy makes phpMyAdmin available. See also ``PMA_SUB_URI_BASE``.

## Usage on sub-URI behind a reverse proxy

For NGINX, a proxy config could looks like that:

docker-compose.yml:
```yaml
version: '3.1'
services:
db:
image: mariadb:10.3
restart: always
environment:
MYSQL_ROOT_PASSWORD: notSecureChangeMe
phpmyadmin:
image: phpmyadmin
restart: always
ports:
- 8080:80 # <-- Exporting the port is optional when running behind a revers proxy on docker.
environment:
- PMA_ARBITRARY=1
- PMA_SUB_URI_BASE=/pma # <-- sub-URI used in nginx location selector.
```


nginx configuration - e.g. default.conf:
```conf
location /pma { # <-- sub-URI set in docker-compose by PMA_SUB_URI_BASE
# Resolve against server_name
proxy_set_header Host $http_host;
# Avoid warning message if proxy server is running on SSL port
proxy_set_header X-Forwarded-Proto $scheme;
# docker-compose service name and internal port of the upstream server.
# Port 80 is the internal port of the phpMyAdmin docker container.
# It is not necessay to export the port if PhpMyAdmin should only be accessible
# through the proxy.
proxy_pass http://phpmyadmin:80;
break;
}
```

## Environment variables summary

Expand All @@ -151,6 +195,7 @@ Set the variable ``PMA_ABSOLUTE_URI`` to the fully-qualified path (``https://pma
* ``PMA_PORTS`` - define comma separated list of ports of the MySQL servers
* ``PMA_USER`` and ``PMA_PASSWORD`` - define username and password to use only with the `config` authentication method
* ``PMA_ABSOLUTE_URI`` - the full URL to phpMyAdmin. Sometimes needed when used in a reverse-proxy configuration. Don't set this unless needed. See [documentation](https://docs.phpmyadmin.net/en/latest/config.html#cfg_PmaAbsoluteUri).
* ``PMA_SUB_URI_BASE`` - the URL suffix to phpMyAdmin when running on sub-URI like `your.domain.local/pma`. Syntax: `/<sub-uri>`.
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

For me this can not be called PMA_SUB_URI_BASE starting with PMA_ means it is a phpMyAdmin config option

Maybe URL_BASE ?

* ``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
* ``PMA_CONTROLHOST`` - when set, this points to an alternate database host used for storing the [phpMyAdmin Configuration Storage database](https://docs.phpmyadmin.net/en/latest/setup.html#phpmyadmin-configuration-storage) database
Expand Down
24 changes: 24 additions & 0 deletions docker-entrypoint.sh
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,28 @@ if [ ! -z "${PMA_USER_CONFIG_BASE64}" ]; then
echo "${PMA_USER_CONFIG_BASE64}" | base64 -d > /etc/phpmyadmin/config.user.inc.php
fi

# Create a symlink for the www root dir to support sub-URI.
# See: https://stackoverflow.com/questions/42035947/how-to-change-the-access-url-of-official-phpmyadmin-docker-image-to-http-local/68643939#68643939
if [ -n "${PMA_SUB_URI_BASE}" ]; then
echo "Using sub URI: ${PMA_SUB_URI_BASE}."
# Create symlink if link target does not already exit.

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Create symlink if link target does not already exit.

if [ ! -d /var/www/html/"${PMA_SUB_URI_BASE}" ] && [ ! -f /var/www/html/"${PMA_SUB_URI_BASE}" ]; then
ln -s /var/www/html /var/www/html"${PMA_SUB_URI_BASE}"
## Verify creation.
if [ -d /var/www/html"${PMA_SUB_URI_BASE}" ]; then
echo "Sub URI link created."
else
echo "!! Creating sub-URI link failed. Validate PMA_SUB_URI_BASE. !!"
exit 1
fi
# If symlink target exist, validate that it is a symlink.
# Fail if the target is pointing to an existing file or dir like 'doc'.
elif [ ! -L /var/www/html/"${PMA_SUB_URI_BASE}" ]; then
echo "!! Sub URI '${PMA_SUB_URI_BASE}' invalid. Please change PMA_SUB_URI_BASE. Cannot create link since a file or directory with same name exists. !!"
exit 1
fi
fi

get_docker_secret() {
local env_var="${1}"
local env_var_file="${env_var}_FILE"
Expand All @@ -48,3 +70,5 @@ get_docker_secret PMA_HOST
get_docker_secret PMA_CONTROLPASS

exec "$@"