Skip to main content

Hosting WordPress On OpenShift

If you’ve not heard of OpenShift, it’s:
"a free, cloud-based application platform for Java, Perl, PHP, Python, and Ruby applications."

OpenShift uses git to publish files to your site, so the general approach is to make your application locally, commit files to git and then push them to OpenShift. In practice this works very well, but there are a couple of gotcha’s that I encountered – I’ll explain those later.

OpenShift express supports Java (with full AS7 support), Ruby, PHP, Perl and Python apps.

In this post, I’m going to show the steps needed to host WordPress at OpenShift Express.

Installing the client tools
So, the first stage in setting up on OpenShift is to install the OpenShift client tools. On Ubuntu, this is achieved with apt-get

$ sudo apt-get install ruby
$ sudo apt-get install rubygems
$ sudo apt-get install rhc

Creating a domain and an application
After installing the OpenShift tools, the next stage is to create a domain name to host the application in and the application itself.

Creating a domain is achieved with the rhc domain create command.

$ rhc domain create -n <domain> -l <emailaddress>

Where domain is the OpenShift unique domain name for your application and emailaddress is your login email address for OpenShift.

Next, you need to create an application. This is essentially a remote git repository which is cloned onto your local filesystem. When creating an application, you need to specify which "cartridges" you want to use. For WordPress, you will need to use the php-5.3 cartridge.

$ rhc app create -a <appname> -t php-5.3

Where appname is your application name.

If all goes well, your application will now be created and available on the internet at:

http://<appname>-<domain>.rhcloud.com

MySQL Support
The next stage of hosting WordPress on OpenShift is to create a MySQL database. This is again achieved using the OpenShift command tools:

$ rhc-ctl-app -a  "appname" -e add-mysql-5.1

This will give you MySQL support for your application. After running this command, you’ll be supplied details to your MySQL database. To help manage the database, the easiest way I found was to add PHPMyAdmin

$ rhc-ctl-app -e add-phpmyadmin-3.4 -a "appname"

Now that you’ve got PHPMyAdmin installed, a good security practice is to create a MySQL user with the appropriate access rights for accessing WordPress. We don’t really want WordPress running against the admin MySQL account.

Install WordPress
At this point, you’ve created a basic OpenShift PHP application with MySQL support. The next stage is to install WordPress. To install, simply download the latest archive of WordPress and unzip it into the php folder that has been created underneath your appname folder.

After unziping, its tempting to just access the OpenShift application and run the WordPress wizard to create the standard wp-config.php file. Unfortunately if you do this, when you next push your local code to OpenShift, any modifications made on the server will be lost. So, the general procedure is to always make changes locally and then push them to the server. This also applies for installing plugins to WordPress – always install them locally, commit them to git and then push them to OpenShift.

So, to get WordPress up and running, create a wp-config.php file locally within the WordPress installation folder. Its a very straightforward file to create, but check out the WordPress docs for more info.

Pushing to OpenShift
Having created the database configuration file, you can now commit everything to git and push it to OpenShift.

$ git commit -a -m "Initial installation of WordPress"
$ git push

Again, assuming everything has gone OK with no errors, you should be able to access your WordPress site at:

http://<appname>-<domain>.rhcloud.com

Publishing to a custom domain
OpenShift has recently added support to allow applications to be hosted at their own domain names rather than as a subdomain of rhcloud.com

To publish to a custom domain, you need to add an alias in OpenShift for your application to the domain name you want it hosted at.

$ rhc-ctl-app -c add-alias --alias www.somedomain.com -a <appname>

To complete the process, you need to edit your DNS records and add a cname pointing your domain (e.g. www.somedomain.com) to <appname>-<domain>.rhcloud.com

You should now have a working WordPress installation running on OpenShift

Uploading media to WordPress
One of the side effects of pushing local content to a git repository is that any changes made to the web site are lost when new code is pushed to it. For example plugins installed via the WordPress user interface are lost when you push new code to OpenShift. Also, any images uploaded to WordPress (by default stored in wp-content/uploads) are also lost when you push new code. To overcome this, edit the /.openshift/action_hooks/build file and add the following contents:

if [ ! -d $OPENSHIFT_DATA_DIR/uploads ]; then
mkdir $OPENSHIFT_DATA_DIR/uploads
fi

ln -sf $OPENSHIFT_DATA_DIR/uploads $OPENSHIFT_REPO_DIR/php/wp-content/

Any uploaded data will now be stored outside of the OpenShift git repository and therefore won’t be overwritten each time you push to OpenShift.

Hopefully I’ve shown how straightforward is is to host applications on OpenShift Express. If you’ve got any questions, leave them as comments to the post.

Comments

  1. I must say this is a great article i enjoyed reading it keep the good work :)

    ReplyDelete
  2. Nice article, I’m interested is it possible to create alias to somedomain.com without www? And what exactly in a case of openshift cname record is? give/point to an example pliz :)

    ReplyDelete
  3. Nice article. How would you upload some initial data to the OPENSHIFT_DATA_DIR?

    ReplyDelete
  4. Wondering if you’ve seen http://log.amitshah.net/2011/12/blog-moved-to-wordpress-on-openshift/ — I moved to openshift from blogger.

    ReplyDelete
  5. Hi. I’m a technical writer for Red Hat, and wanted to point you to our documentation where you may find the information you are looking for regarding domain name aliases. Here is the link to the information that may help you: http://hurl.test.redhat.com/pugE6z. You can find all OpenShift documentation at docs.redhat.com. Let us know how you go! Thanks.

    ReplyDelete

Post a Comment

Popular posts from this blog

Creating a Joke Application in React

Introduction I've recently started learning React. I've been a backend developer for a long time, but have started to love doing client side work. As they say, the best way to learn is to practise. So here is a simple joke application that I've written in React. The source code for the application can be found on GitHub at: https://github.com/doobrie/react-joke Creating the project Whilst practising, I've quite often created projects from scratch, but this is quite tedious as the same steps need to be taken for each project. I needed to create the project structure, configure Babel, write some control scripts etc. Instead of doing that this time, I've used the create-react-app tool to scaffold the basics of an application. npx create-react-app This sets up everything that you need to get started with a React app. Coding As this is a simple project, I've created one react component, function app() . I've created this as a functional c...

Changing Default Search Provider in Firefox on Linux Mint

On Linux Mint, the default version of Firefox is installed and configured to allow the following search engines to be queried directly from the address bar: Yahoo! Startpage DuckDuckGo Wikipedia Mint defines these as the default available set of search engines based upon 3 criteria (funding to Linux Mint, privacy support and whether the search engine is non-commercial). Other search engines such as Google, Bing or Twitter, etc. can easily be added into the default version of Firefox however. To add a different search provider, browse to Search Engines At the bottom of the page, click on the icon of the requested search engine, then click on the ... button in the URL bar and select the Add Search Engine option. You then have the option to change the default search engine within Firefox preferences to your new choice.

The new Eclipse logo

In a blog post today, Ian Skerrett has announced the new logo for Eclipse. Last fall we [The Eclipse Foundation] started a process to  update the Eclipse logo . The existing logo had not been change since Eclipse was launched and it was showing its age. I am happy to announce we have finished the process and am pleased to introduce the updated Eclipse logo. The new logo has a fresh modern look to it, which I think is a good improvement and will stand Eclipse in good stead for the future. The new logo will be included with the next Eclipse release train, Luna, and gradually rolled out across the Eclipse site and projects. What do you think?  Do you like the new logo?  Add your comments below.