-
Notifications
You must be signed in to change notification settings - Fork 454
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
[Question] Serving fpm-alpine image with nginx #253
Comments
@lonix1 try port If it does not work comment back here :) |
@williamdes Thanks - yes you are right it should be However, it still does not work :-(
The docker log shows:
|
maybe you should change See: https://github.com/phpmyadmin/docker/blob/master/fpm-alpine/Dockerfile#L77 I assume you have data into the volume https://superuser.com/a/435969/609233 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 |
When I do
That's why I used that path. But even if I use I tried the new Does that actually work for you? I will carry on fiddling to get it working. Maybe we can then add it to the docs. |
Light versionresolver 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 |
Using a proxyresolver 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 CGIThanks 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 |
@williamdes wow thanks! I used the "Using CGI" section, and got it working finally, but on the wrong path:
BTW, I assume your "Using a proxy" section is for the |
I think you are correct on what you assume @lonix1 can you paste your final configuration? I made it work with the |
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 |
@williamdes BTW thanks for taking the time to help me... Appreciated! |
@lonix1 I think it is because all files need to know their base path? |
@williamdes Yes... so we need to correctly set |
@lonix1 please post the config when you have a working example ;) |
@williamdes This works for me:
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
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). |
@lonix1 Thank you ! From what I understand removing If you want to open a pull-request let me know, if not I will do it |
I'm not sure how to do that... what I mean is that maybe the documents site can have this info... |
@lonix1 Does nginx server need to have phpmyadmin volume attached to it? |
@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. |
@lonix1 yes, there is an apache version |
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:
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? |
Hi @ThibaultVlacich Did this work ? |
It... worked... Swear I tried it already but I guess not. Thanks @williamdes. |
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 |
You did not configure correctly the .php file handler IMO |
@williamdes |
@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 ? |
So the |
I download and open with vscode:
|
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. |
@DevSaumyadip I think |
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. 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
|
Argh... the problematic line is: volumes:
- ./phpmyadmin/:/var/www/html/ without that line, phpmyadmin is being extracted and inside /var/www/html/ |
Maybe changing the nginx config block? |
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) |
I would suggest you to have a look to the configuration of @woosungchoi #299 (comment) |
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
The container itself is ok. So the only thing to do is to rerun the steps from the Dockerfile: |
I understand, you are talking about #284 (comment) on #285 |
Please have a look f.ex. at the nextcloud project and get some ideas there. You could do the same. |
Hi @pzystorm |
@pzystorm do you also have an Nginx service in your 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 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 |
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". |
Site located at /* and phpmyadmin located at /phpmyadmin 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/;
}
} |
Since you are using the config I made, it should work. It could be the contents of the volume. |
Hi William, |
Thank you so much for letting me know and anyone searching about this ! |
I am trying to get the
fpm-alpine
image to work with nginx.docker-compose.yml
default.conf
Then:
docker-compose up
.When I access
http://www.example.com/pma
I getI also tried to get it working using a port instead of path, i.e.
http://www.example.com:8080
instead ofhttp://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?
The text was updated successfully, but these errors were encountered: