Skip to content

How to use in subdirectory #101

Open

Description

@kujiy

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

PMA_ABSOLUTE_URI seemed not work.

Activity

  1. nijel commented on Dec 15, 2016

    @nijel
    Contributor

    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.

  2. self-assigned this
    on Dec 15, 2016
  3. kujiy commented on Dec 15, 2016

    @kujiy
    ContributorAuthor

    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...

  4. nijel commented on Dec 15, 2016

    @nijel
    Contributor

    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....

  5. kujiy commented on Dec 15, 2016

    @kujiy
    ContributorAuthor

    @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.

  6. kujiy commented on Dec 16, 2016

    @kujiy
    ContributorAuthor

    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?

  7. nijel commented on Dec 16, 2016

    @nijel
    Contributor

    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.

  8. kujiy commented on Dec 16, 2016

    @kujiy
    ContributorAuthor

    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?

  9. nijel commented on Dec 16, 2016

    @nijel
    Contributor

    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

  10. added a commit that references this issue on Feb 6, 2017
  11. lkaybob commented on Apr 28, 2017

    @lkaybob

    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
    
  12. nijel commented on Apr 28, 2017

    @nijel
    Contributor

    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.

  13. lkaybob commented on Apr 28, 2017

    @lkaybob

    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?

  14. 5 remaining items

  15. laimison commented on Aug 4, 2021

    @laimison

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

  16. williamdes commented on Aug 4, 2021

    @williamdes
    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

  17. laimison commented on Aug 4, 2021

    @laimison

    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

  18. lug-gh commented on Sep 29, 2021

    @lug-gh

    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.

  19. fishermans commented on Feb 10, 2022

    @fishermans

    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 ...
  20. lug-gh commented on Feb 11, 2022

    @lug-gh

    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.

  21. fishermans commented on Feb 11, 2022

    @fishermans

    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.

  22. williamdes commented on Aug 11, 2022

    @williamdes
    Member

    I am re-opening because of #353

  23. williamdes commented on Aug 12, 2022

    @williamdes
    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() {
  24. biladina commented on Oct 28, 2022

    @biladina

    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..

  25. scotty86 commented on Sep 29, 2023

    @scotty86

    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.

  26. tswaehn commented on Feb 17, 2024

    @tswaehn

    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
    ...
  27. williamdes commented on Mar 6, 2024

    @williamdes
    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

  28. removed their assignment
    on Nov 1, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions