How to set up wordpress blog in heroku in just 30 mins

First of all, this process require some technical knowladge (how to use terminal, working with git). So if you want to dodge that, the easiest way to set up a wordpress blog is to simply goto wordpress.com and register to a new wordpress blog!

But if you still want to set up a blog in heroku, keep reading.

You’ll need:
Register to heruko
– Working terminal (iterm, bash etc..)
– Git CLI – github – see here
Heruko CLI

Lets Start – Create wordpress heruko in 30 mins

Lets start by downloading and unzip wordpress on your machine

curl -sS http://wordpress.org/latest.zip
unzip latest.zip
mv latest wordpress
cd wordpress
touch Procfile
touch composer.json
mv wp-config-sample.php wp-config.php
  1. we download wordpress.
  2. we unzip the file – if you don’t have unzip on your machine run “sudo apt-get install unzip” to get it (for linux/ubuntu).
  3. change the file name to wordpress, you can change the name to “blog” if you want.
  4. go into wordpress folder.
  5. create Procfile for heroku (we’ll use it later).
  6. create composer.json – if you don’t have composer – just run this command: “curl -sS https://getcomposer.org/installer | php” than, if composer doesn’t work, maybe you’ll need to run it from php like that: “php composer.phar”.
  7. change config name, as part of the installation (maybe you’ll need to do it after you push everything to heroku and install wordpress) – otherwise wordpress will request you to do the installation again and again even if you already did it once.

Proc File

Just copy the next line into Proc file:

web: vendor/bin/heroku-hhvm-ngin

Composer.json

Copy he next line into composer.json

{ "require": { "hhvm": "3.5.1" } }

Open wp-config.php

find and replace those lines of code:

$db = parse_url(getenv('DATABASE_URL') ? getenv('DATABASE_URL') : getenv('CLEARDB_DATABASE_URL'));

/** The name of the database for WordPress */
define('DB_NAME', trim($db['path'], '/'));

/** MySQL database username */
define('DB_USER', $db['user']);

/** MySQL database password */
define('DB_PASSWORD', $db['pass']);

/** MySQL hostname */
define('DB_HOST', $db['host']);

/** Database Charset to use in creating database tables. */
define('DB_CHARSET', 'utf8');

/** The Database Collate type. Don't change this if in doubt. */
define('DB_COLLATE', '');

Find those env config and replace with this code:

define('AUTH_KEY', getenv('AUTH_KEY'));
define('SECURE_AUTH_KEY', getenv('SECURE_AUTH_KEY'));
define('LOGGED_IN_KEY', getenv('LOGGED_IN_KEY'));
define('NONCE_KEY', getenv('NONCE_KEY'));
define('AUTH_SALT', getenv('AUTH_SALT'));
define('SECURE_AUTH_SALT', getenv('SECURE_AUTH_SALT'));
define('LOGGED_IN_SALT', getenv('LOGGED_IN_SALT'));
define('NONCE_SALT', getenv('NONCE_SALT'));

Set Up Heroku & Git

Now we’ll generate git project and heroku project.

composer update --ignore-platform-reqs
git init
git add .
git commit -m "[INITIAL] wordpress blog"
heroku create
heroku addons:add cleardb
heroku addons:add sendgrid
  1. First we create composer lock file.
  2. we generate git project
  3. we add make sure all files are going to be track by git.
  4. we add commit.
  5. generate heroku project.
  6. add cleardb (cleardb is limited to 5MB for free and anything else cost money).
  7. add sendgrid for email supports (reset pass etc..)

Now we’ll need to set the ENV data with random values from here.

heroku config:set AUTH_KEY=''
heroku config:set SECURE_AUTH_KEY=''
heroku config:set LOGGED_IN_KEY=''
heroku config:set NONCE_KEY=''
heroku config:set AUTH_SALT=''
heroku config:set SECURE_AUTH_SALT=''
heroku config:set LOGGED_IN_SALT=''
heroku config:set NONCE_SALT=''

Just populate the above code with the random salt from the link above and run that code in the console folder of heroku.

Deploy

git push heroku master
heroku open
  1. We push herok master to production – and by doing so we trigger heroku deploy process.
  2. That command will open our project at heroku – xxx.herokuapp.com

Lets set your domain name

The easy way to set a domain name is to use CNAME alias – because heruko doesn’t provide DNS services. For more information on how to set your domain name go to heruko help center.

Set Wordpres to a Subfolder

This step i optional, But if you want to set up your blog in a subfolder (www.example.com/blog) than follow this tutorial here – with this tutorial you’ll be able to move a Root install to its own directory.

One of the steps in the above tutorial require us to move wordpress core files into the inner folder (“blog” or anything else you want) – here is a command that includes those files:

mv index.php license.txt readme.html wp-activate.php wp-admin/ wp-blog-header.php wp-comments-post.php wp-config.php wp-content/ wp-cron.php wp-includes/ wp-links-opml.php wp-load.php wp-login.php wp-mail.php wp-signup.php wp-trackback.php xmlrpc.php wp-settings.php blog/

Redirect To WWW domain

Another good SEO practice is to forward/redirect the domain from http://lioramsalem.com to http://www.lioramsalem.com. And there are few ways of doing it – one way is to simply add htaccess redirect (edit or create .htaccess file – make sure you add the dot at the start!):

RewriteEngine On
RewriteCond %{HTTP_HOST} !^www\. [NC]
RewriteRule ^(.*)$ http://www.%{HTTP_HOST}/$1 [L,R=301]

If you use CNAME alias you may have problems to set the domain without WWW to connect to your heroku app – so if you have this problem, but with WWW the CNAME alias work – than all you need to do is to redirect the domain without WWW (301/302 redirect) from your domain provider UI to the domain with WWW.

And if you host your blog at subdir and you want to redirect the user to the subdir (for example lioramsalem.com/blog) just use this simple PHP redirect code inside the root domain.

<?php // Permanent 301 Redirect via PHP
header(“HTTP/1.1 301 Moved Permanently”);
header(“Location: http://www.lioramsalem.com/blog”);
exit();
?>

Change my domain to whatever you want.

The following next steps should be to choose your blog theme, install plugins, and write your first blog post.

Extras

  1. clearDB will cost you money after the first 5MB, but you can replace it with Amazon RDS and once you generate your new DB at RDS – just run this line of code with your host, username, password, and DB name:
    heroku config:set DATABASE_URL=’mysql://username:password@hostname/dbname’
    you’ll probably need to set amazon group security under networking -> VPC -> Security Groups -> Create Group with mysql/aurora port 3306, tcp protocol with 0.0.0.0/0 source (here).
  2. If you end up with “vendor” folder, you’ll want to gitignore it and avoid pushing it to heroku – just create “.gitignore” file and add “vendor/” to the file.
  3. Good way to debug errors on heroku server is to type in the console folder “heroku logs -t” than you’ll get all the logs from the server and see if something goes wrong.
  4. In you heroku dashboard application on the top right, you can click “more” than “Restart all dynos” in case of any error or problems with the server.
  5. If you have problems with heroku cli, than you can configure ENV variables, domains and other stuff via the dashboard inside “Settings” tab.
  6. If you want to install plugins, themes or update wordpress – do so from heroku install not from wordpress dashboard (wordpress can’t modify files in heroku). For example, inside wp-content folder you can place your plugins or themes – than push to heroku in production and activate the themes/plugins in wordpress dashboard.
  7. In case you get problems with wordpress dashboard due to changes to the domain or anything else, remember that you can alway change wordpress related configuration in the Database itself (wp_options for settings, wp_users for users) etc…

Good Luck!

Leave a Reply

Your email address will not be published. Required fields are marked *

All rights reserved 2024 ©