A few months back I decided to move my blog to Heroku. In this post I have explained how I deployed my WordPress blog on Heroku.

This blog post is the first of the two posts for running WordPress on Heroku. You can find the second post here: Considerations & Workarounds: WordPress on Heroku – 2 of 2  http://www.appcloud101.com/archives/7795

What is Heroku?

Heroku is a cloud platform as a service. You create applications in a language of your choice (e.g. Java, node.js, Ruby, PHP). Then you push your application to Heroku and make it available on the internet. Heroku will provide you with a URL of the form yourapp.herokuapp.com. You can bring your own domain name (e.g. purchase through GoDaddy.com) and attach it to this URL.

So How Do You Learn Heroku?

 lightbulbThe fantastic thing about Heroku is that there is nothing new to learn! Simply create your application in whatever language you think is best – and when you are done push it to Heroku. You are live! No need to wade through an ocean of documentation or hire experts to plan your hardware and software strategy.

As you sprint through your application development, make sure you spin up an instance of Heroku to do your testing in parallel. This way you will get familiar with all the knobs and pulls in Heroku and at the same time ensure that the bugs in your application are weeded out continuously.

Can you migrate an app which you have already created and run elsewhere to Heroku? Absolutely!

Get Started with Heroku


Option #1
“Real Easy” Heroku Guide

Three Step in 5 Minutes

1. Sign up for a free Heroku account

  https://signup.heroku.com/www-header

2. Deploy WordPress Build Pack from Technomile using the Heroku Button

 https://github.com/technomile/Heroku-WordPress

3. Write your blog!

Write what inspires you!


 

If you are interested, you can read about the Technomile WordPress Build for Heroku here:  https://www.heroku.com/partners-app-showcase



Option #2
“Get Your Hands Dirty” Heroku Guide

The above three step process (Option #1) is what I would recommend esp if you are starting afresh. However if you simply want to flex your developer chops, read on!
 screenshot
In this guide we shall examine how I deployed a fully complete PHP app – this WordPress blog – on Heroku.

Pls note that this blog itself is not running on Heroku at present.

So what is this WordPress thing? WordPress is nothing except a bunch of pre-written PHP code, which provides an easy way to organize and publish content on the internet. I think of WordPress as a PHP framework which I can extend to do all kind of stuff, not just post my daily ramblings. It takes care of a lot of routine stuff for me – user permissions, database access and more.

Step 1

Following the  Heroku Cheatsheet, I completed the first two sections – “Get Started” & “Prepare a Local Staging Directory”.

Then I set up my local development server.

Remember in enterprise dev environments, I may choose to have separate Heroku instances for development & testing, instead of maintaining a local environment.

However I have used a local dev environment approach and here are the steps I followed.

Step 2

Download & install WordPress on my local machine: https://wordpress.org/download/
Customize my WordPress instance the way I want.

Step 3

Copy the contents of my local WordPress installation root directory to my staging directory.

Step 4

Install notepad++ and search & replace in my files references to www.appcloud101.com/my_wordpress_directory with my remote address (my_app_name.herokuapp.com).

Step 5

Also correct the mappings in .htaccess file in my staging directory.

Step 6

Push contents of my staging directory to remote using the section “Deploy” in the Heroku Cheatsheet link included in this post.

Step 7

Export the local MySQL database and store it in a temporary location.

Step 8

Get the config variables of my remote database as follows:
D:wkdir git>heroku config –app myappname

Step 9

Add the config variables to my app
D:wkdir git>heroku config:add DATABASE_URL=mysql://… # Replace the “mysql://…” with the URL from CLEARDB_DATABASE_URL

Step 10

Edit wp-config.php in the WordPress root directory (in staging). Instead of entering my database name and other variables, I will pass the config variables names and Heroku will supply the values at runtime. Note how I commented out the default lines in wp-config.php which ask for database name, username, password and host:
/** The name of the database for WordPress */
$db = parse_url($_ENV[“DATABASE_URL”]);
define(“DB_NAME”, trim($db[“path”],”/”));
define(“DB_USER”, $db[“user”]);
define(“DB_PASSWORD”, $db[“pass”]);
define(“DB_HOST”, $db[“host”]);
// define(‘DB_NAME’, ‘database_name_here’);
/** MySQL database username */
// define(‘DB_USER’, ‘username_here’);
/** MySQL database password */
// define(‘DB_PASSWORD’, ‘password_here’);
/** MySQL hostname */
// define(‘DB_HOST’, ‘www.appcloud101.com’);

Step 11

Now download and install MySQL Workbench, connect it to remote ClearDB on Heroku: https://dev.mysql.com/downloads/workbench/5.2.html

Step 13

Import the local database file to my remote database using the MySQL Workbench.

Step 14

In my remote database, run sql queries to find and replace references to www.appcloud101.com with my remote app’s address.

Step 15

Now when I open a browser and navigate to my_app_name.herokuapp.com, I see my WordPress blog. I am live!

Does the “Get Your Hands Dirty” method seem tedious? Seems like a lot of work? You will learn a lot as well. It’s a lot of fun and all this is one time configuration only. And, after all Heroku is a developer’s delight! But if you are an organization who would rather run your business – go for the option #1 I have mentioned at the beginning. (WordPress BuildPack for Heroku)

 


The Plumbing

Software

List of software needed: MySQL Database, Apache Webserver and PHP 5.2 Runtime. Linux. WordPress.

 

Note – I decided to get the official binaries from wordpress.org not the pre-created builds for Heroku. I am not a fan of installing packaged code from unverified sources; apart from the fact that these builds may run into future upgrade & plugin compatibility issues.
 plumbing
A word about databases. Heroku supports different database flavours including Postgres, MySQL, Graph DB, Hadoop clusters and others. I chose MySQL simply because my local development system runs MySQL and I have some good tools to manipulate it.

 

You can run your WordPress blog on Postgres as well. In many cases Postgres on Heroku may be a good choice – Postgres supports technologies like Heroku Connect, External Objects and more for easy integration with your Salesforce org and other systems.

Development

My Dev environment: WAMP on local host, a local staging directory and the remote Heroku cloud.

 

I run WordPress on my local Windows 2007 server using WAMP for development and local testing. WAMP simply gives me an easy installation of Apache, MySQL and PHP. You can download these and install separately also.

 

For enterprise apps you would most likely use a Dev instance of Heroku itself for development or testing.

Staging

To deploy to Heroku, I first copy my files to a local git directory. Here is where I make changes to the files – I use notepad++ to find and replace all www.appcloud101.com references to my custom domain reference (technologyformanagers.com). I then push my changes to Heroku; and then on the remote MySQL database I again use a SQL query to find and replace all www.appcloud101.com references.

 

The changes to database I could have done locally also, but I would have to maintain a separate database locally (not a big deal).

 

My Mobile & Social Strategy

Mobile Strategy

I decided not to create a native/hybrid app, nor even a responsive site – for now. Instead, I created a site which looks equally good both on mobile and web, with large fonts and minimal navigation button. With the growing size of pocket devices and my desire to get the site out quickly this seemed the best plan of attack. A mobile app is coming though, stay tuned!

Social Strategy

I used social media groups (FB Groups & Pages, Google groups & LinkedIn Groups) for creating community of users around specific activities. As an individual blogger that works great for me. For enterprises, I would recommend leveraging Salesforce Communities.

Comments

For comments, instead of native WordPress comments, I use OAuth 2.0 to integrate with Facebook and Twitter so you can comment on posts and also share posts. I did not use any of the commenting & social login web services like Janrain, Gigya and Disqus. One – these are very expensive for what they do. Second, I don’t need users to login in to my site.

Trends which inspired me

As a general trend in CMS, many sites like Copyblogger have decided to do away with commenting all together for various reasons. You can visit their site to read about it. Many people are questioning the authenticity of hundreds of comments on many sites today.

 

All in all, engaging people through comment system is not my top priority. Providing real value knowledge which you can use is my top priority. If you have questions or comments, tweet them out to me, or engage with me on other better QA platforms like Stack Exchange.

Why Did I Choose WordPress?

I chose WordPress because it is Open Source, based on an easily extensible framework, and is well documented. Most common issues have been sorted out since it’s used by so many people. I have done a lot of customization in my WordPress both in the UX design (using HTML5/CSS/JavaScript) as well as in the code (PHP/JavaScript).

 

I have worked a lot with other portals also known nowadays as “User Experience Platforms” – Liferay (Java), Oracle Webcenter Suite 11g (Java), Drupal (PHP), Ghost (PHP), Microsoft SharePoint (.Net). For now I am sticking with WordPress though my long term roadmap is to migrate to Liferay.

Why Did I Choose Heroku?

First of all, I chose Heroku for my personal blog because I wanted to play with this amazing platform. Heroku makes my internet presence easy while giving me enterprise grade service.

There are some IaaS providers who claim to be elastic, automated cloud platforms – but in my humble opinion, no one today provides the unique blend of enterprise grade service with complete automation like Heroku does.

 

Heroku Takes Care of All Infrastructure

 

Heroku Takes Care of All Dev-Ops


Ultimately the benefit of Heroku lies in how it eliminates the need for infrastructure & Dev-Ops allowing you to focus on innovation.

How Do You License Compute Power?

You need processing power, file storage for your applications files and database for your application’s data. In Heroku, you license units of computing power called Dynos – each dyno has a certain amount of memory and CPU associated with it. When your application becomes popular and more people start accessing it, use the Heroku DX dashboard to increase the number of dynos for your application. Heroku is designed as an elastic cloud, you can decrease the amount of dynos for those times when you don’t need much compute power. Also, you can license database service as an add-on.

How Does Heroku Run My Apps?

 

Celadon Cedar-14 is Heroku’s default runtime stack and is a flexible, polyglot environment.

 

Polyglot support means that you can use many languages across and within my projects.

 

Include a Procfile with your applications to tell Heroku what to run. A Procfile is a text file in the root directory of your application that defines process types and explicitly declares what command should be executed to start my app.

 

Check Heroku docs for application specific tips – for example, for PHP apps, include a file called composer.json in the root directory of my app; using this file you can specify things like the version of PHP runtime you want from Heroku.

 

What’s happening inside Heroku? While Heroku does a lot in the background, you have complete visibility to what’s happening. Here’s how you can get info about what’s happening in your application: https://blog.heroku.com/archives/2011/6/24/the_new_heroku_3_visibility_introspection

Ok, So How Do you Become an Expert in Heroku?

There is no need to ‘learn’ Heroku. All you got to know is how it works conceptually, how to add database, the ephemeral nature of its file system etc. Then you develop in whatever language you love and push your app to Heroku using the cheat sheet link I have mentioned in this article.

While you can do a lot, if not everything, from command line interface (CLI) – it would be inefficient not to take advantage of the great new Heroku DX dashboard. That is why I am suggesting in the cheat sheet to do things (like create an app) on the Heroku DX dashboard and not through CLI. Use the Heroku DX as much as you can: https://dashboard.heroku.com/

Caution:

This post with WordPress on Heroku tips is not an official guide from Heroku. Please make sure that you try it in a “crash and burn” environment only. Refer to official Heroku guides on Heroku.com.


Here’s the Heroku Cheat Sheet for you: http://www.appcloud101.com/archives/4112

Here are some things to keep in mind while deploying WordPress on Heroku: “WordPress on Heroku Considerations” http://www.appcloud101.com/archives/7795