How can I change my Rails application to run in production mode? Is there a config file, environment.rb for example, to do that?
This question is related to
ruby-on-rails
development-environment
production-environment
In Rails 3
Adding Rails.env = ActiveSupport::StringInquirer.new('production')
into the application.rb and rails s
will work same as rails server -e production
module BlacklistAdmin
class Application < Rails::Application
config.encoding = "utf-8"
Rails.env = ActiveSupport::StringInquirer.new('production')
config.filter_parameters += [:password]
end
end
This would now be
rails server -e production
Or, more compact
rails s -e production
It works for rails 3+ projects.
Change the environment variable RAILS_ENV
to production
.
for default server : rails s -e production
for costum server port : rails s -p [port] -e production, eg. rails s -p 3002 -e production
If you're running on Passenger, then the default is to run in production, in your apache conf:
<VirtualHost *:80>
ServerName application_name.rails.local
DocumentRoot "/Users/rails/application_name/public"
RailsEnv production ## This is the default
</VirtualHost>
If you're just running a local server with mongrel or webrick, you can do:
./script/server -e production
or in bash:
RAILS_ENV=production ./script/server
actually overriding the RAILS_ENV constant in the enviornment.rb should probably be your last resort, as it's probably not going to stay set (see another answer I gave on that)
RAILS_ENV=production rails s
OR
rails s -e production
By default environment is developement.
You can also pass the environment to script/server:
$ script/server -e production
$> export RAILS_ENV=production
Please make sure you have done below in your environment.rb file.
ENV['RAILS_ENV'] ||= 'production'
If you application runs in shared hosting environment or phushion passenger, you might need to need make changes in .httaccess (inside public folder) and set mode as production.
rails s -e production
This will run the server with RAILS_ENV
= 'production'
.
Apart from this you have to set the assets path in production.rb
config.serve_static_assets = true
Without this your assets will not be loaded.
It is not a good way to run rails server in production environment by "rails server -e production", because then rails runs as a single-threaded application, and can only respond to one HTTP request at a time.
The best article about production environment for rails is Production Environments - Rails 3
As others have posted: rails server -e production
Or, my personal fave: RAILS_ENV=production
rails s
By default server runs on development environment: $ rails s
If you're running on production environment: $ rails s -e production
or $ RAILS_ENV=production rails s
If mipadi's suggestion doesn't work, add this to config/environment.rb
# force Rails into production mode when
# you don't control web/app server and can't set it the proper way
ENV['RAILS_ENV'] ||= 'production'
Source: Stackoverflow.com