Skip to content

Instantly share code, notes, and snippets.

@Fabricio20
Last active November 7, 2023 04:37
Show Gist options
  • Star 23 You must be signed in to star a gist
  • Fork 4 You must be signed in to fork a gist
  • Save Fabricio20/32b553e29f3c087d445eb1cc4f6260e8 to your computer and use it in GitHub Desktop.
Save Fabricio20/32b553e29f3c087d445eb1cc4f6260e8 to your computer and use it in GitHub Desktop.
Docker - Nginx + PHP FPM + MariaDB + PhpMyAdmin

Docker

This is a docker-compose template for a lemp stack.

Make sure to change both the root password under the mysql service, and the absolute URI on the phpmyadmin container.
You can also expose phpMyAdmin locally instead of remotely by properly configuring the ports.

Default locations:
(Original) -> (Your server)
/var/www/html -> ./webroot
/etc/nginx -> ./nginx
/etc/nginx/sites-enabled -> ./nginx/sites-enabled
/var/lib/mysql -> ./mariadb (MariaDB Disk Storage)
/sessions -> ./phpmyadmin/sessions (phpMyAdmin session storage)

Don't forget! -> To use phpMyAdmin behind the nginx container, you need to configure a proxy-pass entry on it.

nginx proxy_pass example:

server {
        listen 80;
        listen [::]:80;
        listen 443 ssl;
        listen [::]:443 ssl;
        server_name phpmyadmin.your.domain;
        location / {
                proxy_set_header    Host $host;
                proxy_set_header    X-Real-IP $remote_addr;
                proxy_set_header    X-Forwarded-For $proxy_add_x_forwarded_for;
                proxy_set_header    X-Forwarded-Proto $scheme;
                proxy_pass          http://phpmyadmin/; #! phpmyadmin is the docker host !
                proxy_read_timeout  90;
        }
}
version: '3.2'
services:
nginx:
image: richarvey/nginx-php-fpm:latest
container_name: nginx
restart: always
ports:
- "80:80"
volumes:
- "./nginx/:/etc/nginx"
- "./webroot/:/var/www/html"
external_links:
- mariadb:mariadb
- phpmyadmin:phpmyadmin
mariadb:
image: mariadb
container_name: mariadb
restart: always
environment:
MYSQL_ROOT_PASSWORD: your_sql_root_password
volumes:
- "./mariadb/:/var/lib/mysql"
phpmyadmin:
image: phpmyadmin/phpmyadmin
container_name: phpMyAdmin
restart: always
environment:
- "PMA_HOST=mariadb"
- "PMA_PORT=3306"
- "PMA_ABSOLUTE_URI=https://phpmyadmin.your.domain"
external_links:
- mariadb:mariadb
volumes:
- "./phpmyadmin/sessions:/sessions"
@xf-
Copy link

xf- commented May 30, 2020

why not use the fpm version or fpm-alpine instead of apache webserver phpmyadmin?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment