Compute Engine Google Cloud

Docker WordPress Development on Google Cloud with Cloud SQL

Docker WordPress Development on Google Cloud with Cloud SQL. We have covered the details of setting up WP on LEMP stack on Ubuntu 18.04 LTS.

Now, in this tutorial we are going to use EasyEngine to set up WordPress in Docker on Google Cloud and use Cloud SQL for database.

Prerequisites

Make sure you choose Ubuntu 16.04/18.04 or Debian while setting up your Google Compute Engine.

  1. Up and running Compute Engine, see the Setting up Compute Engine Instance.
  2. Domain name is pointed to your virtual machine.
  3. For setting up Cloud DNS, see the Setting up Google Cloud DNS for your domain.
  4. Google Cloud SQL Setup, see Setup Cloud SQL and connect with Compute Engine.

Install EasyEngine

We shall install EasyEngine with the official installer script for Linux. This script will install all dependencies for you.

Go to your Google Cloud Console and navigate to Compute Engine >> VM Instances and SSH to your instance.

Now execute the following commands to install EE v4.

sudo apt update
wget -qO ee rt.cx/ee4 && sudo bash ee

This will take a few minutes to install and setup docker. Once the installation is complete you will receive a confirmation like this below.

+-------------------+-------------------------------------------------------------------------+
| OS | Linux 4.15.0-1026-gcp #27-Ubuntu SMP Thu Dec 6 18:27:01 UTC 2018 x86_64 |
| Shell | /bin/bash |
| PHP binary | /usr/bin/php7.2 |
| PHP version | 7.2.13-1+ubuntu18.04.1+deb.sury.org+1 |
| php.ini used | /etc/php/7.2/cli/php.ini |
| EE root dir | phar://ee.phar |
| EE vendor dir | phar://ee.phar/vendor |
| EE phar path | /home/username |
| EE packages dir | |
| EE global config | |
| EE project config | |
| EE version | 4.0.8 |
+-------------------+-------------------------------------------------------------------------+

Now you can proceed to create a new site.

Set up WordPress in Docker

There are different types of sites that can be created using EasyEngine

  1. Basic HTML website
  2. PHP website with database
  3. WordPress website (Cache, Non-cache, Sub-domain, Sub-directory)
  4. Multi-site WordPress on Sub-domain or Sub-directory

Now we shall install WP using cache and use Cloud SQL as database.

The command to create a new site is sudo ee site create yourdomainname.com --type=wp

We shall customize the installation with some additional parameters as defined below.

  • dbhost => External database host name
  • dbuser => Database username
  • dbpass => Database password
  • dbname => Database name
  • admin-email => WP admin Email
  • admin-user => WP admin username
  • admin-pass => WP admin password
  • dbprefix => Database prefix
  • cache => Enable Redis cache
  • ssl => Install SSL certificate

Now execute the following command to create your WordPress website.

sudo ee site create yourdomainname.com --type=wp --dbhost=CLOUD_SQL_INSTANCE_IP_ADDRESS --dbuser=database_username --dbpass=database_password --dbname=database_name --admin-email=your_email --admin-user=admin_username --admin-pass=admin_password --dbprefix=db_prefix_ --cache

Now you have instructed EasyEngine to create a WP website for your Domain name with Redis cache, Cloud SQL for database and custom login credentials.

Within a few seconds your website will be created with the above details and once the set up is completed you will receive your site details like this.

Configuring project.
Verifying connection to remote database
Success: Connection to remote db verified
Creating WordPress site yourdomainname.com
Copying configuration files.
Starting site's services.
Downloading and configuring WordPress.
+--------------------+------------------------------------------+
| Site | https://yourdomainname.com |
+--------------------+------------------------------------------+
| Site Root | /opt/easyengine/sites/yourdomainname.com |
+--------------------+------------------------------------------+
| Site Title | yourdomainname.com |
+--------------------+------------------------------------------+
| WordPress Username | WordPress Username |
+--------------------+------------------------------------------+
| WordPress Password | WordPress Password |
+--------------------+------------------------------------------+
| DB Host | CLOUD_SQL_INSTANCE_IP_ADDRESS |
+--------------------+------------------------------------------+
| DB Name | Database Name |
+--------------------+------------------------------------------+
| DB User | Database Username |
+--------------------+------------------------------------------+
| DB Password | Database Password |
+--------------------+------------------------------------------+
| E-Mail | Admin Email |
+--------------------+------------------------------------------+
| SSL | Enabled |
+--------------------+------------------------------------------+
| SSL Wildcard | No |
+--------------------+------------------------------------------+
| Cache | Enabled |
+--------------------+------------------------------------------+

Now visit your Domain name in your browser, you can see your website homepage.

Great!

Docker WordPress HomePage

Let’s check the admin to verify what is used.

Login to your dashboard with your admin username and password. If you don’t remember the password you can always get your site info.

sudo ee site info yourdomainname.com
WordPress Docker Admin settings

As you can see Nginx Helper and WP Redis plugins are activated by default in your installation.

Install SSL Certificate in Docker

Now you can install Let’sEncrypt SSL certificate using EE v4.

sudo ee site update yourdomainname.com --ssl=le

Once this is completed your site will be accessible with HTTPS.

Docker Processes

You can check also the running services inside containers using sudo docker ps

CONTAINER ID        IMAGE                           COMMAND                  CREATED             STATUS              PORTS                                      NAMES
a0420958d5a4 easyengine/nginx:v4.0.0 "/usr/bin/openresty …" 11 minutes ago Up 11 minutes 80/tcp yourdomainnamecom_nginx_1
22f902aa48d4 easyengine/cron:v4.0.0 "/usr/bin/ofelia dae…" 18 minutes ago Up 18 minutes ee-cron-scheduler
1ed9c3d38a85 easyengine/postfix:v4.0.0 "postfix start-fg" 24 minutes ago Up 23 minutes 25/tcp yourdomainnamecom_postfix_1
b61074c1703a easyengine/php:v4.0.0 "docker-entrypoint.s…" 24 minutes ago Up 24 minutes 9000/tcp yourdomainnamecom_php_1
556f452292ac easyengine/redis:v4.0.0 "docker-entrypoint.s…" 25 minutes ago Up 24 minutes 6379/tcp services_global-redis_1
c7933827d685 easyengine/nginx-proxy:v4.0.1 "/app/docker-entrypo…" 35 minutes ago Up 35 minutes 0.0.0.0:80->80/tcp, 0.0.0.0:443->443/tcp services_global-nginx-proxy_1

You can see PHP, Redis, Nginx are running inside docker.

You can also check the docker status for memory, cpu and I/O usage.

sudo docker stats
CONTAINER ID        NAME                             CPU %               MEM USAGE / LIMIT        MEM %               NET I/O             BLOCK I/O           PIDS
a0420958d5a4 yourdomainnamecom_nginx_1 0.00% 4.113MiB / 1.65GiB 0.24% 5.17kB / 42B 9.89MB / 0B 2
22f902aa48d4 ee-cron-scheduler 0.79% 6.832MiB / 1.65GiB 0.40% 1.87kB / 0B 7.54MB / 0B 7
1ed9c3d38a85 yourdomainnamecom_postfix_1 0.00% 5.027MiB / 1.65GiB 0.30% 2.7kB / 2.68kB 11.8MB / 4.1kB 4
b61074c1703a yourdomainnamecom_php_1 0.01% 10.44MiB / 1.65GiB 0.62% 27.5kB / 67.9kB 59.8MB / 0B 1
556f452292ac services_global-redis_1 0.15% 1.902MiB / 1.65GiB 0.11% 64.3kB / 2.83kB 7.04MB / 0B 4

Now your WordPress installed with Docker containers. To learn more abour EE you can get more details by checking their handbook.

Running WordPress inside the Docker is easy now!

Cloudbooklet builds a large collection of Linux based guides and tutorials on Cloud platforms like Google Cloud, AWS, Azure, DigitalOcean and more

2 Comments

  1. Hi

    Can I run Cyberpenl instead with the same structure, right? I really enjoy your tutorial. They are so thorough and clear and would like to see your new post regarding of LiteSpeed server. Thank you.

    • Cloudbooklet Reply

      Thank you so much for your interest in this article

Write A Comment

This site is protected by reCAPTCHA and the Google Privacy Policy and Terms of Service apply.