phpmyadmin / docker

Docker container for phpMyAdmin
https://hub.docker.com/_/phpmyadmin
GNU General Public License v3.0
673 stars 456 forks source link

[Question] Serving fpm-alpine image with nginx #253

Open lonix1 opened 5 years ago

lonix1 commented 5 years ago

I am trying to get the fpm-alpine image to work with nginx.

docker-compose.yml

version: "3.7"

networks:
  mynet:

volumes:
  mariadb_data:
  phpmyadmin_data:

services:

  mariadb:
    image: mariadb:10.4.8-bionic
    environment:
      MYSQL_DATABASE: mydb
      MYSQL_ROOT_PASSWORD: password
      MYSQL_USER: admin
      MYSQL_PASSWORD: password
    volumes:
      - mariadb_data:/var/lib/mysql/
    networks:
      - mynet

  phpmyadmin:
    image: phpmyadmin/phpmyadmin:fpm-alpine
    volumes:
      - phpmyadmin_data:/var/www/html/
    networks:
      - mynet
    depends_on:
      - mariadb

  nginx:
    image: nginx:1.17.4-alpine
    volumes:
      - ./default.conf:/etc/nginx/conf.d/default.conf:ro
      - phpmyadmin_data:/var/www/html/:ro
    ports:
      - "80:80"
    networks:
      - mynet
    depends_on:
      - mariadb
      - phpmyadmin

default.conf

resolver 127.0.0.11 valid=15s;

server {

  listen 80;
  server_name www.example.com;

  root /var/www/html/;
  index index.php index.html index.htm;

  set $upstream phpmyadmin:9000;

  location ~ \/pma {
    fastcgi_pass $upstream;
    fastcgi_index index.php;
    fastcgi_split_path_info ^(.+\.php)(/.*)$;
    include fastcgi_params;
    fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
    fastcgi_param PATH_INFO $fastcgi_path_info;
  }
}

Then: docker-compose up.

When I access http://www.example.com/pma I get

502 Bad Gateway

I also tried to get it working using a port instead of path, i.e. http://www.example.com:8080 instead of http://www.example.com/pma.

The docs show examples using traefik and haproxy, but not for nginx.

Can someone spot the error in my setup, or does someone have a working example to share?

williamdes commented 5 years ago

@lonix1 try port 9000 on host phpmyadmin for fastcgi_pass since you are sending the script to the cgi and not to the web server

If it does not work comment back here :)

lonix1 commented 5 years ago

@williamdes Thanks - yes you are right it should be 9000! I edited it above.

However, it still does not work :-(

curl http://www.example.com/pma gives:

File not found.

The docker log shows:

"GET /pma/index.php" 404

williamdes commented 5 years ago

maybe you should change /var/www/html to /usr/src/phpmyadmin

See: https://github.com/phpmyadmin/docker/blob/master/fpm-alpine/Dockerfile#L77

I assume you have data into the volume phpmyadmin_data

https://superuser.com/a/435969/609233 I would write the nginx config block like that

  location ~ \/pma {
    rewrite ^/pma(/.*)$ $1 last;
    fastcgi_pass $upstream;
    fastcgi_index index.php;
    include snippets/fastcgi-php.conf;
    # remove line below ?
    fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
  }

You are maybe missing the rewrite part since the files are in the root folder and not in /pma

lonix1 commented 5 years ago

When I do docker-compose up for the first time, it says

phpMyAdmin not found in /var/www/html - copying now... Complete! phpMyAdmin has been successfully copied to /var/www/html

That's why I used that path. But even if I use /usr/src/phpmyadmin it fails with same error. I checked that there are files in there, looks okay.

I tried the new location block also. Same error (file not found).

Does that actually work for you?


I will carry on fiddling to get it working. Maybe we can then add it to the docs.

williamdes commented 5 years ago

~After hours (since my last post) I could not make a rewrite folder that worked.~

Light version

resolver 127.0.0.11 valid=15s;
server {
    listen 80;
    server_name williamdes.local default_server;
    root /var/www/html/;
    index index.php index.html index.htm;
    set $upstream phpmyadmin:9000;

    location ~ \.php$ {
        try_files $uri = 404;
        #fastcgi_split_path_info ^(.+\.php)(/.+)$;
        fastcgi_pass $upstream;
        fastcgi_index index.php;
        include fastcgi_params;
        fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
        fastcgi_param PATH_INFO $fastcgi_path_info;
    }
}
version: "3.7"

networks:
  mynet:

volumes:
  mariadb_data:
  phpmyadmin_data:

services:

  mariadb:
    image: mariadb:10.4.8-bionic
    environment:
      MYSQL_DATABASE: mydb
      MYSQL_ROOT_PASSWORD: password
      MYSQL_USER: admin
      MYSQL_PASSWORD: password
    volumes:
      - mariadb_data:/var/lib/mysql/
    networks:
      - mynet

  phpmyadmin:
    image: phpmyadmin/phpmyadmin:fpm-alpine
    environment:
      PMA_HOST: mariadb
    volumes:
      - phpmyadmin_data:/var/www/html/
    networks:
      - mynet
    depends_on:
      - mariadb

  nginx:
    image: nginx:1.17.4-alpine
    volumes:
      - ./default.conf:/etc/nginx/conf.d/default.conf:ro
      - phpmyadmin_data:/var/www/html/:ro
    ports:
      - "90:80"
    networks:
      - mynet
    depends_on:
      - mariadb
      - phpmyadmin
williamdes commented 5 years ago

Using a proxy

resolver 127.0.0.11 valid=15s;
server {
    listen 80;
    server_name williamdes.local default_server;
    root /var/www/html/;
    index index.php index.html index.htm;
    set $upstream phpmyadmin:9000;

    location ^~ /pma {
        rewrite /pma/(.*) /$1 last;
        proxy_pass http://localhost:80;
        proxy_set_header Upgrade $http_upgrade;
        proxy_set_header Host $host;
        proxy_set_header X-Real-IP $remote_addr;
        proxy_set_header X-Forwarded-Proto $http_x_forwarded_proto;
        proxy_cache_bypass $http_upgrade;
        proxy_redirect off;
    }

    location ~ \.php$ {
        try_files $uri = 404;
        #fastcgi_split_path_info ^(.+\.php)(/.+)$;
        fastcgi_pass $upstream;
        fastcgi_index index.php;
        include fastcgi_params;
        fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
        fastcgi_param PATH_INFO $fastcgi_path_info;
    }
}

Using CGI

Thanks to: https://stackoverflow.com/a/29213330/5155484

resolver 127.0.0.11 valid=15s;
server {
    listen 80;
    server_name williamdes.local default_server;
    root /var/www/html/;
    index index.php index.html index.htm;
    set $upstream phpmyadmin:9000;

    location ^~ /pma {
        rewrite /pma/(.*) /$1 last;
        try_files $uri = 404;
        #fastcgi_split_path_info ^(.+\.php)(/.+)$;
        fastcgi_pass $upstream;
        fastcgi_index index.php;
        include fastcgi_params;
        fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
        fastcgi_param PATH_INFO $fastcgi_path_info;
    }

    location ~ \.php$ {
        try_files $uri = 404;
        #fastcgi_split_path_info ^(.+\.php)(/.+)$;
        fastcgi_pass $upstream;
        fastcgi_index index.php;
        include fastcgi_params;
        fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
        fastcgi_param PATH_INFO $fastcgi_path_info;
    }
}

@lonix1 the CGI version is what you want

lonix1 commented 5 years ago

@williamdes wow thanks! I used the "Using CGI" section, and got it working finally, but on the wrong path:

curl http://www.example.com/pma gives 404 but curl http://www.example.com/ gives the phpmyadmin login page


BTW, I assume your "Using a proxy" section is for the latest image, and "Using CGI" is for the fpm-alpine and fpm images?

williamdes commented 5 years ago

I think you are correct on what you assume

@lonix1 can you paste your final configuration?

I made it work with the ^~ and position can be important from what Internet says

lonix1 commented 5 years ago

Okay I got it to work, thanks to this!

Notes:

resolver 127.0.0.11 valid=15s;

server {

  listen 80;
  server_name www.example.com example.com;
  set $upstream phpmyadmin:9000;

  location ^~ /phpmyadmin {
    alias /var/www/html/;
    index index.php;
    location ~ \.php$ {
      try_files $uri = 404;
      fastcgi_pass $upstream;
      include fastcgi_params;
      fastcgi_param SCRIPT_FILENAME $request_filename;
    }
  }

}

This should be in the docs. If someone knows how to do that, please add @williamdes' code for latest image and my code for fpm-alpine and fpm images.

lonix1 commented 5 years ago

@williamdes BTW thanks for taking the time to help me... Appreciated!

williamdes commented 5 years ago

@lonix1 I think it is because all files need to know their base path?

lonix1 commented 5 years ago

@williamdes Yes... so we need to correctly set SCRIPT_FILENAME.

williamdes commented 5 years ago

@lonix1 please post the config when you have a working example ;)

lonix1 commented 5 years ago

@williamdes This works for me:

docker-compose.yml

version: "3.7"

networks:
  mynet:

volumes:
  mariadb_data:
  phpmyadmin_data:

services:

  mariadb:
    image: mariadb:10.4.8-bionic
    environment:
      MYSQL_DATABASE: mydb
      MYSQL_ROOT_PASSWORD: password
      MYSQL_USER: admin
      MYSQL_PASSWORD: password
    volumes:
      - mariadb_data:/var/lib/mysql/
    networks:
      - mynet

  phpmyadmin:
    image: phpmyadmin/phpmyadmin:fpm-alpine
    environment:
      PMA_HOST: mariadb
     #PMA_ABSOLUTE_URI: http://www.example.com/phpmyadmin/
    volumes:
      - phpmyadmin_data:/var/www/html/
     #- ./config.user.inc.php:/etc/phpmyadmin/config.user.inc.php:ro
    networks:
      - mynet
    depends_on:
      - mariadb

  nginx:
    image: nginx:1.17.4-alpine
    volumes:
      - ./default.conf:/etc/nginx/conf.d/default.conf:ro
      - phpmyadmin_data:/var/www/html/:ro
    ports:
      - "80:80"
    networks:
      - mynet
    depends_on:
      - mariadb
      - phpmyadmin

default.conf

resolver 127.0.0.11 valid=15s;

server {
  listen 80;
  server_name www.example.com example.com;
  set $upstream phpmyadmin:9000;

  location ^~ /phpmyadmin {
    alias /var/www/html/;
    index index.php;
    location ~ \.php$ {
      try_files      $uri = 404;
      include        fastcgi_params;
      fastcgi_split_path_info ^\/phpmyadmin\/(.+\.php)(.*)$;
      fastcgi_param  SCRIPT_FILENAME $fastcgi_script_name;
      fastcgi_pass   $upstream;
    }
  }

}

Of course, in production, nginx would not be in the same stack (but should be in the same docker network).

williamdes commented 5 years ago

@lonix1 Thank you !

From what I understand removing $document_root solved the URI issue.

If you want to open a pull-request let me know, if not I will do it

lonix1 commented 5 years ago

I'm not sure how to do that... what I mean is that maybe the documents site can have this info...

Jason-2020 commented 4 years ago

@lonix1 Does nginx server need to have phpmyadmin volume attached to it? In my case I'd like to use host machine's nginx but don't want to share phpmyadmin docker's volume into host machine to actually use it as 'stateless' as possible.

lonix1 commented 4 years ago

@Jason-2020 From what I remember the alpine image doesn't come with a webserver, that's why you need to use nginx.

If you want phpmyadmin to be completely isolated, then don't use the alpine image. The normal image comes with apache, I think.

williamdes commented 4 years ago

@lonix1 yes, there is an apache version I think you need to have the volume attached or you will get 404 errors if you do not bypass the file check on the nginx side before sending requests to the fpm server

ThibaultVlacich commented 4 years ago

I'm trying to serve PHPMyAdmin on the root of a subdomain using Nginx, to avoid having two web-server running (I use Nginx for the rest of my application, so having Apache just for PMA is not really optimal...), but I cannot get it working.

I followed the conversation here, but all I get is a "404 not found", and this in the Nginx logs:

2020/02/14 21:34:49 [error] 15#15: *1 FastCGI sent in stderr: "Primary script unknown" while reading response header from upstream, client: 172.18.0.1, server: phpmyadmin.example.com, request: "GET / HTTP/1.1", upstream: "fastcgi://172.18.0.5:9000", host: "phpmyadmin.example.com"

Here's what I have for now for my Nginx config:

server {
    server_name phpmyadmin.example.com;
    root /var/www/html;
    index index.php index.html index.htm;

    location ~ \.php$ {
        try_files $uri = 404;

        fastcgi_pass phpmyadmin:9000;
        #fastcgi_split_path_info ^(.+\.php)(/.*)$;
        fastcgi_index index.php;
        include fastcgi_params;
        fastcgi_param SCRIPT_FILENAME $fastcgi_script_name;
        fastcgi_param HTTPS off;
    }

    error_log /var/log/nginx/phpmyadmin_error.log;
    access_log /var/log/nginx/phpmyadmin_access.log;
}

Any idea?

williamdes commented 4 years ago

Hi @ThibaultVlacich Maybe you should follow https://github.com/phpmyadmin/docker/issues/253#issuecomment-543938409 and use fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;

Did this work ?

ThibaultVlacich commented 4 years ago

It... worked...

Swear I tried it already but I guess not. Thanks @williamdes.

zengzhengrong commented 4 years ago

Okay I got it to work, thanks to this!

Notes:

  • No rewriting necessary
  • I did not need to set PMA_ABSOLUTE_URI - not sure why?
resolver 127.0.0.11 valid=15s;

server {

  listen 80;
  server_name www.example.com example.com;
  set $upstream phpmyadmin:9000;

  location ^~ /phpmyadmin {
    alias /var/www/html/;
    index index.php;
    location ~ \.php$ {
      try_files $uri = 404;
      fastcgi_pass $upstream;
      include fastcgi_params;
      fastcgi_param SCRIPT_FILENAME $request_filename;
    }
  }

}

This should be in the docs. If someone knows how to do that, please add @williamdes' code for latest image and my code for fpm-alpine and fpm images.

I user this config ,www.example.com/phpmyadmin is work,but i add

    location / {
        uwsgi_pass  unix:/api/api.sock;        
        include     uwsgi_params;
    }

    location /phpmyadmin {
        alias /var/www/html/;
        index index.php;
        location ~ \.php$ {
        try_files $uri = 404;
        fastcgi_pass $upstream;
        include fastcgi_params;
        fastcgi_param SCRIPT_FILENAME $request_filename;
        fastcgi_param PATH_INFO $fastcgi_path_info;
        }
    }

browser www.example.com will be download file , have any idea?

when fastcgi_param SCRIPT_FILENAME $request_filename; change to fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name; it www.example.com/phpmyadmin does not work, i am not clear konw about fastcgi_param and variables does mean what

williamdes commented 4 years ago

browser www.example.com will be download file , have any idea?

You did not configure correctly the .php file handler IMO

zengzhengrong commented 4 years ago

@williamdes I guess probably is browser cause it , I use edge to browse www.example.com ,it can show me page correctly ,but chrome do not,always download the php file

williamdes commented 4 years ago

@zengzhengrong Are you sure the URLs are exactly the same ? What about using curl or wget to have a test without a browser ?

zengzhengrong commented 4 years ago

@williamdes I test curl or wget ,it both correctly route to my api.sock and postman as good as well,only chrome do not

williamdes commented 4 years ago

Very strange, could you send all the nginx config file?

zengzhengrong commented 4 years ago

https://github.com/zengzhengrong/django-forum-backend/blob/master/nginx/conf.d/django.conf

resolver 127.0.0.11 valid=15s;

server {
    listen    80;
    charset     utf-8;
    client_max_body_size 75M;
    server_name     192.168.1.235;
    set $upstream phpmyadmin:9000;

    location /static {
        alias /api/static;
    }

    location /media {
        alias /api/media;
        expires 24h;
    }

    location /flower-internal/ {
        internal;
        rewrite ^/flower-internal/(.*)$ /$1 break;
        proxy_pass http://django-forum-backend:5555;
        proxy_set_header Host $host;
    }

    location / {
        uwsgi_pass  unix:/api/api.sock;        
        include     uwsgi_params;
    }

    location /phpmyadmin {
        alias /var/www/html/;
        index index.php;
        location ~ \.php$ {
        try_files $uri = 404;
        fastcgi_pass $upstream;
        include fastcgi_params;
        fastcgi_param SCRIPT_FILENAME $request_filename;
        fastcgi_param PATH_INFO $fastcgi_path_info;
        }
    }

}
williamdes commented 4 years ago

@zengzhengrong Could you copy the request from F12 > Network > The request (index.php) > Copy > as curl and post it here after trying it into a terminal ?

zengzhengrong commented 4 years ago

The chrome response headers have a Content-Type: application/octet-stream

微信截图_20200503023331

chrome:

微信截图_20200503023845

edge:

微信截图_20200503023831

copy as curl in terminal:

微信截图_20200503024423
williamdes commented 4 years ago

@zengzhengrong

I use edge to browse www.example.com ,it can show me page correctly ,but chrome do not,always download the php file

So the application/octet-stream sent to chrome is html or php code ?

zengzhengrong commented 4 years ago

I download and open with vscode:

<?php
/* vim: set expandtab sw=4 ts=4 sts=4: */
/**
 * Main loader script
 *
 * @package PhpMyAdmin
 */
declare(strict_types=1);

use PhpMyAdmin\Controllers\HomeController;
use PhpMyAdmin\Core;
use PhpMyAdmin\DatabaseInterface;
use PhpMyAdmin\Response;
use PhpMyAdmin\Url;
use PhpMyAdmin\Util;

if (! defined('ROOT_PATH')) {
    define('ROOT_PATH', __DIR__ . DIRECTORY_SEPARATOR);
}

global $server;

require_once ROOT_PATH . 'libraries/common.inc.php';

/**
 * pass variables to child pages
 */
$drops = [
    'lang',
    'server',
    'collation_connection',
    'db',
    'table',
];
foreach ($drops as $each_drop) {
    if (array_key_exists($each_drop, $_GET)) {
        unset($_GET[$each_drop]);
    }
}
unset($drops, $each_drop);

/**
 * Black list of all scripts to which front-end must submit data.
 * Such scripts must not be loaded on home page.
 */
$target_blacklist =  [
    'import.php',
    'export.php',
];

// If we have a valid target, let's load that script instead
if (! empty($_REQUEST['target'])
    && is_string($_REQUEST['target'])
    && 0 !== strpos($_REQUEST['target'], "index")
    && ! in_array($_REQUEST['target'], $target_blacklist)
    && Core::checkPageValidity($_REQUEST['target'], [], true)
) {
    include ROOT_PATH . $_REQUEST['target'];
    exit;
}

/** @var Response $response */
$response = $containerBuilder->get(Response::class);

/** @var DatabaseInterface $dbi */
$dbi = $containerBuilder->get(DatabaseInterface::class);

/** @var HomeController $controller */
$controller = $containerBuilder->get(HomeController::class);

if (isset($_REQUEST['ajax_request']) && ! empty($_REQUEST['access_time'])) {
    exit;
}

if (isset($_POST['set_theme'])) {
    $controller->setTheme([
        'set_theme' => $_POST['set_theme'],
    ]);

    header('Location: index.php' . Url::getCommonRaw());
} elseif (isset($_POST['collation_connection'])) {
    $controller->setCollationConnection([
        'collation_connection' => $_POST['collation_connection'],
    ]);

    header('Location: index.php' . Url::getCommonRaw());
} elseif (! empty($_REQUEST['db'])) {
    // See FAQ 1.34
    $page = null;
    if (! empty($_REQUEST['table'])) {
        $page = Util::getScriptNameForOption(
            $GLOBALS['cfg']['DefaultTabTable'],
            'table'
        );
    } else {
        $page = Util::getScriptNameForOption(
            $GLOBALS['cfg']['DefaultTabDatabase'],
            'database'
        );
    }
    include ROOT_PATH . $page;
} elseif ($response->isAjax() && ! empty($_REQUEST['recent_table'])) {
    $response->addJSON($controller->reloadRecentTablesList());
} elseif ($GLOBALS['PMA_Config']->isGitRevision()
    && isset($_REQUEST['git_revision'])
    && $response->isAjax()
) {
    $response->addHTML($controller->gitRevision());
} else {
    // Handles some variables that may have been sent by the calling script
    $GLOBALS['db'] = '';
    $GLOBALS['table'] = '';
    $show_query = '1';

    if ($server > 0) {
        include ROOT_PATH . 'libraries/server_common.inc.php';
    }

    $response->addHTML($controller->index());
}
devsaumya commented 4 years ago
version: '3.6'
services:
    web:
       image: nginx:latest
       container_name: nginx
       restart: unless-stopped
       ports:
            - "8080:80"
       volumes:
            - ./public_html:/public_html
            - ./conf.d:/etc/nginx/conf.d
            -  /etc/localtime:/etc/localtime
            - ./logs/nginx-error.log:/var/log/nginx/error.log
            - ./logs/nginx-access.log:/var/log/nginx/access.log
       networks:
            - nginxphp
    php:
       image: php:fpm
       container_name: php-fpm
       restart: unless-stopped
       volumes:
            - ./public_html:/public_html
       expose:
            - 9000
       networks:
            - nginxphp
    mySql:
        image: mysql/mysql-server:latest
        container_name: mysql
        restart: unless-stopped
        restart: always
        environment:
            - MYSQL_DATABASE= 'root'
            - MYSQL_USER=root
            - MYSQL_ROOT_PASSWORD=password
            - MYSQL_PASSWORD=password
        ports:
            - "3306:3306"
        networks:
            - nginxphp
    phpmyadmin:
        image: phpmyadmin/phpmyadmin:fpm-alpine
        container_name: phpmyadmin
        restart: always
        environment:
               PMA_HOST: mySql
        ports:
            - 8081:80
        volumes:
            - /sessions
            - ~/docker/phpmyadmin/config.user.inc.php:/etc/phpmyadmin/config.user.inc.php
            - /custom/phpmyadmin/theme/:/www/themes/theme/
        networks:
            - nginxphp
        depends_on:
            - mySql
networks:
     nginxphp:

and config file

resolver 127.0.0.11 valid=15s;
server {
        listen 80;
        server_name _;
        root /public_html;
        location / {
            index index.php index.html;
        }
        location ~* \.php$ {
            fastcgi_pass    php:9000;
            fastcgi_index   index.php;
            include         fastcgi_params;
            fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
            fastcgi_param PATH_INFO $fastcgi_path_info;
        }
        location ^~ /phpmyadmin {
            alias /var/www/html/;
            index index.php;
            location ~ \.php$ {
            try_files      $uri = 404;
            include        fastcgi_params;
            fastcgi_split_path_info ^\/phpmyadmin\/(.+\.php)(.*)$;
            fastcgi_param  SCRIPT_FILENAME $fastcgi_script_name;
            fastcgi_pass   $upstream;
            }
        }    
}

can anyone help where I am going wrong, Nginx and MySQL and PHP:fpm is serving info.php but PHPMyAdmin/PHPMyAdmin:fpm-alpine is not working the PHPMyAdmin container is stopped standard_init_linux.go:211: exec user process caused "exec format error" and IP:8081/phpmyadmin is 404.

williamdes commented 4 years ago

@DevSaumyadip I think fastcgi_split_path_info is either invalid or useless https://github.com/phpmyadmin/docker/issues/253#issuecomment-543938409

pzystorm commented 4 years ago

I also have some trouble with the phpmyadmin:fpm-alpine image. my docker-compose.yml is this:

version: "3.7"

networks:
  pma_net:

services:

  pma_php:
    image: phpmyadmin/phpmyadmin:fpm-alpine
    container_name: pma_php
    volumes:
      - ./phpmyadmin/:/var/www/html/
      - ./sessions/:/sessions/
    networks:
      - pma_net

First, I want t have a working phpmyadmin, then I want to continue with nginx and mysql. But, I have already trouble with phpmyadmin. This image seems not to install any phpmyadmin php stuff. After /usr/local/bin/docker-compose up -d and /usr/local/bin/docker-compose exec pma_php /bin/bash I look into the folder /var/www/html and it is completely empty. There is some /usr/src/php.tar.xz but has not been extracted.

For me it seems, the Dockerfile (https://github.com/phpmyadmin/docker/blob/master/fpm-alpine/Dockerfile) is not executed at all.

Can someone give some ideas on that?

FYI, output of /usr/local/bin/docker-compose up is this

Pulling phpmyadmin (phpmyadmin/phpmyadmin:fpm-alpine)...
fpm-alpine: Pulling from phpmyadmin/phpmyadmin
df20fa9351a1: Already exists
b358d6dbbdff: Already exists
0232d962484c: Already exists
0c1d3ac04d2a: Already exists
21e2be1d2e71: Pull complete
a715280c3b40: Pull complete
4fa736fe3036: Pull complete
4808dd45a24b: Pull complete
591d728477bc: Pull complete
5c38ac758dc8: Pull complete
a71b4a25891a: Pull complete
de76418f19c8: Pull complete
c65c697332bd: Pull complete
f0c6a339d37c: Pull complete
ac061b372d71: Pull complete
ee55b41a276b: Pull complete
Digest: sha256:b83b55bdef2c17d9eb18c697ddb0dd309f61a9e3fecc700ac8c5d861b1fcd2c2
Status: Downloaded newer image for phpmyadmin/phpmyadmin:fpm-alpine
Creating phpmyadmin ... done
Attaching to phpmyadmin
phpmyadmin    | [30-Aug-2020 16:04:16] NOTICE: fpm is running, pid 1
phpmyadmin    | [30-Aug-2020 16:04:16] NOTICE: ready to handle connections
pzystorm commented 4 years ago

Argh... the problematic line is:

    volumes:
      - ./phpmyadmin/:/var/www/html/

without that line, phpmyadmin is being extracted and inside /var/www/html/ So, it seems, the mount of that directory is later than the Dockerfile RUN scripts are executed and downloading and extracting phpmyadmin. Is there any solution for that?

williamdes commented 4 years ago

Maybe changing the nginx config block? Why do you want to have a volume?

pzystorm commented 4 years ago

Maybe changing the nginx config block? Why do you want to have a volume?

a seperate nginx container and this phpmyadmin-fpm container need to share the document root with the phmyadmin contents, otherwise it will not work. fpm can only serve php files, so nginx need to handle css/js/html files (all other stuff)

williamdes commented 4 years ago

I would suggest you to have a look to the configuration of @woosungchoi https://github.com/phpmyadmin/docker/issues/299#issuecomment-679214555

pzystorm commented 4 years ago

it's the same. because of the volume (which is mounted when starting and not when building), the folder /var/www/html is empty at first startup

    volumes:
      - phpmyadmin:/var/www/html

The container itself is ok. So the only thing to do is to rerun the steps from the Dockerfile: https://github.com/phpmyadmin/docker/blob/master/fpm-alpine/Dockerfile#L78-L101

williamdes commented 4 years ago

I understand, you are talking about https://github.com/phpmyadmin/docker/issues/284#issuecomment-685176901 on https://github.com/phpmyadmin/docker/pull/285

pzystorm commented 4 years ago

Please have a look f.ex. at the nextcloud project and get some ideas there. They are doing all the magic inside the docker-entrypoint.sh file: First extracting the source files to /usr/src/nextcloud and then doing some rsync to /var/www/html https://github.com/nextcloud/docker/blob/master/docker-entrypoint.sh

You could do the same. There is no need to do all the magic inside the Dockerfile :)

williamdes commented 4 years ago

Hi @pzystorm Could you open a pull-request here so we can discuss and review the change you need please?

osteel commented 4 years ago

@pzystorm do you also have an Nginx service in your docker-compose.yml file, that is using the same phpmyadmin volume?

If that is the case, it's possible that the Nginx container is the first to start, initialising the volume as an empty folder. If you make sure the phpMyAdmin container starts first with depends_on, that might fix your issue:

version: "3.7"

networks:
  pma_net:

services:

  nginx:
    ...
    volumes:
      - ./phpmyadmin/:...
    ...
    depends_on:
      - pma_php

  pma_php:
    image: phpmyadmin/phpmyadmin:fpm-alpine
    container_name: pma_php
    volumes:
      - ./phpmyadmin/:/var/www/html/
      - ./sessions/:/sessions/
    networks:
      - pma_net
capitalfuse commented 3 years ago

Working correctly phpmyadmin-fpm container with nginx container, if volumes sections of these are set to "phpmyadmin: /var/www/html" (NOT ./phpmyadmin: /var/www/html). But in advance, need to create the external volume by the following command: "$ docker volume create --name=phpmyadmin".

SergeShkurko commented 3 years ago

Site located at /* and phpmyadmin located at /phpmyadmin phpMyAdmin location /var/www/html/ reqired other site can be located at /var/www/site_name

I resolve problem with same configs:

version: '3.9'

volumes:
  phpmyadmin_data:

services:
  web:
    image: nginx:alpine
    container_name: 'hostinpl-web'
    ports:
      - '${HOST_MACHINE_UNSECURE_HOST_PORT}:80'
      - '${HOST_MACHINE_SECURE_HOST_PORT}:443'
    working_dir: /var/www/
    volumes:
      - phpmyadmin_data:/var/www/html/ # target pma location at html dir required!
      - ./:/var/www/panel/ # another site should be located in /var/www
      - ${PHP_STORAGE_DIR-./docker/data/php}:/var/www/storage
      - ./docker/config/nginx/nginx.conf:/etc/nginx/nginx.conf:ro
      - ${NGINX_CONFIG-./docker/config/nginx/default.conf}:/etc/nginx/conf.d/default.conf:ro
      - ${NGINX_LOG_DIR-./docker/logs/nginx}:/var/log/nginx/
    depends_on:
      - php
      - phpmyadmin
  php:
    build: 
      context: .
      dockerfile: ./docker/bin/php/Dockerfile # php:7.4.14-fpm
    container_name: 'hostinpl-php'
    working_dir: /var/www/panel/
    depends_on:
      - database
    volumes: 
      - ./:/var/www/panel/ # another site location
      - /var/www/panel/vendor/
      - ${PHP_STORAGE_DIR-./docker/data/php}:/var/www/storage
      - ${PHP_INI-./docker/config/php/php.ini}:/usr/local/etc/php/php.ini
      - ${PHP_LOG_DIR-./docker/logs/php}:/var/log/php
  database:
    image: mariadb:10.3
    command: --default-authentication-plugin=mysql_native_password --character-set-server=utf8 --collation-server=utf8_general_ci
    container_name: 'hostinpl-database'
    ports:
      - '127.0.0.1:${HOST_MACHINE_MYSQL_PORT}:3306'
    volumes: 
      - ${MYSQL_DATA_DIR-./docker/data/mysql}:/var/lib/mysql
      - ${MYSQL_LOG_DIR-./docker/logs/mysql}:/var/log/mysql
      - ${MYSQL_DUMP-./docker/dump.sql}:/docker-entrypoint-initdb.d/dump.sql
    environment:
      MYSQL_ROOT_PASSWORD: ${MYSQL_ROOT_PASSWORD}
      MYSQL_DATABASE: ${MYSQL_DATABASE}
      MYSQL_USER: ${MYSQL_USER}
      MYSQL_PASSWORD: ${MYSQL_PASSWORD}
  phpmyadmin:
    image: phpmyadmin/phpmyadmin:fpm-alpine
    container_name: 'hostinpl-phpmyadmin'
    depends_on:
      - database
    environment:
      PMA_HOST: database
      PMA_PORT: 3306
      MYSQL_ROOT_PASSWORD: ${MYSQL_ROOT_PASSWORD}
      MYSQL_USER: ${MYSQL_USER}
      MYSQL_PASSWORD: ${MYSQL_PASSWORD}
    volumes: 
      - phpmyadmin_data:/var/www/html/ # target pma location at html dir required!
      - /sessions
      - ${PHP_INI-./docker/config/php/php.ini}:/usr/local/etc/php/conf.d/php-phpmyadmin.ini

default.conf

server {
    error_log  /var/log/nginx/error.log;
    access_log /var/log/nginx/access.log;
    root /var/www/;

    location ^~ /phpmyadmin/ {
        gzip_static on;
        alias /var/www/html/;
        index index.php;

        location ~ \.php$ {
            try_files $uri = 404;
            fastcgi_pass phpmyadmin:9000;
            include fastcgi_params;
            fastcgi_param SCRIPT_FILENAME $request_filename;
            fastcgi_param SCRIPT_NAME $fastcgi_script_name;
            fastcgi_param PATH_INFO $fastcgi_path_info;
        }
    }

    location / {
        gzip_static on;
        root /var/www/panel/public/;
        index index.php;
    try_files $uri $uri/ /index.php$is_args$args; 

        location ~ \.php$ {
            fastcgi_pass php:9000;
            include fastcgi_params;
            fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
            fastcgi_param SCRIPT_NAME $fastcgi_script_name;
            fastcgi_param PATH_INFO $fastcgi_path_info;
        }
    }

    location /storage {
        alias /var/www/storage/;
    }
}
gitown commented 3 years ago

when I run my docker compose file I'm getting this weird rendering of phpmyadmin:fpm-alpine, I tried different web browsers and clearing the cache but the issue is the same: image

Here is my docker-compose.yml:

version: "3.9"

services:
  aspnetcoreapp:
    container_name: aspnetcoreapp
    build:
      context: ./aspnetcoreapp
      dockerfile: Dockerfile
    expose:
      - "5080"
    restart: always
    depends_on:
      - mysql
    networks:
      - mynet

  nginx:
    container_name: nginx
    build:
      context: ./nginx
      dockerfile: Dockerfile
    volumes:
      - ./src:/var/www/php:ro
      - phpmyadmin_data:/var/www/html/:ro
    restart: always
    ports:
      - "60000:8282"
      - "60001:8383"
    depends_on:
      - aspnetcoreapp
      - phpmyadmin
      - mysql
    networks:
      - mynet

  mysql:
    container_name: mysql
    image: mysql:8.0.26
    restart: always
    environment:
      MYSQL_ROOT_PASSWORD: rootPass
      MYSQL_DATABASE: demoHello
    volumes:
      - sql_data:/var/lib/mysql
    ports:
      - 42333:3306
    networks:
      - mynet

  phpmyadmin:
    container_name: phpmyadmin
    image: phpmyadmin/phpmyadmin:fpm-alpine
    restart: always
    environment:
      PMA_USER: root
      PMA_PASSWORD: rootPass
      PMA_HOST: mysql
      MYSQL_ROOT_PASSWORD: rootPass
    expose:
      - "9000"
    depends_on:
      - mysql
    volumes:
      - phpmyadmin_data:/var/www/html/
    networks:
      - mynet

volumes:
  sql_data:
  phpmyadmin_data:

networks:
  mynet:
    driver: bridge

And my Nginx Dockerfile:

FROM nginx:1.21-alpine AS base

ENV TERM xterm
RUN apk update && apk add vim

WORKDIR /
COPY nginx.conf /etc/nginx/nginx.conf

And finally my nginx.conf:

worker_processes 5;

events { worker_connections 1024; }

http {
    sendfile on;

    upstream docker_aspnetcoreapp {
        server aspnetcoreapp:5080;
    }

    server {
        listen 8282;
        # server_name www.domain.com;
        location / {
            proxy_pass http://docker_aspnetcoreapp;
        }
    }

    resolver 127.0.0.11 valid=15s;

    server {
        listen 8383;
        #server_name williamdes.local default_server;
        root /var/www/html/;
        index index.php index.html index.htm;
        set $upstream phpmyadmin:9000;

        location ^~ /pma {
            rewrite /pma/(.*) /$1 last;
            try_files $uri = 404;
            fastcgi_pass $upstream;
            fastcgi_index index.php;
            include fastcgi_params;
            fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
            fastcgi_param PATH_INFO $fastcgi_path_info;
        }

        location ~ \.php$ {
            try_files $uri = 404;
            fastcgi_pass $upstream;
            fastcgi_index index.php;
            include fastcgi_params;
            fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
            fastcgi_param PATH_INFO $fastcgi_path_info;
        }
    }
}

Any idea what's causing this issue?

#

williamdes commented 3 years ago

Any idea what's causing this issue?

Since you are using the config I made, it should work. It could be the contents of the volume. Could you check the contents of the volume ? js/dist folder should exist and each theme should have css files in the css folder

gitown commented 3 years ago

Any idea what's causing this issue?

Since you are using the config I made, it should work. It could be the contents of the volume. Could you check the contents of the volume ? js/dist folder should exist and each theme should have css files in the css folder

Hi William, I found how to fix this, I just have to add this line to the http block in the nginx.conf file: include /etc/nginx/mime.types;