Hướng dẫn Install WordPress on Google Cloud Run Container Registry

31st Mar 2022
Table of contents

You will need the following items to complete this tutorial.

  • WordPress Docker image in Google Container Registry

  • A Cloud SQL Instance up and running with MySQL.

  • Environment Variables.

  • A Domain. (Register a Domain, or else use an existing Domain).

Step - 1: Pull and Push WordPress Image to Google Container Registry.

To begin, pull and push the bitnami wordpress image to Google Container Registry from the Docker Hub. Use the Cloud SDK or Cloud Shell to run the commands below.

Example:

docker pull bitnami/wordpress
docker tag bitnami/wordpress gcr.io/optical-depth-345113/bitnami-wordpress
docker push gcr.io/optical-depth-345113/bitnami-wordpress

In the above example, The "gcr.io" is the hostname, and the "elegant-canto-331917" is the project ID. Kindly, Substitute the hostname and project ID with yours. To learn more about pulling and pushing Docker images into the Google container registry. Refer to the following article.

Output:

info@cloudshell:~ (elegant-canto-331917)$ docker pull bitnami/wordpress
Using default tag: latest
latest: Pulling from bitnami/wordpress
be4dd8fa80cd: Pull complete
87d5d5d80dcb: Pull complete
72276dc2231e: Pull complete
ae418799c487: Pull complete
52e445f40546: Pull complete
a1a3cb231147: Pull complete
26fb68febdb7: Pull complete
6ba9e60dd627: Pull complete
84a4049a0a32: Pull complete
7f4b439880db: Pull complete
ba21f435eab2: Pull complete
5ab426f05241: Pull complete
906fa1ff1880: Pull complete
e6d3ef41d9c4: Pull complete
5c0b03980544: Pull complete
06107a038509: Pull complete
f20ad7b50f98: Pull complete
f5fa7aa05063: Pull complete
38f95d451884: Pull complete
57266b8aa6f4: Pull complete
Digest: sha256:0941fa5c418d6d6044ccf22545ecd8c46fe60b15e630540110309ce0cba38d4c
Status: Downloaded newer image for bitnami/wordpress:latest
docker.io/bitnami/wordpress:latest
info@cloudshell:~ (elegant-canto-331917)$ docker tag bitnami/wordpress gcr.io/elegant-canto-331917/bitnami-wordpress
info@cloudshell:~ (elegant-canto-331917)$ docker push gcr.io/elegant-canto-331917/bitnami-wordpress
Using default tag: latest
The push refers to repository [gcr.io/elegant-canto-331917/bitnami-wordpress]
4a1cded640f2: Preparing
5f2aa59ddddf: Preparing
7a13bd4b7e00: Preparing
eefff3efd0bb: Preparing
bd09d5bcf057: Preparing
latest: digest: sha256:0941fa5c418d6d6044ccf22545ecd8c46fe60b15e630540110309ce0cba38d4c size: 4516
info@cloudshell:~ (elegant-canto-331917)$

To learn more about pulling and pushing Docker images to the container registry, as well as particular versioning, see this page.

>> Hướng dẫn nhỏ add Docker image to Google Container Registry

Finally, Navigate to the container registry images interface in the cloud console to verify the pushed image in the container registry.

Step - 2: Create a Cloud SQL Instance with MySQL.

In the Console, Navigate to Cloud SQL, Create a new instance with MYSQL version 8.0, add "0.0.0.0/0" under Authorized networks and create the instance.

In the Console, Navigate to Cloud SQL, Create a new instance with MYSQL version 8.0, add "0.0.0.0/0" under Authorized networks and create the instance.

Lastly, In the Cloud SQL interface, Navigate to Databases and create a new database for WordPress. For example, "my_wordpress_database".

Step - 3. Installing WordPress on Google Cloud Run. Navigate to the Cloud Run interface in the Google cloud console and click on the "Create Service" option to deploy the WordPress.

Step - 3. Installing WordPress on Google Cloud Run.

Navigate to the Cloud Run interface in the Google cloud console and click on the "Create Service" option to deploy the WordPress.

​  Step - 3. Installing WordPress on Google Cloud Run. Navigate to the Cloud Run interface in the Google cloud console and click on the "Create Service" option to deploy the WordPress. [Click and drag to move] ​

Choose the "Deploy one revision from an existing container image" option in the create service interface and select the bitnami WordPress image from the container registry.

Then, type the service name and choose the region and specify the CPU allocation, pricing and auto-scaling options. Also, select the "Allow all traffic" option in the ingress and select the "Allow unauthenticated invocations" in the Authentication.

Next, Expand the "Container, Variables & Secrets, Connections, Security" option and type "8080" in the container port under the container tab.

Next, switch to the Variables tab, and add the following variables.

Choose the "Deploy one revision from an existing container image" option in the create service interface and select the bitnami WordPress image from the container registry.   Then, type the service name and choose the region and specify the CPU allocation, pricing and auto-scaling options. Also, select the "Allow all traffic" option in the ingress and select the "Allow unauthenticated invocations" in the Authentication.   Next, Expand the "Container, Variables & Secrets, Connections, Security" option and type "8080" in the container port under the container tab.   Next, switch to the Variables tab, and add the following variables.

In the environment variables tab, add the following variable. Please remember to substitute the WordPress username, password, email, database host, port, username, and password with your values.

Environment Variable Name Value Notes
WORDPRESS_USERNAME ​yourusername WordPress administrator username. For example, manoj.
WORDPRESS_PASSWORD ​PassWord WordPress administrator password. For example, Admin@123
​WORDPRESS_EMAIL [email protected] WordPress application email. For example, [email protected]

WORDPRESS_

DATABASE_HOST

35.239.118.173 Cloud SQL instance Public IP Address.

WORDPRESS_DATABASE

_PORT_NUMBER

3306 Port used by the MariaDB or MySQL server. By default, 3306.

WORDPRESS_

DATABASE_NAME

Your_WordPress_Database Database name that WordPress will use to connect with the database. Refer Step -2.

WORDPRESS_

DATABASE_USER

root Database user that WordPress will use to connect with the database. By default, Cloud SQL username is root.

WORDPRESS_

DATABASE_PASSWORD

Your_CloudSQL_Instance_Password Database password that WordPress will use to connect with the database. CloudSQL instance password. Refer Step - 2.

Finally, click on the "create" option to deploy the WordPress on Google Cloud Run. 

Google cloud

To visit the website, click the URL once the deployment is complete. Please keep in mind that remembering the URL each time you want to access the website is difficult. Refer the Step-4 and assign a custom(your) domain to the Cloud Run service..

gogole wordpress

Step - 4. Assign a custom domain to your WordPress Cloud Run Service.

Navigate to the Cloud Run interface and click on the "Manage Custom Domains" option,

Click on the "Add Mapping" option in the Manage Custom Domains interface to point to your custom domain

Select the service to which you're mapping the custom domain from the Add Mapping interface.

map domain

Enter your domain name and click on continue to verify ownership of the domain.

Unless you bought your domain from Google, you must prove ownership before using it.

In case, If you have already verified the ownership of the domain, choose the domain from the "Select a verified domain" drop-down list and type the subdomain name in the "Specify Subdomain" field or leave it to a blank to point to the root domain.

Then, click on the "continue" option to update your DNS record at your domain registrar.

Lastly, add a CNAME record in your domain DNS points to "ghs.googlehosted.com."

google cloud

Finally, Click on the "Done" option in the add mapping interface.

google domain

When the domain mapping is finished, navigate your domain URL to browse the website.

Here are some recommended tips and tricks.

Custom domain mapping typically takes a long time. It usually takes a few minutes to load after the domain mapping is completed.

google cloud

Keep in mind that if you disable the container registry service by accident, the Cloud Run service will collapse, and your website will become unavailable.

Bạn thấy bài viết này như thế nào?
0 reactions

Add new comment

Image CAPTCHA
Enter the characters shown in the image.
Câu nói tâm đắc: “Điều tuyệt với nhất trong cuộc sống là làm được những việc mà người khác tin là không thể!”

Related Articles

Tiếp tục tìm hiểu về Elasticsearch mới thấy, đằng sau những query và response tưởng như rất đơn giản kia là cả một tổ hợp rất phức tạp của biết bao tinh hoa công nghệ trên thế giới.

The first method to enable container registry service is to use the Google Cloud Console interface. Log in to the cloud console, search for the library in the search bar, and select the API library under the products and pages