Let's reveal the code!

Hosting WordPress Blog on Heroku with support of Postgres

WordPress on Heroku

To have a WordPress blog hosted on Heroku is a pretty good experience that I’m sharing with you. Also we will talk about how to configure WordPress to work with Postgres database.

  1. First get a free account on Heroku, you can use this simple guide for the required steps
  2. On your machine, create an empty project directory and initialize your local git repository for the project.

  3. Download the latest repository from WordPress.

  4. Copy wordpress directory content to ‘wp_blog’ directory created earlier. Now you are ready to push the code to your local git repository.

  5. Create your heroku app with Cedar stack and push your wordpress project content to this app.

  6. For the database, you know that by default WordPress supports MySQL database. But if you choose to use Postgres database for any reason, you should configure your WordPress application to use Postgres database by installing Postgres WordPress plugin.
    For that purpose you can use pg4wp plugin. For installation you can follow these steps

    noteNote: You will need to modify little thing for the plugin to work; in the plugin folder pg4wp find driver_pgsql.php file, go to line 80 and modify it so that it uses “DB_NAME” instead of “template1″ as a test for database connection.

  7. Install Heroku Postgres Dev plan which is free. Of course you can upgrade later to any other proper plan according to your website needs, which is explained here

    Add Heroku Postgres

    get the config var HEROKU_POSTGRESQL_COLOR_URL which contains the URL used to access the newly provisioned Heroku Postgres service.

    Then use the HEROKU_POSTGRESQL_COLOR_URL (ex: HEROKU_POSTGRESQL_RED_URL) you gor from the previous step to promote your app to store the location of your primary database in DATABASE_URL config var (This step is recommended by Heroku)

    You can get more information here

  8. Copy wp-config-sample.php file to wp-config.php. Open wp-config.php and comment all MySQL settings, then add the following code to wp-config.php

  9. Now you are ready to commit your changes and push them to Heroku.