Question

Rails 4.1.4 Production environment, Ubuntu Apache/Passenger

  • Posted August 4, 2014

I’m getting the error

App 2280 stderr: [ 2014-08-04 18:45:00.6935 2301/0x9a59598(Worker 1) utils.rb:72 ]: *** Exception RuntimeError in Rack application object (Missing secret_key_base for 'production' environment, set this value in config/secrets.yml) (process 2301, thread 0x9a59598(Worker 1)):

But I’m sure I’d run export SECRET_KEY_BASE=xxx and ruby -e 'p ENV["SECRET_KEY_BASE"]'. Have went through a page of Google search results. Not sure what else I’m missing. Setup is as per title.

Side question. Is there anyway we can find back questions we’d asked? I found a solution to my pass problem but I have no idea how to get the question back.

Subscribe
Share

Submit an answer
You can type!ref in this text area to quickly search our full set of tutorials, documentation & marketplace offerings and insert the link!

These answers are provided by our Community. If you find them useful, show some love by clicking the heart. If you run into issues leave a comment, or add your own answer to help others.

Rails default /config/secrets.yml looks like this:

development:
      secret_key_base: # random string
test:
      secret_key_base: # random string
production:
      secret_key_base: <%= ENV["SECRET_KEY_BASE"] %>

It is OK to keep test and development secret key base in your (possibly public) codebase, however, the secret key on production should be set up within server environment. We are running Ubuntu 14.04, here is how we set up our SECRET_KEY_BASE environmental variable: ssh into your production server and run sudo nano /etc/environment. This will open the environment file in nano text editor. You need to add two lines at the bottom of this file:

export SECRET_KEY_BASE=<rake secret>
ruby -e 'p ENV["SECRET_KEY_BASE"]'

Where <rake secret> is the output you get when running rake secret in console (it will be a string of random characters just like # random string for development and test secret_key_base). Source /etc/environment or restart the server and test by running echo $SECRET_KEY_BASE.

Make sure you are in development /testing.

Put this in virtual host configuration:

RailsEnv development

Worry about Secrets once you go production mode

Try adding it to config/secrets.yml:

production:
  secret_key_base: XXX

Is there anyway we can find back questions we’d asked? I found a solution to my pass problem but I have no idea how to get the question back.

That’s not supported at the moment, however, it should be soon :) You can search for it until then (using the search bar at the very top of this page).