Here's how to set up cloud hosting with Heroku and Amazon S3.
1. Add the Heroku extension
If you run the engine for multisites, you need LocomotiveCMS to tell Heroku to update the domains when you add one in the LocomotiveCMS backoffice.
Open your Gemfile file in your LocomotiveCMS application and add the following statement right after the one about the LocomotiveCMS engine.
gem 'locomotive-heroku', '~> 0.1.0', :require => 'locomotive/heroku'
gem 'thin', :group => 'production'
While you’re at it, add the following line right before your first gem entry:
ruby '2.1.3'
Then, in your terminal, run:
bundle install
2. Create the Heroku app from your app folder
git init .
heroku create <YOUR APP NAME>
heroku config:add BUNDLE_WITHOUT=development:test
3. Set up a remote Mongodb database
You can find more information here.
heroku addons:add mongohq:sandbox
Modify the configuration for the production mongodb database in the config/mongoid.yml file.
production:
sessions:
default:
uri: <%= ENV['MONGOHQ_URL'] %>
4. Enable emails
LocomotiveCMS needs to send emails and Heroku provides a nice way to send emails for free without configuring a whole mail server on your own. You can find more information here.
heroku addons:add sendgrid:starter
Add the following lines in your config/environments/production.rb file.
config.action_mailer.delivery_method = :smtp
config.action_mailer.smtp_settings = {
:address => 'smtp.sendgrid.net',
:port => 25,
:authentication => :plain,
:user_name => ENV['SENDGRID_USERNAME'],
:password => ENV['SENDGRID_PASSWORD'],
:domain => ENV['SENDGRID_DOMAIN']
}
5. Configure Heroku to work with your Amazon S3 credentials
Unless you modified your config/initializers/carrierwave.rb file, Carrierwave should be set up for Amazon S3 in the production environment.
heroku config:add S3_KEY_ID=<YOUR S3 KEY ID>
heroku config:add S3_SECRET_KEY=<YOUR S3 SECRET KEY>
heroku config:add S3_BUCKET=<YOUR S3 BUCKET NAME>
heroku config:add S3_BUCKET_REGION=<YOUR S3 BUCKET REGION>
Note: For S3 Bucket Region var, here is the correspondance table between your ‘human’ bucket region name, and it’s endpoint :
Region | Location Constraint |
---|---|
US Standard * | us-east-1 |
US West (Oregon) Region | us-west-2 |
US West (Northern California) Region | us-west-1 |
EU (Ireland) Region | eu-west-1 |
Asia Pacific (Singapore) Region | ap-southeast-1 |
Asia Pacific (Tokyo) Region | ap-northeast-1 |
South America (Sao Paulo) Region | sa-east-1 |
6. Edit your Locomotive config file.
Open your config/initializers/locomotive.rb file and add the following lines :
config.hosting = {
:target => :heroku,
:api_key => ENV['HEROKU_API_KEY'],
:app_name => ENV['HEROKU_APP_NAME']
}
7. Configure Heroku credentials
Specify your credentials :
heroku config:add HEROKU_API_KEY=<YOUR HEROKU API KEY>
heroku config:add HEROKU_APP_NAME=<YOUR APP NAME>
8. Pre-compile your assets
We suggest you to compile your assets locally so that if there is an issue with your assets, you will be able to debug it more easily.
It is very important that you disable the initialize_on_precompile option in the config/application.rb file of your application:
module YourApplication
class Application < Rails::Application
...
config.assets.initialize_on_precompile = false
...
end
end
Then, in your terminal, run the following command
bundle exec rake assets:precompile
9. Launch it !
In your terminal,
git add .
git commit -am "launch it"
git push heroku master
Then, visit your application
heroku open