Sunday, April 15, 2012

Blogging with Wordpress in Cloud with OpenShift

From Official OpenShift homepage,
OpenShift is Red Hat's Cloud Computing Platform as a Service (PaaS) offering. OpenShift is an application platform in the cloud where application developers and teams can build, test, deploy, and run their applications. OpenShift takes care of all the infrastructure, middleware, and management and allows the developer to focus on what they do best: designing and coding applications.

Running Wordpress on OpenShift is easy. Here are the steps:

Register for an account at: https://openshift.redhat.com/app/account/new
Install Client Tools:
  • For Debian-based systems including Ubuntu, issue the following commands:
    # apt-get install ruby rubygems rhc
    
    If 'rhc' is unavailable, do this:
    # gem install json_pure
    # gem install rhc
    
  • For RPM based systems:
    # wget -O openshift.repo https://openshift.redhat.com/app/repo/openshift.repo
    # mv openshift.repo /etc/yum.repos.d/
    # yum install rhc
    # rm -f openshift.repo
    
Create Domain name (Namespace):
# rhc domain create -n  -l <emailaddress>
This domain is a third level domain. Any new application will inherit this domain name. Use the email address you used to sign up with OpenShift.

Create a new application:
# rhc app create -a wordpress -t php-5.3
Add MySQL Cartridge and PhpMyAdmin to application:
# rhc app cartridge add -a wordpress -c mysql-5.1
# rhc-ctl-app -e add-phpmyadmin-3.4 -a wordpress
You can now access PhpMyAdmin from http://wordpress-<domain>.rhcloud.com/phpmyadmin Note the username, password and host details.

Add Official Wordpress Bundle to Repository:
# cd wordpress/php 
# wget -O latest.tar.gz http://wordpress.org/latest.tar.gz
# tar -xf latest.tar.gz
# rm -f latest.tar.gz
# cd wordpress
# mv * ../
# cd ..
# git add .
# git commit -m "Initial Push"
Now, if you head over to http://wordpress-<domain>.rhcloud.com, you should see Wordpress complaining about 'wp-config.php'. Now, all you have to do is to modify 'wp-config' and add MySQL details from preceding cartridge command. Then,
# git commit -a -m "Edited wp-config.php"
Use your own domain name: To use your own domain name (assuming www.example.com),
# rhc-ctl-app -c add-alias --alias www.example.com -a wordpress
To get this domain working, add a CNAME record for www.example.com to wordpress-<domain>.rhcloud.com . DNS propagation may take some time. Key to win is patience.

Permanent file uploads: By default, all changes are lost when you push a git repository.
The OPENSHIFT_DATA_DIR and OPENSHIFT_TMP_DIR are designed as file system locations for data written/read by the application.
So, to preserve uploads, here is a workaround by adding following lines to wordpress/.openshift/action_hooks/build:
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/
This creates a symbolic link to Wordpress 'wp-content' directory. It's done. You are now blogging on Cloud. Pick up some words and let it flow around in your blog.

1 comment: