Deployment
So far, we have used Rails to develop, test and demonstrate a web application. Since the web browser was running on the same computer as Rails and its web server, we could simply access the web application using localhost as part of the URL. Here, however, we discuss options for accessing the web application over the internet. The following sections present options ranging from worst performance (but simplest) to the best performance.
Running Rails in the development environment
If we don't care at all about performance, we can simply run the server in the default development environment. If the computer is on the internet and has an IP number (example: 67.186.79.78), the reviews web application could be accessed with this URL:
If your computer has a registered host name (example: it232.com) through a Domain Name Server (DNS), you can access the web application accordingly:
Finally, if you start the server with this option:
The server will run on port 80, which is the default port for a URL. This way, the URL does not need to specify the port number:
Note that some internet service providers block port 80, which will prevent you from running the server on this port.
Running Rails in the production environment
Performance is greatly increased by running a Rails application in the production environment. Here are some important differences from the development environment:
- Ruby classes are not reloaded with each request.
- Every database communication is not logged.
- Caching is available for pages, actions and page fragments.
- Assets (e.g. CSS and JS files) are compressed into one file.
- Users are presented with a short (hopefully helpful) error message rather than a code trace.
All but the last item improves the performance of the web application.
In order to run your web application in the production environment, you need to do the following steps:
- Create the database for the production environment:
bundle exec rake db:schema:load RAILS_ENV=production
- Since the database is empty, you'll need to add any needed
initial
records, possibly through the console in the production
environment:
rails console production
- Precompile the assets files
bundle exec rake assets:precompile
- Start the server in the production environment using a port of your choice:
rails server -e production -p 80
If you are testing with the WEBrick server, you will also need to set the following line in the config/environments/production.rb file:
config.serve_static_assets = true
Assuming you have a recent installation of Rails, your Rails application uses Mongrel as the web server. Mongrel passes all web requests to your Rails application.
This diagram illustrates this simple configuration, where Mongrel is the only web server operating in this deployment:

Using a front-end web server
Mongrel is not intended as an efficient server for static pages. A common deployment strategy uses a production-quality web server (e.g. Apache) on the front-end:

Front-end server with multiple back-end instances
A production-quality server such as Apache is usually multi-threaded and can handle multiple requests simultaneously. Since Mongrel and the rail application is single-threaded, handling multiple requests simultaneously involves creating multiple instances of Mongrel running the rails application:

Servers such as Apache can balance the load of requests among the multiple instances of back-end servers. Phusion Passenger uses this approach.
Production Database
Unless your application will only have a few users accessing the application at a time, you will probably want to use a production-quality database such as MySQL, which can better handle multiple requests at a time. You will either need to create a database in MySQL or ask a system administrator to do it for you. With the database name, user name and password, you can then edit the config/database.yml file to configure for MySQL in the production environment.