Deploy a Static WordPress Using AWS & Cloudflare, Part 1: Building a WordPress in Docker

Basic websites are often made in insecure ways with plugins and features available through frameworks like WordPress. A lot of times though, these websites don’t need these features when they go live because they’re just static sites. For example, if you have a portfolio or personal website, it probably doesn’t have any fancy features that require more than HTML and CSS (and maybe a bit of JavaScript).

Despite all its plugins, WordPress has the option to create a static site. This removes all of the security vulnerabilities so instead of deploying WordPress, you’re only deploying the HTML that it generates.

In this series, we’ll go through how to convert WordPress to static files and host them in AWS S3, a secure channel of storing files. To go live with your site on a custom domain, you’ll connect your S3 bucket to Cloudflare, a DNS service which also offers many security features.

To start your WordPress, all you need is a Docker container, which is what we’ll focus on in the first part of this series.

Part 1 – Building a WordPress in Docker

Part 2 – Downloading Your Static WordPress and Deploying to AWS S3

Part 3 – Connecting Your S3 Bucket to Cloudflare


Building a WordPress in Docker

  1. Create an empty project directory.
  2. Change into that directory.
  3. Create a file called docker-compose.yml with the following contents:

      
      version: '3.3'
      
      services:
         db:
           image: mysql:5.7
           volumes:
             - db_data:/var/lib/mysql
           restart: always
           environment:
             MYSQL_ROOT_PASSWORD: somewordpress
             MYSQL_DATABASE: wordpress
             MYSQL_USER: wordpress
             MYSQL_PASSWORD: wordpress
      
         wordpress:
           depends_on:
             - db
           image: wordpress:latest
           ports:
             - "80:80"
           restart: always
           environment:
             WORDPRESS_DB_HOST: db:3306
             WORDPRESS_DB_USER: wordpress
             WORDPRESS_DB_PASSWORD: wordpress
      volumes:
          db_data:
                  

  4. In your project directory, run
    docker-compose up -d.
    • At some point, your WordPress will be accessible at localhost.
    • Go to localhost/wp-admin to start setting up your WordPress.
    • Note: To shut down your docker container run docker-compose down --volumes.
  5. At this point, you’re ready to make changes to your website.

Come back tomorrow to learn how to statically deploy your WordPress to AWS.