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
- we download wordpress.
- 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).
- change the file name to wordpress, you can change the name to “blog” if you want.
- go into wordpress folder.
- create Procfile for heroku (we’ll use it later).
- 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”.
- 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
- First we create composer lock file.
- we generate git project
- we add make sure all files are going to be track by git.
- we add commit.
- generate heroku project.
- add cleardb (cleardb is limited to 5MB for free and anything else cost money).
- 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
- We push herok master to production – and by doing so we trigger heroku deploy process.
- 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
- 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). - 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.
- 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.
- 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.
- If you have problems with heroku cli, than you can configure ENV variables, domains and other stuff via the dashboard inside “Settings” tab.
- 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.
- 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!
Lior Amsalem embarked on his software engineering journey in the early 2000s, Diving into Pascal with a keen interest in creating, developing, and working on new technologies. Transitioning from his early teenage years as a freelancer, Lior dedicated countless hours to expanding his knowledge within the software engineering domain. He immersed himself in learning new development languages and technologies such as JavaScript, React, backend, frontend, devops, nextjs, nodejs, mongodb, mysql and all together end to end development, while also gaining insights into business development and idea implementation.
Through his blog, Lior aims to share his interests and entrepreneurial journey, driven by a desire for independence and freedom from traditional 9-5 work constraints.
Leave a Reply