Hosting this blog on openshift

I’m sure there are hundreds of posts already on how to do this. Openshift has a one click installation as well. It’s ok. I’ll still write my take on it. The idea is to learn something about how openshift works and how to deploy a simple application on the cloud. A one click install does not provide learning opportunity. However, taking the longer route and doing a few mistakes in the process does exactly that.

Let me make it clear, this is not written after I completed the process. Instead, I am yet to start the process. By the time I finish, I should be finished with the porting of my existing blog from a rented server space to openshift cloud. I owe a lot to this blog by amit shah apart from the documentation found on openshift and stackoverflow.

And to those who don’t know what is openshift, it is just like amazon AWS.

Create an account in openshift, go to the settings page and create a namespace as well.

Install all the tools that are required for deploying your application (in this case, a wordpress application) into the cloud. Installation of ruby, git and rhc are documented in the following openshift documentation.

I also prefer to have these things done in a linux environment as everything just works out of the box (or rather command line). In windows, I normally have to set a whole lot of environment variables, download putty for ssh related stuff and so on. Anyway, it is a personal choice. You could try cygwin though I haven’t tried it myself in this particular case.

Once those are installed, it is time to setup SSH keys. This allows you to remotely access your application. On linux, all you have to do is run

rhc setup.

On windows, you will have to play around with putty first. A detailed explanation is given here: Openshift Remote access.

Prepare backend…

First, type

rhc cartridge list

This gives a list of all the cartridges that are available for you to create apps. Cartridges are nothing but platforms; ex: php, node.js, python, ruby etc. You will have to use the correct version numbers in the below commands to get things working correctly.

In the terminal, just type the following:

rhc app create -a xyz-t php-5.3

where xyz is the name of the application and can be anything. This will take a few seconds and will create an application on the server. Also a copy of the code for your application will be checked out locally into a folder with the same name as your application.

Now, add mysql cartridge to this app using the command:

rhc cartridge add mysql-5.1 -a xyz

Note down the credentials that are output by the terminal somewhere.

Now, add phpmyadmin which is just like the previous step:

rhc cartridge add phpmyadmin-4 -a xyz

The credentials should be the same as the previous one.

Now login to the following link: https://xyz–namespace.rhcloud.com/phpmyadmin/ . This is your own phpmyadmin page. Replace the app name and namespace with your own. Create a new user and a database there. The database should have full privileges for the user.

Now deploy wordpress…

Download the wordpress bundle from WordPress.org. Unzip that file and place the contents of that file into the php folder of your app folder. It should look similar to the following example.