Skip to content
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

upp #97

Open
wants to merge 6 commits into
base: master
Choose a base branch
from
Open

upp #97

Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
37 changes: 31 additions & 6 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,23 @@
# WPDC - WordPress Docker Compose

## 1. set env

```sh
cp env.example .env
```

## 2. run locally

```sh
docker compose -f docker-compose-local.yml up --build -d
```

## 3. run in production

```sh
docker compose -f docker-compose-production.yml up --build -d
```

Easy WordPress development with Docker and Docker Compose.

With this project you can quickly run the following:
Expand All @@ -19,9 +37,12 @@ Contents:

Make sure you have the latest versions of **Docker** and **Docker Compose** installed on your machine.

Clone this repository or copy the files from this repository into a new folder. In the **docker-compose.yml** file you may change the IP address (in case you run multiple containers) or the database from MySQL to MariaDB.
Clone this repository or copy the files from this repository into a new folder. In the **docker-compose.yml** file you
may change the IP address (in case you run multiple containers) or the database from MySQL to MariaDB.

Make sure to [add your user to the `docker` group](https://docs.docker.com/install/linux/linux-postinstall/#manage-docker-as-a-non-root-user) when using Linux.
Make sure
to [add your user to the `docker` group](https://docs.docker.com/install/linux/linux-postinstall/#manage-docker-as-a-non-root-user)
when using Linux.

## Configuration

Expand All @@ -46,15 +67,17 @@ This creates two new folders next to your `docker-compose.yml` file.
* `wp-data` – used to store and restore database dumps
* `wp-app` – the location of your WordPress application

The containers are now built and running. You should be able to access the WordPress installation with the configured IP in the browser address. By default it is `http://127.0.0.1`.
The containers are now built and running. You should be able to access the WordPress installation with the configured IP
in the browser address. By default it is `http://127.0.0.1`.

For convenience you may add a new entry into your hosts file.

## Usage

### Starting containers

You can start the containers with the `up` command in daemon mode (by adding `-d` as an argument) or by using the `start` command:
You can start the containers with the `up` command in daemon mode (by adding `-d` as an argument) or by using
the `start` command:

```
docker-compose start
Expand Down Expand Up @@ -93,7 +116,8 @@ You can now use the `up` command:
docker-compose up
```

This will create the containers and populate the database with the given dump. You may set your host entry and change it in the database, or you simply overwrite it in `wp-config.php` by adding:
This will create the containers and populate the database with the given dump. You may set your host entry and change it
in the database, or you simply overwrite it in `wp-config.php` by adding:

```
define('WP_HOME','http://wp-app.local');
Expand Down Expand Up @@ -126,7 +150,8 @@ volumes:

### WP CLI

The docker compose configuration also provides a service for using the [WordPress CLI](https://developer.wordpress.org/cli/commands/).
The docker compose configuration also provides a service for using
the [WordPress CLI](https://developer.wordpress.org/cli/commands/).

Sample command to install WordPress:

Expand Down
27 changes: 16 additions & 11 deletions docker-compose.yml → docker-compose-local.yml
Original file line number Diff line number Diff line change
@@ -1,10 +1,12 @@
version: '3'
version: "3"

services:
wp:
image: wordpress:latest # https://hub.docker.com/_/wordpress/
#platform: linux/x86_64 # Uncomment if your machine is running on arm (ex: Apple Silicon processor)
restart: always
ports:
- ${IP}:${PORT}:80 # change ip if required
- ${PORT}:80 # change ip if required
volumes:
- ./config/php.conf.ini:/usr/local/etc/php/conf.d/conf.ini
- ./wp-app:/var/www/html # Full wordpress project
Expand All @@ -22,6 +24,7 @@ services:

wpcli:
image: wordpress:cli
#platform: linux/x86_64 # Uncomment if your machine is running on arm (ex: Apple Silicon processor)
volumes:
- ./config/php.conf.ini:/usr/local/etc/php/conf.d/conf.ini
- ./wp-app:/var/www/html
Expand All @@ -35,28 +38,30 @@ services:
- wp

pma:
image: phpmyadmin:latest # https://hub.docker.com/_/phpmyadmin
image: phpmyadmin:latest # https://hub.docker.com/_/phpmyadmin
#platform: linux/x86_64 # Uncomment if your machine is running on arm (ex: Apple Silicon processor)
environment:
# https://docs.phpmyadmin.net/en/latest/setup.html#docker-environment-variables
PMA_HOST: db
PMA_PORT: 3306
MYSQL_ROOT_PASSWORD: "${DB_ROOT_PASSWORD}"
UPLOAD_LIMIT: 50M
ports:
- ${IP}:8080:80
- 8080:80
links:
- db:db

db:
image: mysql:latest # https://hub.docker.com/_/mysql/ - or mariadb https://hub.docker.com/_/mariadb
# platform: linux/x86_64 # Uncomment if your machine is running on arm (ex: Apple Silicon processor)
#platform: linux/x86_64 # Uncomment if your machine is running on arm (ex: Apple Silicon processor)
ports:
- ${IP}:3306:3306 # change ip if required
command: [
'--default_authentication_plugin=mysql_native_password',
'--character-set-server=utf8mb4',
'--collation-server=utf8mb4_unicode_ci'
]
- 3306:3306 # change ip if required
command:
[
"--default_authentication_plugin=mysql_native_password",
"--character-set-server=utf8mb4",
"--collation-server=utf8mb4_unicode_ci",
]
volumes:
- ./wp-data:/docker-entrypoint-initdb.d
- db_data:/var/lib/mysql
Expand Down
113 changes: 113 additions & 0 deletions docker-compose-production.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,113 @@
version: "3"

services:
web:
image: nginx
depends_on:
- wp
restart: always
volumes:
#
# Import our Nginx configuration for FPM.
#
- ./nginx.conf:/etc/nginx/conf.d/default.conf
#
# The webserver will also need to see our Wordpress install.
#
- ./wp-app:/var/www/html
#
# Write logs here. Note that they will need to be
# rotated on the parent system.
#
- ./logs:/var/log/nginx
https-portal:
image: steveltn/https-portal:1
depends_on:
- web
ports:
- 80:80
- 443:443
restart: always
#
# Save our SSL certs between runs so they aren't regenerated on every single run.
#
volumes:
- ./ssl_certs:/var/lib/https-portal
environment:
DOMAINS: "abc.com -> http://web:80 #production"
#DOMAINS: 'YOUR_FQDN -> http://web:80 #staging' # Uncomment when you want to test a staging cert.
#DOMAINS: 'YOUR_FQDN -> http://web:80 #production' # Uncomment when you are ready for production.
#
# Allow larger files to be uploaded
#
CLIENT_MAX_BODY_SIZE: 64M
wp:
image: wordpress:php8.2-fpm # https://hub.docker.com/_/wordpress/
#platform: linux/x86_64 # Uncomment if your machine is running on arm (ex: Apple Silicon processor)
restart: always
# ports:
# - ${PORT}:80 # change ip if required
volumes:
- ./config/php.conf.ini:/usr/local/etc/php/conf.d/conf.ini
- ./wp-app:/var/www/html # Full wordpress project
#- ./plugin-name/trunk/:/var/www/html/wp-content/plugins/plugin-name # Plugin development
#- ./theme-name/trunk/:/var/www/html/wp-content/themes/theme-name # Theme development
environment:
WORDPRESS_DB_HOST: db
WORDPRESS_DB_NAME: "${DB_NAME}"
WORDPRESS_DB_USER: root
WORDPRESS_DB_PASSWORD: "${DB_ROOT_PASSWORD}"
depends_on:
- db
links:
- db

wpcli:
image: wordpress:cli
#platform: linux/x86_64 # Uncomment if your machine is running on arm (ex: Apple Silicon processor)
volumes:
- ./config/php.conf.ini:/usr/local/etc/php/conf.d/conf.ini
- ./wp-app:/var/www/html
environment:
WORDPRESS_DB_HOST: db
WORDPRESS_DB_NAME: "${DB_NAME}"
WORDPRESS_DB_USER: root
WORDPRESS_DB_PASSWORD: "${DB_ROOT_PASSWORD}"
depends_on:
- db
- wp

pma:
image: phpmyadmin:latest # https://hub.docker.com/_/phpmyadmin
#platform: linux/x86_64 # Uncomment if your machine is running on arm (ex: Apple Silicon processor)
environment:
# https://docs.phpmyadmin.net/en/latest/setup.html#docker-environment-variables
PMA_HOST: db
PMA_PORT: 3306
MYSQL_ROOT_PASSWORD: "${DB_ROOT_PASSWORD}"
UPLOAD_LIMIT: 50M
ports:
- 8080:80
links:
- db:db

db:
image: mysql:latest # https://hub.docker.com/_/mysql/ - or mariadb https://hub.docker.com/_/mariadb
#platform: linux/x86_64 # Uncomment if your machine is running on arm (ex: Apple Silicon processor)
ports:
- 3306:3306 # change ip if required
command:
[
"--default_authentication_plugin=mysql_native_password",
"--character-set-server=utf8mb4",
"--collation-server=utf8mb4_unicode_ci",
]
volumes:
- ./wp-data:/docker-entrypoint-initdb.d
- db_data:/var/lib/mysql
environment:
MYSQL_DATABASE: "${DB_NAME}"
MYSQL_ROOT_PASSWORD: "${DB_ROOT_PASSWORD}"

volumes:
db_data:
1 change: 0 additions & 1 deletion env.example
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
IP=127.0.0.1
PORT=80
DB_ROOT_PASSWORD=password
DB_NAME=wordpress
28 changes: 28 additions & 0 deletions nginx.conf
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
server {
listen 80;

root /var/www/html;
index index.php;

access_log /var/log/nginx/access.log;
error_log /var/log/nginx/error.log;

#
# Allow larger file uploads
#
client_max_body_size 64M;

location / {
try_files $uri $uri/ /index.php?$args;
}

location ~ \.php$ {
try_files $uri =404;
fastcgi_split_path_info ^(.+\.php)(/.+)$;
fastcgi_pass wp:9000;
fastcgi_index index.php;
include fastcgi_params;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
fastcgi_param PATH_INFO $fastcgi_path_info;
}
}