Skip to content

Instantly share code, notes, and snippets.

@alexeylozenko
Forked from Fabricio20/ReadMe.md
Created July 17, 2019 09:51
Show Gist options
  • Save alexeylozenko/fb2acdf59034848f633bd67068353eeb to your computer and use it in GitHub Desktop.
Save alexeylozenko/fb2acdf59034848f633bd67068353eeb 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"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment