SitePoint Sponsor

User Tag List

Results 1 to 7 of 7
  1. #1
    Avid Logophile silver trophy
    ParkinT's Avatar
    Join Date
    May 2006
    Location
    Central Florida
    Posts
    2,343
    Mentioned
    192 Post(s)
    Tagged
    4 Thread(s)

    Rails - Switching to PRODUCTION

    In config/environment.rb there is a line (remarked out):
    Code:
    # 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:
    Code:
    # 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?
    Don't be yourself. Be someone a little nicer. -Mignon McLaughlin, journalist and author (1913-1983)


    Git is for EVERYONE
    Literally, the best app for readers.
    Make Your P@ssw0rd Secure
    Leveraging SubDomains

  2. #2
    Programming Team silver trophybronze trophy
    Mittineague's Avatar
    Join Date
    Jul 2005
    Location
    West Springfield, Massachusetts
    Posts
    17,252
    Mentioned
    196 Post(s)
    Tagged
    2 Thread(s)
    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.

  3. #3
    SitePoint Enthusiast
    Join Date
    Dec 2005
    Posts
    25
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    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.

    1. This first solution is considered the best.
    Open up the ~/.bashrc file
    Add the line
    Code:
    export RAILS_ENV="production"

    2. Or you could set the environment in your web server config file, perhaps using a local .htaccess file on Apache.

    3. Or you could edit environment.rb, commenting out the line you mentioned:
    Code:
    ENV['RAILS_ENV'] ||= 'production'

    I hope that helps.

  4. #4
    SitePoint Addict
    Join Date
    Feb 2007
    Posts
    270
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Depends on what web server you're using. If you're using the apache/fastCGI combination then you'd try something like this:

    Code:
    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.

  5. #5
    SitePoint Enthusiast
    Join Date
    Dec 2005
    Posts
    25
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    To set up a production database you must do three things.

    1. Create the database
    2. put the database connection details in database.yml
    3. 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.

    2. enter the database details in database.yml for the production database.

    3. run the migrations for the production database by forcing the ENV
    Code:
    $ rake db:migrate RAILS_ENV=”production”
    I think that should set you up.

  6. #6
    Avid Logophile silver trophy
    ParkinT's Avatar
    Join Date
    May 2006
    Location
    Central Florida
    Posts
    2,343
    Mentioned
    192 Post(s)
    Tagged
    4 Thread(s)
    Excellent!
    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.
    Don't be yourself. Be someone a little nicer. -Mignon McLaughlin, journalist and author (1913-1983)


    Git is for EVERYONE
    Literally, the best app for readers.
    Make Your P@ssw0rd Secure
    Leveraging SubDomains

  7. #7
    l º 0 º l silver trophybronze trophy lo0ol's Avatar
    Join Date
    Aug 2002
    Location
    Palo Alto
    Posts
    5,329
    Mentioned
    1 Post(s)
    Tagged
    0 Thread(s)
    You can also explicitly start up your app locally in production mode using:
    Code:
    script/server production
    .
    Zach Holman
    good-tutorialsblogtwitterlast.fm


Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •