├── .env ├── .gitignore ├── README.md ├── app └── index.php ├── config └── nginx │ └── nginx.conf ├── docker-compose.yml └── docker └── php.Dockerfile /.env: -------------------------------------------------------------------------------- 1 | APP_NAME=myapp 2 | MYSQL_ROOT_PASSWORD=rootpass -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | 2 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # Docker Compose LEMP Stack 2 | 3 | This repository contains a little `docker-compose` configuration to start a `LEMP (Linux, Nginx, MariaDB, PHP)` stack. 4 | 5 | ## Details 6 | 7 | The following versions are used. 8 | 9 | * PHP 7.2 (FPM) - With MySQLi driver optionally (Uncomment line from php.Dockerfile) 10 | * Nginx 1.13.6 11 | * MariaDB 10.3.9 12 | 13 | ## Configuration 14 | 15 | The Nginx configuration can be found in `config/nginx/`. 16 | 17 | You can also set the following environment variables, for example in the included `.env` file: 18 | 19 | | Key | Description | 20 | |-----|-------------| 21 | |APP_NAME|The name used when creating a container.| 22 | |MYSQL_ROOT_PASSWORD|The MySQL root password used when creating the container.| 23 | 24 | ## Usage 25 | 26 | To use it, simply follow the following steps: 27 | 28 | ##### Clone this repository. 29 | 30 | Clone this repository with the following command: `git clone https://github.com/stevenliebregt/docker-compose-lemp-stack.git`. 31 | 32 | ##### Start the server. 33 | 34 | Start the server using the following command inside the directory you just cloned: `docker-compose up`. 35 | 36 | ## Entering the containers 37 | 38 | You can use the following command to enter a container: 39 | 40 | Where `{CONTAINER_NAME}` is one of: 41 | 42 | `docker exec -ti {CONTAINER_NAME} /bin/bash` 43 | 44 | * `{APP_NAME}-php` 45 | * `{APP_NAME}-nginx` 46 | * `{APP_NAME}-mariadb` 47 | -------------------------------------------------------------------------------- /app/index.php: -------------------------------------------------------------------------------- 1 | 10 | 11 | 12 | 13 | 14 | Hello, world! 15 | 21 | 22 | 23 |

Hello, world!

24 |

Your magic numbers are:

25 | 26 | 27 | 28 | 29 | 30 | $number): ?> 31 | 32 | 33 | 34 | 35 | 36 |
#Number
37 |

If you can see this properly, then it means PHP is working fine.

38 | 39 | 40 | -------------------------------------------------------------------------------- /config/nginx/nginx.conf: -------------------------------------------------------------------------------- 1 | server { 2 | index index.php index.html; 3 | server_name localhost; 4 | error_log /var/log/nginx/error.log; 5 | access_log /var/log/nginx/access.log; 6 | root /var/www/html; 7 | 8 | location / { 9 | try_files $uri $uri/ /index.php$is_args$query_string; 10 | fastcgi_split_path_info ^(.+\.php)(/.+)$; 11 | fastcgi_pass php:9000; 12 | fastcgi_index index.php; 13 | include fastcgi_params; 14 | fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name; 15 | fastcgi_param PATH_INFO $fastcgi_path_info; 16 | } 17 | 18 | # Static files 19 | location ~* ^.+\.(jpg|jpeg|gif|css|png|js|ico|svg|html|txt)$ { 20 | access_log off; 21 | expires 30d; 22 | } 23 | } 24 | -------------------------------------------------------------------------------- /docker-compose.yml: -------------------------------------------------------------------------------- 1 | version: '3' 2 | services: 3 | php: 4 | # image: 'php:7.2-fpm' 5 | build: 6 | context: ./docker 7 | dockerfile: php.Dockerfile 8 | container_name: ${APP_NAME:?err}-php 9 | volumes: 10 | - './app:/var/www/html' 11 | depends_on: 12 | - mariadb 13 | 14 | nginx: 15 | image: nginx:latest 16 | container_name: ${APP_NAME:?err}-nginx 17 | ports: 18 | - '80:80' 19 | - '443:443' 20 | links: 21 | - 'php' 22 | volumes: 23 | - './app:/var/www/html' 24 | - './config/nginx:/etc/nginx/conf.d' 25 | 26 | mariadb: 27 | image: mariadb:10.3.9 28 | container_name: ${APP_NAME:?err}-mariadb 29 | restart: 'on-failure' 30 | environment: 31 | MYSQL_ROOT_PASSWORD: ${MYSQL_ROOT_PASSWORD:?err} 32 | volumes: 33 | - ${PWD} 34 | -------------------------------------------------------------------------------- /docker/php.Dockerfile: -------------------------------------------------------------------------------- 1 | FROM php:7.2-fpm 2 | 3 | RUN apt-get update && \ 4 | apt-get install -y git zip 5 | 6 | RUN curl --silent --show-error https://getcomposer.org/installer | php && \ 7 | mv composer.phar /usr/local/bin/composer 8 | 9 | # Uncomment to have mysqli extension installed and enabled 10 | # RUN docker-php-ext-install mysqli && docker-php-ext-enable mysqli 11 | --------------------------------------------------------------------------------