Skip to content

Installing WordPress on Amazon EC2 Ubuntu 18.04 using Docker Compose

License

Notifications You must be signed in to change notification settings

alantanlc/wordpress-docker-ec2

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

51 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Installing WordPress on Amazon Elastic Compute Cloud (Amazon EC2) Ubuntu 18.04 using Docker Compose

There are three main ways to host your own WordPress website on AWS according to the best practices:

  1. Amazon Lightsail (Recommended)
  2. Amazon Elastic Compute Cloud (Amazon EC2)
  3. AWS Marketplace

There are also different ways to install WordPress on a Ubuntu machine (non-exhaustive):

  1. Manually set up WordPress with LAMP stack like this or this or this
  2. Using containers (e.g. Docker and Docker Compose) like this
  3. Using infrastructure as code tools (e.g. Terraform, Ansible) like this

This guide covers the steps to host a WordPress on a Amazon Elastic Compute Cloud (Amazon EC2) Ubuntu 18.04 machine using Docker Compose. You can use Docker Compose to easily run WordPress in an isolated environment built with Docker containers.

Connecting to the AWS EC2 instance

Prepare private key on your local machine

The private key (a .pem file) that corresponds to your AWS EC2 instance is required in order to connect to your instance using SSH to perform the WordPress installation. If you do not have the private key, please check with your instance provider.

Extract the private key from the zipped file. Note that it is not '-x', there is no space between the option '-p' and the password for the 7z command. Replace PASSWORD with the password for the zipped file.

$ sudo apt-get install p7zip-full
$ 7z x -pPASSWORD devops-test.pvt.zip
$ mv devops-test.pvt.key devops-test.pem
$ chmod 400 devops-test.pem

Connect to your AWS EC2 instance using SSH

$ ssh -i devops-test.pem devops-test@ec2-54-255-184-141.ap-southeast-1.compute.amazonaws.com

Installing Docker Engine and Docker Compose

If the instance already has Docker Engine and Docker Compose installed, you can skip to Setting up the WordPress project.

Update software repositories and packages

$ sudo apt-get update
$ sudo apt-get upgrade

Install Docker Engine

This sets up the Docker repository and installs the latest version of Docker Engine and containerd.

$ sudo apt-get remove docker docker-engine docker.io containerd runc
$ sudo apt-get install apt-transport-https ca-certificates curl gnupg-agent software-properties-common
$ curl -fsSL https://download.docker.com/linux/ubuntu/gpg | sudo apt-key add -
$ sudo add-apt-repository "deb [arch=amd64] https://download.docker.com/linux/ubuntu $(lsb_release -cs) stable"
$ sudo apt-get update
$ sudo apt-get install docker-ce docker-ce-cli containerd.io

Verify that Docker Engine is installed correctly by running the hello-world image.

$ sudo docker run hello-world

For more information on installing, uninstalling and upgrading Docker Engine, check out the official installation guide.

Install Docker Compose

This downloads the current stable release of Docker Compose binary from the Compose repository release page on GitHub.

$ sudo curl -L "https://github.com/docker/compose/releases/download/1.26.0/docker-compose-$(uname -s)-$(uname -m)" -o /usr/local/bin/docker-compose
$ sudo chmod +x /usr/local/bin/docker-compose
$ sudo ln -s /usr/local/bin/docker-compose /usr/bin/docker-compose

Test the installation.

$ sudo docker-compose --version
docker-compose version 1.26.0, build 1110ad01

For more information on installing, uninstalling and upgrading Docker Compose, check out the official installation guide.

Setting up the WordPress project

Clone this repository on your instance

$ git clone https://gitlab.com/alanwuha/wordpress.git
$ cd wordpress

Update configuration in docker-compose.yml in the wordpress directory

Update docker-compose.yml with the credentials (e.g. database name and passwords) specific to your environment using an editor before building the project.

If you are unsure about the necessary changes, please contact the writer of this guide for any clarification.

Building the WordPress project

Run the following command from the wordpress directory.

$ sudo docker-compose up -d

This runs sudo docker-compose up in detached mode, pulls the needed Docker images, and starts the containers.

Containers:

Setting Up WordPress

Navigate to http://54.255.184.141:80 and complete the "famous five-minute installation" as a WordPress administrator.

Setting Up Grafana

Navigate to http://54.255.184.141:443 and login with user admin password admin.

1. Add Prometheus as data source

Go to Configure > Data Sources and add Prometheus as a data source. Fill in the URL input with prometheus:9090 and click on Save & Test. If successful, it should return Data source is working.

2. Add dashboards

Go to Create > Import and import the following dashboards one by one using the steps below:

  • 1860 (Node Exporter Full)
  • 7362 (MySQL Overview)
  • 893 (Docker and system monitoring)

Under Import via grafana.com, fill in the dashboard id (e.g. 1860) and click Load. Select 'Prometheus' under the Prometheus dropdown and then click Import:

Shutting down and cleaning up

Remove the containers and default network, but preserve your WordPress database.

$ sudo docker-compose down

Remove the containers, default network, and the WordPress database. DO THIS WITH CAUTION AS YOUR DATA WILL BE ERASED.

$ sudo docker-compose down --volumes

Monitoring Test

Instance Down

$ sudo docker stop <CONTAINER ID>

High Storage Load

$ fallocate -l 10G dummy.img

Assumptions

This is a standalone application with wordpress, database, and monitoring tools installed on the same AWS EC2 instance.

References

  1. Best Practices for WordPress on AWS
  2. Install Docker Engine on Ubuntu
  3. Install Docker Compose on Ubuntu
  4. Docker for Beginners: Full Course
  5. Quickstart: Compose and WordPress
  6. Docker image: WordPress
  7. Docker image: MySQL
  8. Docker image: PhpMyAdmin
  9. Docker image: Prometheus
  10. Docker image: Grafana
  11. Docker image: Node Exporter
  12. Docker image: Mysqld Export
  13. Docker image: Alertmanager
  14. Prometheus Docker Installation Guide
  15. Quick Wordpress Setup with Docker
  16. Monitoring Amazon EC2
  17. Dockprom - A monitoring solution for Docker hosts and containers
  18. Setting up Prometheus and Grafana for monitoring your servers
  19. Step-by-step guide to setting up Prometheus Alertmanager with Slack, PagerDuty, and Gmail
  20. Dockprom alert rules
  21. Save your Grafana data to Docker volume
  22. Docker Data Volume Container pattern

About

Installing WordPress on Amazon EC2 Ubuntu 18.04 using Docker Compose

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages