Repository navigation
3 Set up a Production Server
There are a range of reasons you might want to set up a production server. You can use it to test a fully live version of Loomio and/or run your own private instance of Loomio.
If you're trying to install Loomio on an actual server (as in, not just for development on your local machine), you'll need to do a few things differently. Make sure you have set up the following environment variables:
-
SECRET_COOKIE_TOKEN=123456789012345678901234567890(replace with a random string of alphanumeric characters, at least 30 chars long) -
AWS_ACCESS_KEY_ID=your-key-here(you'll need to set up an AWS S3 account for hosting user uploads. ie user images) AWS_SECRET_ACCESS_KE=your-access-key-
AWS_UPLOADS_BUCKET=your-loomio-uploads(you'll need to create a bucket with this name on your S3 account) -
FOG_DIRECTORY=your-loomio-assets(you'll need to create a bucket with this name on your S3 account) -
CANONICAL_HOST=www.yourloomiosite.com(the web domain for your loomio server) -
SENDGRID_USERNAME=your-sendgrid-username(we use SendGrid for sending emails, which you'll need to create an account for. If you'd rather not use sendgrid, you'll need to edit production.rb) SENDGRID_PASSWORD=your-sendgrid-password-
EXCEPTION_RECIPIENT=you@example.org(any errors that occur on your loomio instance will be sent to this email address)
If you're not using Heroku, edit the .env file in the root of your app directory (unconfirmed whether or not this actually works).
The following is a tutorial for setting up Loomio on Heroku.
If you haven't already, you'll need to set up a Heroku account, and install the Heroku toolbelt.
navigate to the root for your local Loomio repo, then in terminal, run
$ git push heroku master
rename your heroku app, running e.g.
$ heroku rename johnsloomiotest
this needs to be unique and will set your site address to the form johnsloomiotest.herokuapp.com
Visit http://aws.amazon.com/free/ click ‘Get Started for free’ and create a AWS account (requires a credit card and cell phone to verify)
Once set up go to https://console.aws.amazon.com/s3/home Click ‘set up bucket’, giving it a sensible name. Location and tracking shouldn't matter
Go to https://portal.aws.amazon.com/gp/aws/securityCredentials under ‘Access Credentials’, click ‘Create a new Access Key’
Leave this page open for copying details later.
in terminal, run
$ heroku addons:add sendgrid:starter
This sets up the free starter for Sendgrid. Follow the verify link to verify heroku install (may require credit card) Go to https://addons.heroku.com/sendgrid and in dropdown ‘select an app..’ select your app.
Go to the app page e.g. https://dashboard.heroku.com/apps/johnsloomiotest/resources and click on SendGrid to complete any missing setup (this took me to http://sendgrid.com/account/wizardSignup)
in terminal, run
$ heroku config
you should see your SendGrid user and password details listed
Run the following command (replace "*replace*" with the appropriate information. see the top of this page for more info):
$ heroku config:set SECRET_COOKIE_TOKEN=*replace* AWS_ACCESS_KEY_ID=*replace* AWS_SECRET_ACCESS_KEY=*replace* AWS_UPLOADS_BUCKET=*replace* FOG_DIRECTORY=*replace* CANONICAL_HOST=*replace*.herokuapp.com EXCEPTION_RECIPIENT=*replace@thisemail.org*
To check that you've added your config variables correctly, run:
$ heroku config
Run the following commands:
$ heroku run rake db:migrate
$ heroku run rake db:seed
Log into the Heroku console and create a user for yourself in the database. e.g.:
$ heroku run console
...
irb> user = User.create(name: "Your Name", email: "your-email@example.org", password: "yourpassword")
irb> user.is_admin = true
irb> user.save!
In order for Loomio to work correctly, it needs to run background jobs. The easiest way to do this is to run heroku ps:scale worker=1. However, this will cost you $35/month if you leave it on all month (run heroku ps:scale worker=0 to turn it off).
If you're just trying to test Loomio on Heroku for a moment, run heroku run rake jobs:work in your console while you're testing, and then make sure to kill the process (ctrl + c) once you're done testing.
Alternatively, if you're using Loomio for serious purposes but don't want to pay $35/month, you can install Hirefire. For $10/month, it can automatically start workers when you need them and turn them off when you don't. This will hopefully at least half your costs (probably more).
By default, if you're only using 1 web dyno on Heroku (free), Heroku will automatically idle your site when it's not being used. This is so that Heroku can save on resources (a lot of people use their free version for simple testing). However, because of this, when someone visits your site for the first time in a while, it will take a long time to load up.
If you're just using Heroku as a testing environment, we recommend you to leave this behavior the way it is. However, if you're using Heroku to host a proper Loomio instance that other people will be using, you can disable the idling by simply installing the New Relic addon (free version). New Relic pings the site every 30 seconds, which will prevent it from ever going into idle state.
At this point, it's probably a good idea to restart the server:
$ heroku restart
You'll probably have to wait a minute and load the page a few times before it starts working.
Yay!