IBM Cloud Global

 View Only

Hosting Scalable WordPress in IBM Code Engine

By Priyank Narvekar posted Thu August 22, 2024 05:52 PM

  

This tutorial shows how to deploy a scalable WordPress site in the IBM Code Engine.

Prereqs

  • IBM Cloud account

  • ibmcloud cli utility

  • mysql cli utility

  • docker cli utility

Objectives

  • Create an instance of IBM Cloud Databases for MySQL.

  • Create a custom Wordpress Container Image in IBM Container registry

  • Create a Code Engine Project and deploy the WordPress site

Create an instance of IBM Cloud Databases for MySQL.

  1. Log in to IBM Cloud

  2. Navigate to the catalog, search for “Databases for MySQL” and click on the service to open its details page.

  3. Configure your MySQL instance:

- Provide a name for your MySQL instance.

- Choose the region and resource group where you want to create the instance.

- Select the Resource Allocation plan that suits your needs

- Set the database version to 8.0

- Set the Endpoint Type to Both Public and Private endpoints”.

- Optionally configure the encryption.

  1. Review your configuration settings and click on the "Create" button to initiate the creation of your MySQL instance.

  2. The deployment process may take some time. Wait for the instance to be provisioned.

  3. Once the instance is provisioned, from the Resource list page , you can open to the instance to find further details on how to access your MySQL database, including connection strings, credentials.

  4. Navigate to the overview page of the mysql instance and from the Endpoints section download the ca certificate for connection.

  5. Next navigate to the Service credentials page for the mysql instance, and create a new credential. Once created, capture the following details.

    host:port

    5c86f6bd-f2fd-4968-aca8-46b0bfb6295d.c0v4phir0ah9ul9trho0.private.databases.appdomain.cloud:32409

    username

    someusername

    password

    somepassword

  6. From the Overview page , again under the Endpoints section, in CLI tab, use the command to login to mysql and create the database for Wordpress

# Example: 
MYSQL_PWD=<password> mysql \
    --host=5c86f6bd-f2fd-4968-aca8-46b0bfb6295d.c0v4phir0ah9ul9trho0.private.databases.appdomain.cloud \
    --port=32409 --user=<username> --ssl-mode=VERIFY_IDENTITY --ssl-ca=286a39f3-e1b8-4381-a83b-08ca9153eae0 ibmclouddb

mysql> CREATE DATABASE WORDPRESS;

Create a custom Wordpress Container Image in IBM Container registry

  1. Create a local folder as a docker workspace

  2. Copy the ca certificate file to this folder.

  3. Create the Dockerfile in the same folder as follows

FROM wordpress:latest

COPY <ca-certificate-file> /usr/local/share/ca-certificates/icd-mysql.crt       # eg : COPY 286a39f3-e1b8-4381-a83b-08ca9153eae0 /usr/local/share/ca-certificates/icd-mysql.crt

RUN cat /usr/local/share/ca-certificates/icd-mysql.crt >> /etc/ssl/certs/ca-certificates.crt

  1. Log in to ibm cloud from you command-line follow the instructions to log into ibm container registry.

$ ibmcloud login --apikey "${APIKEY}"

# Target a resource group and region : ibmcloud target -g RESOURCE_GROUP -r REGION
$ ibmcloud target -g priyank -r ca-tor

# Install IBM Container Registry plugin
$ ibmcloud plugin install container-registry -r 'IBM Cloud'

# Target the correct IBM Cloud Container Registry region: ibmcloud cr region-set REGION
$ ibmcloud cr region-set ca-tor

# Create a namespace : ibmcloud cr namespace-add <my_namespace>
$ ibmcloud cr namespace-add priyank

# Log your local Docker daemon into the IBM Cloud Container Registry.
ibmcloud cr login

  1. Build the Docker container and push to ICR

# build the docker image tagged in the format "<region>.icr.io/<my_namespace>/<my_repository>:<my_tag>"
$ docker build -t ca.icr.io/priyank/wordpress:latest .

# push the image to icr
$ docker push ca.icr.io/priyank/wordpress:latest

Create a Code Engine Project and deploy the WordPress site

  1. Navigate to Code Engine Projects on IBM Cloud Web Console - https://cloud.ibm.com/codeengine/overview

  2. Click “Create” to create a new project in the appropriate region.

  3. Navigate to the “Applications” tab

  4. Click the “Create” button

  5. Provide the name for the application

  6. Choose container Image for Code and Click on Configure Image button to select the previously pushed image to ICR.

  7. Choose the Instance resources configuration and auto scaling configurations

  8. Configure the Environment variables as follows based on the database connection details captured earlier:

WORDPRESS_DB_HOST

5c86f6bd-f2fd-4968-aca8-46b0bfb6295d.c0v4phir0ah9ul9trho0.private.databases.appdomain.cloud:32409

WORDPRESS_DB_USER

someuser

WORDPRESS_DB_PASSWORD

somepassword

WORDPRESS_DB_NAME

WORDPRESS

WORDPRESS_CONFIG_EXTRA

define('MYSQL_CLIENT_FLAGS', MYSQLI_CLIENT_SSL);

  1. In the Image start options, configure the Listening port to port 80.

  2. Click Create.

  3. Once the application is deployed and healthy, optionally to setup custom domain, navigate to the Domain Mappings tab,

  4. Under the “Custom domain mappings” Click create and follow the instructions to setup your own domain to point to the hosted wordpress.

  5. Finally navigate to the custom domain or the FQDN showed in the “public” property of “Custom domain mappings”. The Wordpress site will be up and running.

0 comments
9 views

Permalink