One of the most popular applications used by customers and users of OpenShift Online is the WordPress blogging platform. Customers have found great value in the ease with which they can stand up a department or team WordPress instance all running on OpenShift. Recently, we announced the general availability of the next generation of OpenShift Online. The new version uses a new architecture while leveraging de facto standards such as containers and Kubernetes for orchestration. This post will describe the process I used to migrate my existing WordPress site from OpenShift Online v2 to the new version of OpenShift Online using the Pro tier.
Please note that the WordPress instance I will be migrating was deployed in 2013, so I am using this as an opportunity to upgrade to the current release of the blogging platform as of this writing.
Here is an image of the old WordPress instance that I will be migrating:
Note: Before getting started with this process, you should understand this is not an officially supported way to migrate blog sites between OpenShift 2 and OpenShift 3. This is just the journey I took to migrate my personal blogging platform..
If you would rather watch this in action instead of reading, check out the YouTube video I made:
Step 1: Backing Up Your Existing WordPress Instance
There are many ways to backup your existing WordPress instance and even options for doing everything using the command line by performing database dumps etc. However, I wanted to focus on a quick and easy way to make the migration. For that reason, I decided to use a WordPress plugin called “All-in-One WP Migration.” In order to install this plugin, I will log in to my existing blog site hosted on OpenShift Online v2 by pointing my browser to the
/wp-admin url as shown here:
Once I have authenticated to WordPress, I select Plugins and then Add New and then search for "All-in-One WP Migration."
After the plugin has been installed, activate it by clicking on the link displayed as shown in the following image:
Note: Before proceeding with the next step, you may want to disable comments on your current WordPress site as any comments made between the export time and import time will be lost.
Once the plugin has been activated, select it from the left hand column, and choose to export your site to a File:
Depending on the number of articles you have, how many comments, etc., the size of this file can be quite large. Keep that in mind when you start the download as it may take several minutes depending on your internet connection.
Great! The current WordPress site has been exported.
Step 2: Creating a Project and Creating a Database on OpenShift 3
Now that we have our current blog site exported, we need to create a new instance of WordPress on OpenShift Online 3. The first thing we want to do is create a project that will hold all of the components, namely the web application and database, for the WordPress platform.
Authenticate to OpenShift 3 and select to create a New Project. Give your project a name, keeping in mind that project names must be unique across the OpenShift 3 cluster you are using.
Once the project has been created, we want to deploy a persistent MySQL database to hold all of the information required for our site. Select Add to project, filter for "MySQL" and select MySQL (Persistent):
After clicking on Select, fill in the following fields:
- MySQL Connection Username
- MySQL Connection Password
- MySQL root user Password
- MySQL Database Name
For this blog post, I am going to use "wordpress" for everything including the database name:
You may also modify the database file size limit on this page as well if you think you will be using more than the 1GB default.
Congratulations! You now have a persistent MySQL database deployed.
Step 3: Deploying WordPress
At this point we have our WordPress site backed up and a new database created. Now we need to deploy WordPress. I have decided to deploy WordPress from source as I want to use persistent storage inside of my container to allow me to save state if the container restarts. Because of the way file permissions work, I need to fork the WordPress project and alter one configuration file. I will be using GitHub for this.
The first thing I want to do is the fork the WordPress project on GitHub into my own GitHub account. If you don’t have a GitHub account, now would be a great time to sign up for one.
Enter the following URL in your browser:
And click the Fork button in the right hand corner:
Now that we have WordPress forked, it’s time to deploy the platform. Go back to OpenShift Online 3 and select Add to Project:
Search for "PHP" and select 7.0, the latest version.
After you have clicked on Select, you will need to give your application a name as well as provide the Git Repository you want to use. I used "wordpress" for the name and the Git Repository that I forked earlier in this step.
IMPORTANT: You will also want to click on the link for advanced options to specify the version of WordPress you want to install. Because 4.8 is the current version, I provide the 4.8 under the Git reference section. If you want to install an older version, this is where you would enter in the version you want to deploy.
Finally, scroll down to the bottom and click on Create.
Step 4: Change the Deployment Strategy
By default, OpenShift will use a Rolling deployment strategy when making changes to an application. In subsequent steps we will attach persistent storage to the WordPress application, so we need to switch to the Recreate deployment strategy to work with the type of persistent storage available.
From the left hand menu, select Deployments, then wordpress. In the "Actions" menu, select Edit.
Under "Deployment Strategy" change "Strategy Type" from "Rolling" to "Recreate". Keep any parameters the same and save the configuration.
Step 5: Adding Persistent Storage
Now that WordPress has been installed, we need to add persistent storage to the container so the plugins, themes, etc. are maintained across application starts. We do this by selecting Storage from the menu on the left hand side:
Once you click on Storage, click on Create Storage and provide a name and size. For my site, I will use "wordpress-storage" and provide 5GB of storage:
Click on Create once you have provided the name and size. At this point, we have a persistent storage allocation but we haven’t assigned it to WordPress yet. In order to do that, click on Applications from the left hand menu, select Deployments, and then click on wordpress. Once you are viewing the WordPress deployment, pull down the "Actions" menu in the top right hand corner and select Add Storage:
On the next screen, select the wordpress-storage volume and enter in the following for the "Mount Path:"
Finally, click on Add to associate the persistent volume to your WordPress container.
Step 6: Configure WordPress
We have a MySQL database and a WordPress platform deployed, but we need to configure WordPress to communicate with the database. To do this, click on the URL provided for WordPress in the project overview page:
This will open the WordPress platform and run you through the initial configuration. Click on Let’s go! to see the page where you can enter in the authentication information. One of the items on that page is the "Database Host." It is important to understand how to get this information as it is certainly not the default
localhost that is provided.
Go to your project overview page and select Applications and then Services. Click on the mysql service and make a note of the "Hostname" as shown here:
Head back over to the WordPress configuration screen and provide the database name, username, and password that you used when you created the database container. For the database host, use the hostname that we retrieved in the previous step:
Note: For OpenShift Online, we could have just used the service name "mysql" for the hostname. It is generally only required to used the fully qualified version if you are communicating across projects while using OpenShift Container Platform or OpenShift Origin. However, it’s probably best to always use the full name.
If you were able to connect, you should see the following message:
Go ahead and run the install and create an admin username and password. Keep in mind this will be overwritten during a future step when we migrate our blog.
Step 7: Modify wp-config.php
Once the project has been deployed and configured, we need to copy the wp-config.php file to the persistent storage, edit it to specify the method for accessing the persistent storage, and override the startup command to have it use this copy of wp-config.php.
To accomplish this, go to the project overview page and click on the blue circle under your WordPress deployment. This is a shortcut to the details of the pod running WordPress.
On the next screen, select the terminal tab as shown in the following image:
Once the terminal has started copy the wp-config.php directory into the wp-content directory.
$ cp wp-config.php wp-content/wp-config.php
Edit wp-content/wp-config.php using vi to add the following line:
You can add this under the
Save your changes.
Next create a new file wp-content/run and add to it:
cp /opt/app-root/src/wp-content/wp-config.php /opt/app-root/src/wp-config.php
Save your changes and make this script executable by running:
chmod +x wp-content/run
Because we mounted a persistent volume for the wp-content directory, we also need to add a couple of directories that WordPress expects to be there. Without this step you will not be able to install plugins or add themes.
Perform the following commands while still using the terminal inside of the web browser:
$ mkdir wp-content/plugins
$ mkdir wp-content/themes
This sets up the persistent storage. We now need to modify the deployment configuration in OpenShift for the WordPress application to use the run script we added when the container starts.
From the left hand menu, select Deployments, then wordpress. In the "Actions" menu, select Edit YAML. Scroll down until you find the
containers section where it defines the configuration for the
wordpress container. Add to this section the
command item, with value of
Save the changes and the WordPress application should be automatically redeployed with our changes.
Step 8: Migrate Old Blog Site
Whew, we're on the home stretch. The last thing we need to do is install the "All-in-One WP Migration" plugin on the new blog site and import our content. While on the WordPress admin dashboard, click on Plugins, then Add New, and then search for "All-in-One WP Migration."
Once the plugin has been installed, click on the Activate button:
Click on the All-in-One WP Migration menu item on the left hand side of the screen and then import.
Select Import From file and then use the export from your previous WordPress installation. You should see a status indicator as indicated in the following image:
Once the migration has been analyzed, you will see a window pop up asking if it’s okay to overwrite everything in this new installation. Because this is a brand new WordPress install, select Continue.
Continue with the migration and remember to follow the instructions regarding permalinks. Finally, if you are upgrading from a very old version, like I am, you will be asked if you want to upgrade the database. Select Yes and then log back in keeping in mind you will now need to use the username / password from your previous WordPress installation as we just migrated everything over.
Step 9: Bask in the Glory
Whew, we finally made it. The old WordPress site that I had deployed to OpenShift Online 2 is now deployed using containers and all the hotness of OpenShift Online 3. Here is a quick screenshot showing what the final site looks like after following these steps:
Step 10: Adding a Public Hostname
In this post I walked you through the steps I took in order to migrate my blog site over to OpenShift 3. The only thing missing is assigning my custom hostname to the application. This can be accomplished by creating a new route to the WordPress service.
From the project overview dashboard, click on Applications, then Services, and select the WordPress service. On this page click on Actions in the top right hand corner and finally select Create Route.
On this page I would enter in the details for my hostname while ensuring that I have access to the DNS records at my registrar to make the necessary changes to point it to OpenShift!
This was a fun journey to migrate an existing WordPress site to using containers on OpenShift 3 Pro Tier. Along the way we were able to create a persistent database, persistent volume for our WordPress plugins and content, and were able to migrate all content to the new platform.
I hope you enjoyed this post and enjoy using OpenShift Online 3 Pro Tier!