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

How to use in subdirectory #101

Open
kujiy opened this issue Dec 15, 2016 · 28 comments
Open

How to use in subdirectory #101

kujiy opened this issue Dec 15, 2016 · 28 comments
Labels

Comments

@kujiy
Copy link
Contributor

kujiy commented Dec 15, 2016

Is is possible that I launch it as http://example.com/phpmyadmin/ ?

PMA_ABSOLUTE_URI seemed not work.

@nijel
Copy link
Contributor

nijel commented Dec 15, 2016

Do you use latest version, PMA_ABSOLUTE_URI sould be the way to do it, but it's not supported on anything older than 4.6.5.

@nijel nijel self-assigned this Dec 15, 2016
@nijel nijel added the question label Dec 15, 2016
@kujiy
Copy link
Contributor Author

kujiy commented Dec 15, 2016

Thanks @nijel I'll check the version tomorrow. I thought I excuted docker pull phpmyadmin/phpmyadmin:latest today. I was wondering that my container ran with php command not nginx and supervisor. I might take some mistakes...

@nijel
Copy link
Contributor

nijel commented Dec 15, 2016

That sounds correcty, but if there is no supervisor, it's clearly some older version. Maybe I've made something wrong in the docker hub tags setup....

@kujiy
Copy link
Contributor Author

kujiy commented Dec 15, 2016

@nijel I feel that's understandable for me. I'd had old container at the moment so I did docker pull and docker rm -f container then docker-compose up. But there's no supervisor inside the container. I'd like to know your recommended tag, thanks.

@kujiy
Copy link
Contributor Author

kujiy commented Dec 16, 2016

Hi @nijel, I was wrong that I specified an old image in docker-compose.yml. I'm sorry to bother you. Now I launched the latest container Version 4.6.5.2. But PMA_ABSOLUTE_URI seemed not to work for subdirectory. I'm wondering where your subdirectory code is. My /etc/nginx.conf is completely same as its original, there's no alias. (I tried to add those lines but couldn't make it work... I've got to learn nginx first).

Could you tell me how you tried a web server to have an alias?

@nijel
Copy link
Contributor

nijel commented Dec 16, 2016

The PMA_ABSOLUTE_URI doesn't change the path where phpMyAdmin is served from the container (it's always on /), it's there for possibility to run it behind reverse proxy which will change the location.

It's there for handing following setups:

(reverse proxy)         <->  (phpMyAdmin docker)
https://host/some/path/      http://1.2.3.4/

Here phpMyAdmin would think it's running on http://1.2.3.4/, while the user sees it at https://host/some/path/. In such case setting PMA_ABSOLUTE_URI=https://host/some/path/ is needed.

@kujiy
Copy link
Contributor Author

kujiy commented Dec 16, 2016

I used phpmyadmin behind haproxy so tried to setup haproxy as a ProxyPass and works!

Here's my haproxy settings for subdirectoried phpmyadmin .

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

    # ProxyPass /phpmyadmin/ http://172.30.21.21/
    reqirep  ^(GET|POST|HEAD)\ /phpmyadmin/(.*)     \1\ /\2 

    server localhost     172.30.21.21:80                # <- phpmyadmin container IP

Here's docker-compose.yml for phpmyadmin.

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/
    networks:
      example.com:
        ipv4_address: 172.30.21.21                # <- Specified container IP for haproxy

networks:
  example.com:
    external: true

Now they're working perfectly. Thank you very much. Would my settings be added to your document perhaps?

@nijel
Copy link
Contributor

nijel commented Dec 16, 2016

Adding that to the docs could be useful, can you please document your setup for our docs? It's here: https://github.com/phpmyadmin/phpmyadmin/blob/master/doc/setup.rst#installing-using-docker

@lkaybob
Copy link

lkaybob commented Apr 28, 2017

Hello, I'm using phpMyAdmin 4.7.0 on Docker along with traefik reverse proxy. I'm experiencing a similar issue on setting up subdirectory.

I used following docker-compose.yml file, with PMA_ABSOLUTE_URL

version: '2'

services:
   myadmin:
     container_name: PHPMyAdmin
     external_links:
       - db
     image: phpmyadmin/phpmyadmin
     networks:
       - web
       - back-end
     restart: always
     environment:
       - PMA_HOST=172.19.0.4
       - PMA_PORT=3306
       - PMA_ABSOLUTE_URI=http://192.168.99.100/phpmyadmin/

networks:
  web:
    external:
      name: ubuntu_webgateway
  back-end:
    external:
       name: 1doitpageconfig_back-end

Also, I set up reverse proxy to point phpMyadmin server with request URL's path to /phpmyadmin But the thing is phpMyAdmin launches at /. So I get 404 error when I access phpMyAdmin from browser with http://EXTERNAL_ADDRESS/phpmyadmin. I ran curl http://INTERNAL_PMA_ADDRESS/ and curl http://INTERNAL_PMA_ADDRESS/phpmyadmin on command line, and the latter one also returns 404 error

I tried to use PathPrefixStip option in reverse proxy. Then I can get index.php properly, but I get 400 error on static assets like CSS, JS, etc. So I think the only way is to make phpMyAdmin available at /phpMyAdmin. Is PMA_ABSOLUTE_URI option valid in 4.7.0 still?

UPDATE I will put request header when I'm trying to access phpMyAdmin at Chrome browser.
This is a request header for index.php with PathPrefixStrip enabled in reverse proxy.

GET /phpmyadmin HTTP/1.1
Host: 192.168.99.100
Connection: keep-alive
Cache-Control: max-age=0
Upgrade-Insecure-Requests: 1
User-Agent: Mozilla/5.0 (Macintosh; Intel Mac OS X 10_12_4) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/58.0.3029.81 Safari/537.36
Accept: text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,*/*;q=0.8
DNT: 1
Accept-Encoding: gzip, deflate, sdch
Accept-Language: ko-KR,ko;q=0.8,en-US;q=0.6,en;q=0.4,ja;q=0.2

HTTP/1.1 200 OK
Cache-Control: no-store, no-cache, must-revalidate,  pre-check=0, post-check=0, max-age=0
Content-Encoding: gzip
Content-Security-Policy: default-src 'self' ;script-src 'self' 'unsafe-inline' 'unsafe-eval' ;;style-src 'self' 'unsafe-inline' ;img-src 'self' data:  *.tile.openstreetmap.org;
Content-Type: text/html; charset=utf-8
Date: Fri, 28 Apr 2017 08:01:03 GMT
Expires: Fri, 28 Apr 2017 08:01:03 +0000
Last-Modified: Fri, 28 Apr 2017 08:01:03 +0000
Pragma: no-cache
Referrer-Policy: no-referrer
Server: nginx
...

and this is for phpmyadmin.css, which returns 400 Bad Request error

GET /phpmyadmin.css.php?nocache=4473505546ltr HTTP/1.1
Host: 192.168.99.100
Connection: keep-alive
User-Agent: Mozilla/5.0 (Macintosh; Intel Mac OS X 10_12_4) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/58.0.3029.81 Safari/537.36
Accept: text/css,*/*;q=0.1
DNT: 1
Accept-Encoding: gzip, deflate, sdch
Accept-Language: ko-KR,ko;q=0.8,en-US;q=0.6,en;q=0.4,ja;q=0.2

HTTP/1.1 400 Bad Request
Content-Length: 166
Content-Type: text/html; charset=utf-8
Date: Fri, 28 Apr 2017 08:01:03 GMT
Server: nginx

@nijel
Copy link
Contributor

nijel commented Apr 28, 2017

The container will always serve phpMyAdmin on /, you need to rewrite the URL in your reverse proxy.

With haproxy example we have in configuration it is done by reqirep ^(GET|POST|HEAD)\ /phpmyadmin/(.*) \1\ /\2. If you can provide example for traefik we can include it in documentation as well.

@lkaybob
Copy link

lkaybob commented Apr 28, 2017

Thanks in advance 👍 While I'm looking through docs, and checking timelines of resources when phpMyAdmin is requested, I just want to check one thing. As I said, I get index.php correctly, but when Stylesheet file is requested from index.php, it is requested as following URL.

image

If my assumption is right, there should be /phpmyadmin prefix in above path. Then the process would be like this.

Requesting CSS @ /phpmyadmin/phpmyadmin.css.php to traefik
--> Traefik stripts the prefix /phpmyadmin
--> Forwards the request with path /phpmyadmin.css.php to internal phpMyAdmin server.
--> Respond with stylesheet file

Is my assumption correct?

@lkaybob
Copy link

lkaybob commented May 2, 2017

Hello again. Sorry for messing up issue thread. I finally found a way to access phpMyAdmin behind traefik. The reason why upper issue happened is a matter of traefik.
Currently, traefik doesn't support backend-by-backend request URL replacement. It merely matches the URL path, or strips the mathed URL path, unlike haproxy or nginx does. (I didn't realize this was a big deal, since traefik is my first reverse proxy experience)

[frontends]
   [frontends.myadmin]
   backend = "myadmin"
   passHostHeader = true
     [frontends.myadmin.routes.default]
     rule="PathPrefixStrip:/phpmyadmin"

I tried 'traefik.toml' first time as above, which is a configuration file. It does get a main page, but static assets, like CSS, JS are not retrieved, since there is no trailing slash on request URL. (This is why above issue happened, browser ommitting incomplete path '/phpmyadmin', when requesting assets.)
So the workaround is to replace whole requested URL, and then strip the prefix. So here is my example for phpMyAdmin behind traefik, with configuration file traefik.toml.

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:/"

P.S. docker-compose.yml(with PMA_ABSOULTE_URI) for starting phpMyAdmin should work with this traefik configuration 😃 . Also, I referenced traefik/traefik#563 and traefik/traefik#679.

@nijel
Copy link
Contributor

nijel commented May 4, 2017

Thanks, I've added your example to our docs.

nijel added a commit to phpmyadmin/phpmyadmin that referenced this issue May 4, 2017
See phpmyadmin/docker#101 (comment)

Signed-off-by: Michal Čihař <michal@cihar.com>
@SimonTod
Copy link

I'm struggling a lot to find a working configuration to make that work with an apache2 reverse proxy using rewrite module. Anyone would have a solution please ?

@LiamKarlMitchell
Copy link

Can we do it from docker-compose.yml labels instead of the traefik.toml?

@laimison
Copy link

laimison commented Aug 4, 2021

I have answered this here https://stackoverflow.com/a/68643939/5689995 in case you don't want to change reverse proxy configuration

@williamdes
Copy link
Member

I have answered this here https://stackoverflow.com/a/68643939/5689995 in case you don't want to change reverse proxy configuration

Thank you
By the way be sure to change FROM phpmyadmin/phpmyadmin to FROM phpmyadmin to use the official image

@laimison
Copy link

laimison commented Aug 4, 2021

I have answered this here https://stackoverflow.com/a/68643939/5689995 in case you don't want to change reverse proxy configuration

Thank you
By the way be sure to change FROM phpmyadmin/phpmyadmin to FROM phpmyadmin to use the official image

Sure, post and image have been updated

@lug-gh
Copy link

lug-gh commented Sep 29, 2021

I have answered this here https://stackoverflow.com/a/68643939/5689995 in case you don't want to change reverse proxy configuration

so, but how do I add this to the docker-compose file?
I tried you image, but there apache fails to start.

@fishermans
Copy link

I have answered this here https://stackoverflow.com/a/68643939/5689995 in case you don't want to change reverse proxy configuration

so, but how do I add this to the docker-compose file? I tried you image, but there apache fails to start.

@lug-gh: Create a new Dockerfile and paste the line of the Stackoverflow post from @laimison into it.

Modify your docker-compose.yml file:

  phpmyadmin:
    image: my-phpmyadmin  #<--- Image name to build
    build: <folder of Dockerfile> #<--- Folder without Dockerfile. See https://docs.docker.com/compose/compose-file/compose-file-v3/#build
    ... config as usual ...

@lug-gh
Copy link

lug-gh commented Feb 11, 2022

I have answered this here https://stackoverflow.com/a/68643939/5689995 in case you don't want to change reverse proxy configuration

so, but how do I add this to the docker-compose file? I tried you image, but there apache fails to start.

@lug-gh: Create a new Dockerfile and paste the line of the Stackoverflow post from @laimison into it.

Modify your docker-compose.yml file:

  phpmyadmin:
    image: my-phpmyadmin  #<--- Image name to build
    build: <folder of Dockerfile> #<--- Folder without Dockerfile. See https://docs.docker.com/compose/compose-file/compose-file-v3/#build
    ... config as usual ...

That way I have to build a new Dockerfile everytime I want to update? Thats not really a good solution in my opinion. Needs a lot of time and is laborious.

I just created a script fix_phpmyadmin which I run after upgrading/restarting the container.

#!/bin/bash
docker exec -it containername bash -c 'mv /var/www/html /var/www/phpmyadmin && mkdir -p /var/www/html && mv /var/www/phpmyadmin /var/www/html/phpmyadmin'

Even thats not a good solution, but better than creating a new Dockerfile, I think.

@fishermans
Copy link

I have answered this here https://stackoverflow.com/a/68643939/5689995 in case you don't want to change reverse proxy configuration

so, but how do I add this to the docker-compose file? I tried you image, but there apache fails to start.

@lug-gh: Create a new Dockerfile and paste the line of the Stackoverflow post from @laimison into it.
Modify your docker-compose.yml file:

  phpmyadmin:
    image: my-phpmyadmin  #<--- Image name to build
    build: <folder of Dockerfile> #<--- Folder without Dockerfile. See https://docs.docker.com/compose/compose-file/compose-file-v3/#build
    ... config as usual ...

That way I have to build a new Dockerfile everytime I want to update? Thats not really a good solution in my opinion. Needs a lot of time and is laborious.

I just created a script fix_phpmyadmin which I run after upgrading/restarting the container.

#!/bin/bash
docker exec -it containername bash -c 'mv /var/www/html /var/www/phpmyadmin && mkdir -p /var/www/html && mv /var/www/phpmyadmin /var/www/html/phpmyadmin'

Even thats not a good solution, but better than creating a new Dockerfile, I think.

No, it grabs the already existing image from docker hub and only applies the additional step at the end. So, it takes less than a few seconds.

Anyway, I will send a PR today to be able to configure the sub uri based on configuration without the need to re build any image.

@williamdes
Copy link
Member

I am re-opening because of #353

@williamdes williamdes reopened this Aug 11, 2022
@williamdes
Copy link
Member

Very much simpler approach:

Set APACHE_ROOT_FOLDER to a value (example: /alernative-path/phpmyadmin), and both / and /alernative-path/phpmyadmin/ will work

Was it the feature that is wanted ?
Because making / not work (404/403) is a bit more complicated and requires file system changes

Anyone, please let me know bout this :)

--- a/apache/docker-entrypoint.sh
+++ b/apache/docker-entrypoint.sh
@@ -35,6 +35,12 @@ if [ -n "${APACHE_PORT+x}" ]; then
     sed -i "s/Listen 80/Listen ${APACHE_PORT}/" /etc/apache2/ports.conf
     apachectl configtest
 fi
+
+if [ ! -z "${APACHE_ROOT_FOLDER}" ]; then
+    echo "Creating an alias for / to ${APACHE_ROOT_FOLDER}."
+    sed -i "/DocumentRoot \/var\/www\/html/a \        Alias ${APACHE_ROOT_FOLDER} /var/www/html" /etc/apache2/sites-enabled/000-default.conf
+    apachectl configtest
+fi
 # end: Apache specific settings
 
 get_docker_secret() {

@biladina
Copy link

biladina commented Oct 28, 2022

Very much simpler approach:

Set APACHE_ROOT_FOLDER to a value (example: /alernative-path/phpmyadmin), and both / and /alernative-path/phpmyadmin/ will work

Was it the feature that is wanted ? Because making / not work (404/403) is a bit more complicated and requires file system changes

Anyone, please let me know bout this :)

--- a/apache/docker-entrypoint.sh
+++ b/apache/docker-entrypoint.sh
@@ -35,6 +35,12 @@ if [ -n "${APACHE_PORT+x}" ]; then
     sed -i "s/Listen 80/Listen ${APACHE_PORT}/" /etc/apache2/ports.conf
     apachectl configtest
 fi
+
+if [ ! -z "${APACHE_ROOT_FOLDER}" ]; then
+    echo "Creating an alias for / to ${APACHE_ROOT_FOLDER}."
+    sed -i "/DocumentRoot \/var\/www\/html/a \        Alias ${APACHE_ROOT_FOLDER} /var/www/html" /etc/apache2/sites-enabled/000-default.conf
+    apachectl configtest
+fi
 # end: Apache specific settings
 
 get_docker_secret() {

this is much make sense and simple, already use this trick before using docker..

edit:
I am using nginx-proxy docker to handle all my apps proxy, and after I test this approach with domain that already have an app, the app become unreachable but the phpmyadmin is ok..

example:
https://example.com => already have web app
https://example.com/phpmyadmin => phpmyadmin

after I add https://example.com/phpmyadmin to the proxy, the https://example.com become 404 not found..

@scotty86
Copy link

I had similar issues using nginx as reverse proxy directing to a docker container and using a subdir for the phpmyadmin url. If i didn't add a slash at the end of the url (https://www.example.org/phpmyadmin) I ended up with a blank page and alle external resources failed to load. Adding a slash at the end (https://www.example.org/phpmyadmin/) helped. I added this to the location part of the phpmyadmin-nginx-config-file:
rewrite ^([^.]*[^/])$ $1/ permanent;
This seems to fix the problems.

@tswaehn
Copy link

tswaehn commented Feb 17, 2024

I am wondering why PMA_ABSOLUTE_URI has to be the full uri. Shouldnt it be only the relativ path behind the host?

looking at your example above:

(reverse proxy)         <->  (phpMyAdmin docker)
https://host/some/path/      http://1.2.3.4/

I would expect PMA_ABSOLUTE_URI = "/some/path"

But as I understand I have to set PMA_ABSOLUTE_URI = "https://host/some/path"

This makes running multiple containers on different hosts pretty unflexible, because we have to always modify the docker-compose file for each new instance, because of changed host name.

Is that correct, or do I miss something?

update

I could get it work with apache adding this to the vhosts config

    # serve phpMyAdmin from subdirectory
    ProxyPass /pma http://phpmyadmin:80/
    ProxyPassReverse /pma http://phpmyadmin:80/

in docker compose:

...

  # Apache Service
  apache:
    build: 'docker/apache_docker'
    ports:
      - 127.0.0.1:8080:80

  # phpMyAdmin Service
  phpmyadmin:
    image: phpmyadmin/phpmyadmin:latest
    environment:
      PMA_HOST: mariadb
      PMA_PORT: 3307
      PMA_ABSOLUTE_URI: "http://phpmyadmin/pma/"
    depends_on:
      - mariadb
...

@williamdes
Copy link
Member

Hello @tswaehn

Setups with different paths are quite difficult I agree.
The full URL seems correct to me, there is no base path handing.
By curiosity why do you need a proxy?
Could you please check #353 it would be nice having it merged

@nijel nijel removed their assignment Nov 1, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests