first commit

This commit is contained in:
Bernd 2023-12-17 15:00:17 +05:00
commit be98ddfc2e
5 changed files with 148 additions and 0 deletions

5
.env Normal file
View File

@ -0,0 +1,5 @@
APP_NAME=myname
MARIADB_ROOT_PASSWORD=rootpwd
MARIADB_DATABASE=database
MARIADB_USER=db_user
MARIADB_PASSWORD=userpwd

44
README.md Normal file
View File

@ -0,0 +1,44 @@
# Docker Compose LEMP Stack
This repository contains `docker-compose` configuration to start a `LEMP (Linux, Nginx, MariaDB, PHP) + wordpress + phpmyadmin` stack.
## Configuration
The Nginx configuration can be found in `nginx/default.conf`.
You can also set the following environment variables, for example in the included `.env` file:
| Key | Description |
|-----|-------------|
|APP_NAME|The name used when creating a container.|
|MARIADB_ROOT_PASSWORD|The mariaDB root password used when creating the container.|
|MARIADB_DATABASE|Name of the database used by Wordpress.|
|MARIADB_USER|Used by Wordpress.|
|MARIADB_PASSWORD|Used by Wordpress.|
## Usage
##### Clone this repository.
Clone this repository with the following command: `git clone https://github.com/bernd32/lemp-wp-phpmyadmin-docker.git`.
##### Start the server.
Start the server using the following command inside the directory you just cloned: `docker-compose up`.
Docker will now build your containers. Once the process is complete, you can access your WordPress installation at `http://localhost:8082` and your phpMyAdmin at `http://localhost:8084` and wordpress at `http://localhost:8086`.
## Entering the containers
You can use the following command to enter a container:
Where `{CONTAINER_NAME}` is one of:
`docker exec -ti {CONTAINER_NAME} /bin/bash`
* `{APP_NAME}-php`
* `{APP_NAME}-nginx`
* `{APP_NAME}-mariadb`
## Setup secure connections (optional):
If you want to set up SSL for secure connections (HTTPS), you will need to modify your Nginx configuration and possibly use Certbot for a free Let's Encrypt certificate or add your own certificate details.

71
docker-compose.yml Normal file
View File

@ -0,0 +1,71 @@
version: '3'
services:
web:
image: nginx:latest
container_name: ${APP_NAME:?err}-nginx
ports:
- "8082:80"
volumes:
- ./nginx:/etc/nginx/conf.d
depends_on:
- php
- db
restart: on-failure
php:
image: php:fpm
build:
context: ./docker
dockerfile: php.Dockerfile
container_name: ${APP_NAME:?err}-php-fpm
ports:
- 9000:9000
volumes:
- ./wordpress:/var/www/html
environment:
- PHP_EXTENSIONS=mysqli pdo pdo_mysql
depends_on:
- db
db:
image: mariadb:latest
container_name: ${APP_NAME:?err}-mariadb
volumes:
- db_data:/var/lib/mysql
environment:
MYSQL_ROOT_PASSWORD: ${MARIADB_ROOT_PASSWORD:?err}
MYSQL_DATABASE: ${MARIADB_DATABASE:?err}
MYSQL_USER: ${MARIADB_USER:?err}
MYSQL_PASSWORD: ${MARIADB_PASSWORD:?err}
restart: always
phpmyadmin:
image: phpmyadmin/phpmyadmin
container_name: phpmyadmin-container
environment:
PMA_HOST: db
MYSQL_ROOT_PASSWORD: ${MARIADB_ROOT_PASSWORD:?err}
ports:
- '8084:80'
restart: unless-stopped
depends_on:
- db
wordpress:
image: wordpress
container_name: ${APP_NAME:?err}-wordpress
restart: always
ports:
- 8086:80
environment:
WORDPRESS_DB_HOST: db
WORDPRESS_DB_USER: ${MARIADB_USER:?err}
WORDPRESS_DB_PASSWORD: ${MARIADB_PASSWORD:?err}
WORDPRESS_DB_NAME: ${MARIADB_DATABASE:?err}
volumes:
- ./wordpress:/var/www/html
volumes:
db_data:
wordpress:

10
docker/php.Dockerfile Normal file
View File

@ -0,0 +1,10 @@
FROM php:fpm
RUN apt-get update && \
apt-get install -y git zip libxml2-dev
RUN curl --silent --show-error https://getcomposer.org/installer | php && \
mv composer.phar /usr/local/bin/composer
# Uncomment to have mysqli extension installed and enabled
RUN docker-php-ext-install mysqli && docker-php-ext-enable mysqli

18
nginx/default.conf Normal file
View File

@ -0,0 +1,18 @@
server {
listen 80;
index index.php index.html;
server_name _;
error_log /var/log/nginx/error.log;
access_log /var/log/nginx/access.log;
root /var/www/html;
location / {
try_files $uri $uri/ /index.php?$args;
}
location ~ \.php$ {
fastcgi_pass php:9000;
fastcgi_index index.php;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
include fastcgi_params;
}
}