Switching between Development and Production mode

(Claus Strasburger) #1

Continuing the discussion from Development mode super slow:

This might seem like a dumb question, but what is the preferred way to switch Discourse from development to production and vice-versa?

I18n fallback not working
(Kuba) #2

Same as any other Rails app, for example: development environment - Change a Rails application to production - Stack Overflow

(Ted Lilley) #3

tl;dr version:

bundle exec thin start -d -e production (or drop the -d to run interactively)


bundle exec rails s RAILS_ENV=production

Note that this will use the production database config from config/database.yml, which is usually not the same as your development db. You’ll either need to set up another db under the production schema (migrations and all), copy your development db to production, or change database.yml to point to your development schema.

Here’s a good article on the thin command.

(Richard Phillips) #4

I’m a ROR newbie, but have Discourse up and running on EC2 - pretty pleased so far (though this was about 10 hours work!!)… I have it proxied behind apache, cluster of thin’s and I think most things are working fine.

Wanted to try this full strength, so switched thin to use production; also made sure the database.yml is the same for production and development… but boom, site does not load at all…

I get the following error:

** [Airbrake] Failure: Net::HTTPUnprocessableEntity
** [Airbrake] Environment Info: [Ruby: 2.0.0] [Rails: 3.2.12] [Env: production]
** [Airbrake] Response from Airbrake:
No ApiKey

Any help gratefully received!

(Juan Manuel Formoso) #6

Did you find a solution for this? I’m having the exact same problem

(Chris Sims) #7

Make sure to follow directions here to get airbrake set up in production:

(Juan Manuel Formoso) #8

Should AirBrake run in production? I thought it shouldn’t. See here: 301 Moved Permanently

EDIT: A more accurate question is: Can I disable the use of AirBrake?

(Richard Phillips) #9

I seem to have solved it… not sure this was the total solution as I tried to re-install the airbrake gem… which I’m not sure was needed…

The main thing was to sign up for a free airbrake account

When you login you can see an API key, copy this:
export RAILS_ENV=production
bundle install
rails generate airbrake --api-key

I then ran into other errors, but slowly working my way through! btw, possible above advice is wrong, incomplete or some of it not needed - am ROR newbie so rather hacking around to solve things as I go…

If you get an error that assets are not precompiled, go for…
RAILS_ENV=production bundle exec rake assets:precompile
This seems to be needed in production but not development…

Good luck!

(Jack James) #10

You don’t need airbrake. I’ve been running a production install perfectly fine without it. As you mentioned, you do need to precompile assets, but doing so will break the development install (at least it does for me) unless you remove them before switching back.

(Sam Saffron) #11

I tire of these nonsense Airbrake errors, just committed a fix so we never try loading the ‘airbrake’ gem unless the config is there:

(Juan Manuel Formoso) #12

After running the application with -e production I’m still seeing the time it takes requests to respond on the left, which I assume is a development feature.

Do I need to do something else? Do I have to explicitly disable that anywhere? Does it show it to me only because I’m admin?

(Ted Lilley) #13

I forgot to include the -d argument to daemonize the process and run it in the background.

I’ve edited my earlier post to reflect that.

(Daniel Watkins) #14

I think this is enabled in production mode for administrators; this threw me off as well.

(Chris Sims) #15

As well as moderators, I believe?

(Repz) #16

Maybe I’ve missed something but to put discourse in production, i need to enter the docker container and run

su - discourse
cd /var/www
bundle exec thin start -d -e production

Am i right ?

(Felix Freiberger) #17

The docker container should always run in production mode by default. There’s no need to manually run a bundle exec.

(Repz) #18

Thanks for your lightnings =)