Accelerate the value of multicloud with collaborative DevSecOps Learn more

Build and deploy a WordPress app on OpenShift using MariaDB

In today’s era, most companies need a fast and easy way to deploy their container-based applications in order to operate in a cloud-friendly way and scale easily in the future. You could choose from plain old Kubernetes, or several other platforms that are built on Kubernetes. Advantages of using Red Hat® OpenShift® are that it’s fast enough, offers a free custom domain, offers large disk space, and a significant amount of MySQL storage. It’s a powerful platform as a service (PaaS) offering, rather than using traditional hosting servers that might be slow and not quite efficient.

The comprehensive enterprise Kubernetes platform Red Hat OpenShift 4 is driven by the innovation of Kubernetes Operators to deliver full-stack automation. Kubernetes is an important fundamental technology in OpenShift because it helps power the deployment and management of the Docker images across autoscaled features in clusters.

This tutorial walks you through getting your first WordPress application instance up and running on an OpenShift managed cluster on IBM Cloud, using OpenShift command-line interface (CLI) tools and the web console.

WordPress is an online, free, and open-source tool written in PHP programming language. It’s probably the easiest and most powerful blogging and website content management system (CMS) today. Used by individuals, big businesses, and everyone in between. WordPress uses MySQL or MariaDB as a back-end database engine. Today WordPress is built and maintained by a huge community of contributors.

Prerequisites

This tutorial assumes that an OpenShift 4 cluster is already created.

Also, it’s good to have a basic familiarity with Kubernetes and the concepts of microservice software architecture.

Make sure that everything you need is ready:

The following technologies are featured in this tutorial:

  • IBM Cloud: A suite of cloud computing services that offer both Platform as a Service (PaaS) and infrastructure as a service (IaaS) capabilities.

  • Red Hat OpenShift Container Platform: A developer- and operations-friendly Kubernetes distro. It runs on top of Kubernetes (previous versions of OpenShift handled container orchestration using a different mechanism). OpenShift provides tools that help developers and operations teams run containerized workloads.

  • MariaDB: MariaDB is one of the most popular database servers in the world. It’s made by the original developers of MySQL and guaranteed to stay open source

  • Docker: An open-source containerization platform used to build, ship, and run distributed applications on laptops, data center, VMs, or the cloud.

  • oc: The OpenShift Origin CLI (oc) exposes commands for managing applications and includes lower-level tools to interact with each component of the system.

Estimated time

Completing this tutorial should take about 20 minutes.

Deploy a WordPress website on OpenShift, connected to a MariaDB instance

Start by signing up and logging in to IBM Cloud.

Under Resource List, you see a clusters section. Expand that section, to see your recently created OpenShift cluster. Select it.

Your cluster’s console also has an Access tab on IBM Cloud that provides information and instructions for how to set up the OpenShift CLI tools that you use in this tutorial.

Screen capture of IBM Cloud and OpenShift Click

The following sections walk you through the steps of the tutorial.

Step 1: Access the OpenShift user interface

Click the blue button as shown in the following screen capture:

Screen capture of OpenShift Console Button

From the cluster’s web console, you see on the top right that you are now automatically authenticated, logged in, and have established a session to the OpenShift Container Platform server with your credentials:

Screen capture of OpenShift Cluster Console

After you successfully downloaded and installed the OpenShift CLI, you use it to log in and create a project.

On the web user interface of OpenShift’s cluster in the top right corner on the service catalog page, click on your credentials and select Copy Login Command. It generates a live session token with your logged in credentials on the OpenShift container platform server.

Screen capture of IBM Cloud login page

Note: The generated token is a type of password. Do not share it with others.

Step 2: Log in from the CLI

Open your CMD/Terminal and paste the login credentials. The command consists of the oc login + the server URL attached with the live session generated token.

Screen capture of logging in to OpenShift

You are now successfully logged in to the OpenShift Container Platform server using the oc CLI. It shows a list of the available OpenShift projects.

Step 3: Create a project

Create a project to host your deployments and resources.

From CMD/terminal, run the following command:

oc new-project <project-name>

oc new-project wordpress

Step 4: Deploy your database and your WordPress app on OpenShift

After creating a project, you need to deploy your WordPress application.

First, you need to create the back-end database instance, which is in our case MariaDB. From the CMD/terminal, run the following command:

oc new-app mariadb-ephemeral

Note: MariaDB is not using persistent storage. So, any data stored is lost when pods are destroyed. Instead, you use a sample database in this tutorial for testing purposes.

Take a note or your MariaDB-generated information: MariaDB connection user name, MariaDB connection password, and MariaDB database name. For the DB host, use mariadb.

Screen capture of MariaDB deployment

Because you are going to deploy WordPress, build your project on Apache with a PHP image.

From the CMD/terminal run the following command:

oc new-app php~https://github.com/wordpress/wordpress

You can track the deployment by viewing its logs:

oc logs -f dc/wordpress

Screen capture of WordPress deployment logs

After you successfully deployed WordPress, you need to access it. You expose it as a service using the following command:

oc expose svc/<service>

oc expose svc/wordpress

Next, query the service route for the host URL that is generated. Run the following command:

oc get routes

Copy the generated host name from your terminal and paste it in any browser. You should see the welcome screen of the deployed WordPress application, waiting for the database configurations to complete its setup. It should look like the following screen capture:

Screen capture of WordPress and database deployment

Now, you have deployed your two resources under one project: MariaDB and WordPress.

You can get a visual view by going back to your Redhat OpenShift console web user interface. Click Refresh and you successfully see your newly created project listed on the My Projects tab, including the two created resources.

Use the database information you previously created to complete the WordPress installation. Complete the information needed and click Install WordPress.

After successfully setting up WordPress, the login screen of WordPress opens. Use the user name and password set earlier and log in:

Screen capture of WordPress login page

From the WordPress dashboard, you can start building your own WordPress website:

Screen capture of WordPress dashboard

In the top left corner, click the website name with the home icon. Click View Site to preview your website. The following screen captures shows a built WordPress website deployed:

Screen capture of a WordPress Website

Summary

Congratulations! You learned how to deploy your WordPress application connected to a MariaDB instance from inside a container, using Red Hat OpenShift on IBM Cloud.

If you’re interested in learning more about how to get started using OpenShift, check out the technical content at Red Hat Openshift on IBM Cloud. For example, Kubernetes with OpenShift 101: Exercises to get you started with a local OpenShift environment shows you how to install a local OpenShift environment on your local machine using MiniShift. You also learn the basics of deploying and managing applications.