In config/environment.rb there is a line (remarked out):
# ENV['RAILS_ENV'] ||= 'production'
and I would assume making that line active is the way to switch from development mode to production mode.
But the comment above the line states:
# Uncomment below to force Rails into production mode when
# you don't control web/app server and can't set it the proper way
I have complete control over the server. It is physically in my lap!
So the real question becomes; what is the proper way to switch to production mode?
How do I handle the migration and databases?
When I uncommented that line I was unable to use 'rake db' tasks because rails still referenced the development database.
Can someone give me some guidance on how to take a completed app [running in development mode] into production?
Your production server is in your lap? I think what is meant by production server is an online (remote) hosted server, not a lap-top.
I must admit, I'm cheating here a little. This advice is from Deploying Rails Applications by Ezra Zygmuntowicz (Pragmatic Programmers, 2008) pp54-55.
According to the book there are three ways to set the RAILS_ENV variable for your application.
- This first solution is considered the best.
Open up the ~/.bashrc file
[INDENT]Add the line
Or you could set the environment in your web server config file, perhaps using a local .htaccess file on Apache.
Or you could edit environment.rb, commenting out the line you mentioned:
ENV['RAILS_ENV'] ||= 'production'
I hope that helps.
Depends on what web server you're using. If you're using the apache/fastCGI combination then you'd try something like this:
FastCgiConfig -maxClassProcesses 20 -maxProcesses 20 -minProcesses 1 -processSlack 1 -initial-env RAILS_ENV=production -idle-timeout 120
IIRC, Mongrel needs something like "-e production" on it's startup line.
To set up a production database you must do three things.
- Create the database
- put the database connection details in database.yml
- run the migrations
Say you are using MySQL:
1. login to mysql on your production server and create your production database.
Create a user for the database and give him all the privileges.
enter the database details in database.yml for the production database.
run the migrations for the production database by forcing the ENV
$ rake db:migrate RAILS_ENV=”production”
I think that should set you up.
The combination of answers from Pootsy was the ticket!
I did not know about the rake 'RAILS_ENV' parameter: cool!
Thanks, Arlen. I am running fastCGI. I will try that.
Yes, Mittineague, I am using a laptop.
This is a very small, internal, proof-of-concept application that will be moved to a corporate server very soon.
The laptop gives me a great opportunity to 'work on the road' with the proprietary application.
But you were very perceptive to catch that.
You can also explicitly start up your app locally in production mode using:
This topic is now archived. It is frozen and cannot be changed in any way.