├── .github └── FUNDING.yml ├── .gitignore ├── README.md ├── docker-compose.yml ├── nginx.conf ├── php-uploads.ini └── reset.sh /.github/FUNDING.yml: -------------------------------------------------------------------------------- 1 | # These are supported funding model platforms 2 | 3 | github: dmuth 4 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | 2 | # 3 | # Don't check these in. 4 | # 5 | data/ 6 | logs/ 7 | wordpress/ 8 | ssl_certs/ 9 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # Install Wordpress in Docker with Nginx and Lets Encrypt for HTTPS 2 | 3 | Wow, that was a mouthful. But yeah, that's what this repo does. 4 | 5 | To get started, after you clone this repo, run `docker-compose up -d` and then visit http://localhost/. 6 | 7 | If you are running this on a production server, you'll want to tweak the server name in 8 | the HTTPS-Portal section of `docker-compose.yml` accordingly. 9 | 10 | This repo is supporting material for the blog post at https://wp.dmuth.org/wordpress-5-in-docker-with-nginx-and-letsencrypt/ 11 | 12 | 13 | 14 | -------------------------------------------------------------------------------- /docker-compose.yml: -------------------------------------------------------------------------------- 1 | 2 | version: '3.3' 3 | 4 | services: 5 | 6 | db: 7 | image: mysql:5.7 8 | restart: always 9 | volumes: 10 | # 11 | # Persist our MySQL data 12 | # 13 | - ./data:/var/lib/mysql 14 | environment: 15 | MYSQL_ROOT_PASSWORD: wordpressrootpw 16 | MYSQL_DATABASE: wordpress 17 | MYSQL_USER: wordpress 18 | MYSQL_PASSWORD: wordpress 19 | 20 | # 21 | # PHP FPM runs persistently, and services requests over port 9000 22 | # from our webserver. 23 | # 24 | php: 25 | image: wordpress:5-fpm 26 | depends_on: 27 | - db 28 | restart: always 29 | volumes: 30 | # 31 | # Copy in our PHP config for large uploads. 32 | # 33 | - ./php-uploads.ini:/usr/local/etc/php/conf.d/uploads.ini 34 | # 35 | # When first run, this image populates /var/www/html/ with a Wordpress install, 36 | # and we want that to be exported so we have a copy of our code. 37 | # 38 | - ./wordpress:/var/www/html 39 | environment: 40 | WORDPRESS_DB_HOST: db:3306 41 | WORDPRESS_DB_USER: wordpress 42 | WORDPRESS_DB_PASSWORD: wordpress 43 | 44 | web: 45 | image: nginx 46 | depends_on: 47 | - php 48 | restart: always 49 | volumes: 50 | # 51 | # Import our Nginx configuration for FPM. 52 | # 53 | - ./nginx.conf:/etc/nginx/conf.d/default.conf 54 | # 55 | # The webserver will also need to see our Wordpress install. 56 | # 57 | - ./wordpress:/var/www/html 58 | # 59 | # Write logs here. Note that they will need to be 60 | # rotated on the parent system. 61 | # 62 | - ./logs:/var/log/nginx 63 | 64 | 65 | https-portal: 66 | image: steveltn/https-portal:1 67 | depends_on: 68 | - web 69 | ports: 70 | - 80:80 71 | - 443:443 72 | restart: always 73 | # 74 | # Save our SSL certs between runs so they aren't regenerated on every single run. 75 | # 76 | volumes: 77 | - ./ssl_certs:/var/lib/https-portal 78 | environment: 79 | DOMAINS: 'localhost -> http://web:80 #local' 80 | #DOMAINS: 'YOUR_FQDN -> http://web:80 #staging' # Uncomment when you want to test a staging cert. 81 | #DOMAINS: 'YOUR_FQDN -> http://web:80 #production' # Uncomment when you are ready for production. 82 | # 83 | # Allow larger files to be uploaded 84 | # 85 | CLIENT_MAX_BODY_SIZE: 64M 86 | 87 | 88 | -------------------------------------------------------------------------------- /nginx.conf: -------------------------------------------------------------------------------- 1 | 2 | server { 3 | listen 80; 4 | 5 | root /var/www/html; 6 | index index.php; 7 | 8 | access_log /var/log/nginx/access.log; 9 | error_log /var/log/nginx/error.log; 10 | 11 | # 12 | # Allow larger file uploads 13 | # 14 | client_max_body_size 64M; 15 | 16 | location / { 17 | try_files $uri $uri/ /index.php?$args; 18 | } 19 | 20 | location ~ \.php$ { 21 | try_files $uri =404; 22 | fastcgi_split_path_info ^(.+\.php)(/.+)$; 23 | fastcgi_pass php:9000; 24 | fastcgi_index index.php; 25 | include fastcgi_params; 26 | fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name; 27 | fastcgi_param PATH_INFO $fastcgi_path_info; 28 | } 29 | } 30 | 31 | -------------------------------------------------------------------------------- /php-uploads.ini: -------------------------------------------------------------------------------- 1 | 2 | # 3 | # Allow larger file uploads 4 | # 5 | file_uploads = On 6 | memory_limit = 64M 7 | upload_max_filesize = 64M 8 | post_max_size = 64M 9 | max_execution_time = 600 10 | 11 | -------------------------------------------------------------------------------- /reset.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | # 3 | # Reset our setup so that we can start over from scratch. 4 | # 5 | 6 | # Errors are fatal 7 | set -e 8 | 9 | 10 | echo "# " 11 | echo "# Stopping and removing containers..." 12 | echo "# " 13 | docker-compose kill 14 | docker-compose rm -f 15 | 16 | echo "# " 17 | echo "# Removing database, wordpress, and logs..." 18 | echo "# " 19 | # 20 | # I made a conscious decision to leave ssl_certs/ untouched, as it can 21 | # take 10s of seconds to generate them, and I don't want users to have 22 | # to wait through that on every single iteration, especially for development purposes. 23 | # 24 | rm -rf data/ logs/ wordpress/ 25 | 26 | 27 | --------------------------------------------------------------------------------