Cloudbooklet
  • News
  • Artificial Intelligence
  • Applications
  • Linux
No Result
View All Result
Cloudbooklet
  • News
  • Artificial Intelligence
  • Applications
  • Linux
No Result
View All Result
Cloudbooklet
No Result
View All Result
Home Google Cloud

Install WordPress with Docker Compose using Nginx – Google Cloud

by Cloudbooklet
4 years ago
in Google Cloud, Compute Engine
Install Wordpress With Docker Compose Using Nginx Google Cloud
ShareTweetSendShare
Readers like you help support Cloudbooklet. When you make a purchase using links on our site, we may earn an affiliate commission.

Install WordPress with Docker Compose using Nginx on Google Cloud Platform. In this article you are going to learn how to install and configure WordPress with Nginx, PHP-FPM on Google Cloud with Docker, Docker Compose and connect to Cloud SQL. We will also install PhpMyAdmin and connect it with Cloud SQL. This setup is tested […]

ADVERTISEMENT

Install WordPress with Docker Compose using Nginx on Google Cloud Platform. In this article you are going to learn how to install and configure WordPress with Nginx, PHP-FPM on Google Cloud with Docker, Docker Compose and connect to Cloud SQL. We will also install PhpMyAdmin and connect it with Cloud SQL.

This setup is tested on Google Cloud Platform, it will also work on other cloud services, any VPS or any Dedicated servers with Docker.

Prerequisites

  1. Your Compute Engine Instance running.
  2. For setting up Compute Engine, see the Setting up Compute Engine Instance.
  3. Install Docker on Google Cloud Platform.
  4. Install Docker Compose on Google Cloud.
  5. Set up Cloud DNS, see the Setting up Google Cloud DNS for your domain.
  6. Google Cloud SQL Setup, see Setup Cloud SQL and connect with Compute Engine.

This setup can also be installed on any Linux based servers.

ADVERTISEMENT

Step 1: Setup Directories

Once you have Docker, Docker Compose installed and the Cloud SQL is setup you can proceed to setup directories for the WordPress installation.

You might also like

How To Setup Ssh Keys On Ubuntu

How to Setup SSH Keys on Ubuntu 20.04

4 months ago
Draggan Ai Editing Tool Install And Use Draggan Photo Editor

DragGAN AI Editing Tool Install and Use DragGAN Photo Editor

4 months ago

SSH to your instance and create the directories as follows.

sudo mkdir wordpress-docker
cd wordpress-docker

sudo mkdir nginx
sudo mkdir wordpress
sudo mkdir -p logs/nginx

We will use these directories as volumes for our installation.

ADVERTISEMENT

Step 2: Configure Nginx

Create a new Nginx configuration inside the nginx folder.

sudo nano nginx/wordpress.conf

Copy the below configurations.

ADVERTISEMENT
server {
     listen 80;
     listen [::]:80;

     server_name yourdomainname.com;
     
     root /var/www/html; 
     index index.php;
     
     location / {
         try_files $uri $uri/ /index.php$is_args$args;
     }

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

     location ~ /.ht {
         deny all;
     }

     location = /favicon.ico { 
         log_not_found off;
         access_log off; 
     }

     location = /robots.txt { 
         log_not_found off;
         access_log off;
         allow all; 
     }

     location ~* .(css|gif|ico|jpeg|jpg|js|png)$ {
         expires max;
         log_not_found off;
     }
 }

Step 3: Setup Docker Compose File

Create a docker-compose.yml file and include the configurations for WordPress.

We will create a container for Nginx and another container for WordPress and connect it to Cloud SQL.

ADVERTISEMENT

We will also setup PhpMyAdmin to manage the database.

sudo nano docker-compose.yml

Copy and paste the below configurations in your docker compose file.

ADVERTISEMENT
version: '3'
 services:
   wordpress:
     image: wordpress:5.2.2-php7.2-fpm
     container_name: wordpress
     restart: unless-stopped
     ports:
         - '9000:9000'
     environment:
       WORDPRESS_DB_HOST: Cloud_SQL_IP
       WORDPRESS_DB_NAME: Database_name
       WORDPRESS_DB_USER: Database_user_name
       WORDPRESS_DB_PASSWORD: Database_user_password
     volumes:
       - ./wordpress:/var/www/html

   nginx:
     image: nginx:latest
     container_name: nginx
     restart: unless-stopped
     ports:
       - "80:80"
       - "443:443"
     volumes:
         - ./nginx:/etc/nginx/conf.d
         - ./logs/nginx:/var/log/nginx
         - ./wordpress:/var/www/html
     links:
       - wordpress

   phpmyadmin:
     image: phpmyadmin/phpmyadmin
     restart: unless-stopped
     ports:
       - 3333:80
     environment:
       PMA_HOST: Cloud_SQL_IP_Address
       MYSQL_ROOT_PASSWORD: Cloud_SQL_Root_Password 

Now we have our docker-compose.yml file setup which a wordpress container wit the latest WordPress image with PHP 7.2 FPM. It will also creates an nginx container and configure it with the configuration we created above.

This will also downloads the phpmyadmin image and configure it on a different port and connects it with Cloud SQL.

Step 4: Run Docker-Compose

Now we have the Nginx configuration and Docker Compose configuration ready to be deployed.

Move to the folder that has your docker-compose.yml file and execute the following command to setup WordPress with Docker containers.

cd ~/wordpress-docker
docker-compose up -d

Now the containers are created using the configured images and will be accessible with the volumes we have created.

Once the setup is completed you can run this command to check the containers.

Step 5: Setup Firewall rules

As we have configured PhpMyAdmin on custom port 3333, we need to open the port in Firewall.

Go to VPC Network >> Firewall rules and click Create Firewall rules.

In Name enter phpmyadmin

In Targets select All instances in the network

In Source filter select IP ranges

In Source IP ranges enter 0.0.0.0/0

In Protocols and ports check TCP and enter 3333.

Click Create.

Step 6: Verify WordPress Installation with Docker

Once the setup is complete go to your browser and check your domain name.

http://yourdomainname.com

You will see the default WordPress installation screen. Go ahead and install WordPress.

To check the PhpMyAdmin you can use the port 3333

http://yourdomainname.com:3333

This is connected with Cloud SQL, you can manage your Cloud SQL database from here.

Conclusion

Now you have learned how to install WordPress with Docker and Docker Compose and install PhpMyAdmin and connect it to Cloud SQL.

Tags: DockerGoogle Cloud PlatformWordPress
ShareTweetSendShare
Cloudbooklet

Cloudbooklet

Comments 1

  1. Avatar Of Rob Rob says:
    3 years ago

    Why is /var/www/html visible in the nginx container?
    ( – ./wordpress:/var/www/html )
    This does not feel secure, because nginx is a reverse proxy that hides the servers behind it, and yet you make the /var/www/html visibl ein the nginx container.

    Reply

Leave a Reply Cancel reply

Your email address will not be published. Required fields are marked *

Related Posts

Set Up Deep Learning With Nvidia, Cuda, Cudnn On Ubuntu

How to Set Up Deep Learning with Nvidia, CUDA, cuDNN on Ubuntu 22.04

7 months ago
How To Install Or Upgrade Php 8.2 On Ubuntu 22.04

How to Install or Upgrade PHP 8.2 on Ubuntu 22.04

9 months ago
How To Change Timezone On Ubuntu 22.04

How to Change Timezone on Ubuntu 22.04

1 year ago
How To Install Ansible On Ubuntu 22.04

How to Install Ansible on Ubuntu 22.04

1 year ago

Follow Us

Trending Articles

Ai Girl Generator

7 Best AI Girl Generators for Creating Realistic and Beautiful AI Girls

September 19, 2023

How to Block YouTube Ads on Android TV in 2023 (6 Easy Methods)

How to Become an AI Trainer: Skills, Salary, and Career Opportunities

Create High Quality AI Cover Song with Covers AI

Top 7 Free Dating Sites for Men in 2023

10 Best AI Song Generator in 2023 (Free and Paid)

Popular Articles

Clear Gmail Inbox

How to Clear Gmail Inbox with AI: Tips and Tricks

September 13, 2023

10 Best Email Tracking App for 2023: Which One is Right for You?

Top 5 Free Linux Cloud Servers to Host Your Website

How to Change My Birthday on Snapchat

Jenni AI: How to Use AI Writing Assistant for Amazing Content

10 Best AI Video Generator Free of 2023

Subscribe Now

loader

Subscribe to our mailing list to receives daily updates!

Email Address*

Name

Cloudbooklet Logo

Welcome to our technology blog, where we explore the latest advancements in the field of artificial intelligence (AI) and how they are revolutionizing cloud computing. In this blog, we dive into the powerful capabilities of cloud platforms like Google Cloud Platform (GCP), Amazon Web Services (AWS), and Microsoft Azure, and how they are accelerating the adoption and deployment of AI solutions across various industries. Join us on this exciting journey as we explore the endless possibilities of AI and cloud computing.

  • About
  • Contact
  • Disclaimer
  • Privacy Policy

Cloudbooklet © 2023 All rights reserved.

No Result
View All Result
  • News
  • Artificial Intelligence
  • Applications
  • Linux

Cloudbooklet © 2023 All rights reserved.