How to set up wordpress on OpenShift in 10 minutes

What this is about?

A lot of customers would like to give the brave new container world (based on Docker technology) a try with real life workload. The WordPress content management system (yes, it has become more than a simple blog) seems to be an application that many customers know and use (and that I’ve been asked for numerous times). From a technical point of view the WordPress use case is rather simple, since we only need a PHP runtime and a database such as MySQL. Therefore it is a perfect candidate to pilot container aspects on OpenShift Container Platform.

Preparation

Install Container Development Kit

I highly recommend to install the freely available Red Hat Container Development Kit (shortly CDK). It will give you a ready to use installation of OpenShift Container Platform based on a Vagrant image. So you’re up to speed in absolutely no time:

Please follow the installation instructions here: https://developers.redhat.com/products/cdk/get-started/

Setup resources on OpenShift

Spin up your CDK environment and ssh into the system:

vagrant up
vagrant ssh

Create a new project and import the template for an ephemeral MySQL (since this is not included in the CDK V2.3 distribution by default). If you prefer to use another database or even one with persistent storage, then you can find additional templates here.

oc new-project wordpress
oc create -f https://raw.githubusercontent.com/openshift/openshift-ansible/master/roles/openshift_examples/files/examples/v1.3/db-templates/mysql-ephemeral-template.json

Now we create one pod for our MySQL database and create our WordPress application based on the source code. OpenShift will automatically determine that it is based on PHP and will therefore choose the PHP builder image to create a Docker image from our WordPress source code.

oc new-app mysql-ephemeral
oc new-app https://github.com/wordpress/wordpress
oc expose service wordpress

Now let’s login to the OpenShift management console and see what has happened:

We now have a pod that runs our WordPress application (web server, PHP, source code) and one pod running our ready to use ephemeral (= non-persistent) MySQL database.

Install wordpress

Before we need to note down the connection settings for our MySQL database. Firstly we look up the cluster IP of our mysql service; secondly we look up the database name, username & password. Have a look at the following screenshots:

Now it is time to setup and configure wordpress. Simply click on the route that has been created for your wordpress pod (in my case the hostname is “http://wordpress-wordpress.rhel-cdk.10.1.2.2.xip.io/wp-admin/setup-config.php”).

Congratulations for installing WordPress on OpenShift!

What’s next

For now we’ve created all the resources manually in a not yet reusable fashion. Therefore one of the next steps could be to create a template from our resources, import it into the OpenShift namespace and make it available for our users as a service catalog item. So our users could provision a fully installed WordPress with the click of a button.

9 thoughts on “How to set up wordpress on OpenShift in 10 minutes

  1. Hallo Sebastian,

    ich habe versucht deine Anleitung für ein WordPress zu befolgen:

    [root@vm74960407 pv20gi72]# oc new-project wordpress
    Now using project “wordpress” on server “https://ocp-t-n-m1.sv.db.de:8443”.

    You can add applications to this project with the ‘new-app’ command. For example, try:

    oc new-app centos/ruby-22-centos7~https://github.com/openshift/ruby-ex.git

    to build a new example application in Ruby.
    [root@vm74960407 pv20gi72]# oc new-app https://github.com/wordpress/wordpress
    –> Found image ee994c3 (9 weeks old) in image stream “openshift/php” under tag “5.6” for “php”

    Apache 2.4 with PHP 5.6
    ———————–
    Platform for building and running PHP 5.6 applications

    Tags: builder, php, php56, rh-php56

    * The source repository appears to match: php
    * A source build using source code from https://github.com/wordpress/wordpress will be created
    * The resulting image will be pushed to image stream “wordpress:latest”
    * Use ‘start-build’ to trigger a new build
    * WARNING: this source repository may require credentials.
    Create a secret with your git credentials and use ‘set build-secret’ to assign it to the build config.
    * This image will be deployed in deployment config “wordpress”
    * Port 8080/tcp will be load balanced by service “wordpress”
    * Other containers can access this service through the hostname “wordpress”

    –> Creating resources …
    imagestream “wordpress” created
    buildconfig “wordpress” created
    deploymentconfig “wordpress” created
    service “wordpress” created
    –> Success
    Build scheduled, use ‘oc logs -f bc/wordpress’ to track its progress.
    Run ‘oc status’ to view your app.

    Leider scheitert es an irgendwelchen Berechtigungen, hier ein Auszug aus dem Log von dem Pod :

    WordPress not found in /var/www/html – copying now…
    tar: ./index.php: Cannot open: Permission denied
    tar: ./license.txt: Cannot open: Permission denied
    :
    :
    :
    tar: ./wp-includes: Cannot mkdir: Permission denied
    tar: ./wp-includes/wlwmanifest.xml: Cannot open: No such file or directory
    tar: ./wp-includes: Cannot mkdir: Permission denied
    tar: ./wp-includes/wp-db.php: Cannot open: No such file or directory
    tar: ./wp-includes: Cannot mkdir: Permission denied
    tar: ./wp-includes/wp-diff.php: Cannot open: No such file or directory
    tar: ./wp-links-opml.php: Cannot open: Permission denied
    tar: ./wp-load.php: Cannot open: Permission denied
    tar: ./wp-login.php: Cannot open: Permission denied
    tar: ./wp-mail.php: Cannot open: Permission denied
    tar: ./wp-settings.php: Cannot open: Permission denied
    tar: ./wp-signup.php: Cannot open: Permission denied
    tar: ./wp-trackback.php: Cannot open: Permission denied
    tar: ./xmlrpc.php: Cannot open: Permission denied
    tar: .: Cannot utime: Operation not permitted
    tar: Exiting with failure status due to previous errors

    Funktioniert das Beispiel nicht mehr oder haben wir ein Problem mit unserer Umgebung? Hast du einen Tipp?

  2. Hallo Holger,

    ich habe die Kommandos gerade nochmal in der aktuellsten CDK V3.4 durchlaufen lassen und hatte keine Probleme. Wo genau treten denn die Fehler auf….d.h. im Log des Build Pods oder später? Evtl. kannst du mir mal das komplette Log zukommen lassen.

    Viele Grüße,
    Sebastian

  3. It’s not a wise idea to use the IP address to connect to the database. You should use the name of your mysql service instead. Here it is simply “mysql”.

  4. Hi Sebastian,

    this is not needed: “Firstly we look up the cluster IP of our mysql service” as well as the screenshots with the IP address of the database service. The service name acts as a host name and will be resolved to the IP address on the other pods (in the project).

  5. /readme.html looks like a good candidate for health checks (“/” seems to return a 301 when used as health check with release 4.8)

  6. Hi Marc,

    I was not aware that the service name also acts as DNS name. Could you please point us to the according section in the OpenShift documentation? – I am really curious how this works. Thanks in advance!

    Cheers,
    Sebastian

Leave a Reply

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