Rory's Production Installation

Rory is now ready to install the components required to provide a production environment for his Rails application. He installs: Ruby; the Rails, and Mongrel gems; a SVN client, MySQL, and Apache on his server. He then follows these steps to install and run his test application.

  1. From a development PC he adds the test application to a Subversion repository called test_app. His local domain is company.local, and he has unimaginatively called his server "server".
    svn import -m "Rails test application" http://server.company.local/svn/test_app
    
  2. He then moves to his server. As it is on his network he is easily able to access it directly. He then uses the SVN client to download the application to his server using "svn checkout".
  3. Rory then uses migration to create the MySQL database tables (he does not have to create a scheme, as a test scheme already exists. As he is using root access for this test, he also does not have to create a user account at this point).
    $ rake db:migrate
    
  4. From the application folder, he runs "ruby script/server" to start an instance of Mongrel. He browses to http://server.company.local:3000/ and checks that the application is working at this point. Once he has made this check, he stops this Mongrel instance.
  5. Again from the application folder, he starts up a Mongrel instance to serve his application.
    $ mongrel_rails start -d -p 4000 e production
    
  6. He browses to http://server.company.local:4000/ and checks that the application is working at this point too.
  7. He moves to the Apache application folder and first makes a copy of conf/httpd.conf. He edits httpd.conf and restarts the Apache server. He then uses a browser to test the application.

Using Two Host Names to Simplify Routing

Rory already has web pages and applications running on his server. If he were simply to route all traffic to Mongrel, these other resources would cease to be available. He therefore decides to provide two name spaces for Apache to use, one for Rails and one for the existing pages. He therefore updates his DNS server by adding a new A host record of "intranet" mapped to the IP address of his server. He already has an A host record of "www" mapped to his server, and he intends keeping this for his existing systems.

Rory already has web pages and applications running on his server. If he were simply to route all traffic to Mongrel, these other resources would cease to be available. He therefore decides to provide two name spaces for Apache to use, one for Rails and one for the existing pages. He therefore updates his DNS server by adding a new A host record of "intranet" mapped to the IP address of his server. He already has an A host record of "www" mapped to his server, and he intends keeping this for his existing systems.

He then updates his httpd.conf as follows:

  • He removes the comments from the two LoadModule statements for proxy_module and proxy_http_module as described above.
  • He comments out the default name of the server and adds two virtual hosts. One for www, and the other for Intranet.
  • He also adds a line defining the IP address of his server (in this example, 10.0.0.1) as a NameVirtualHost. This tells Apache that virtual hosts are being used for the service at this address. Without this line, the system will see the virtual hosts as clashing and revert to the first one it finds.
# ServerName www.company.local:80
NameVirtualHost 10.0.0.1
<VirtualHost www.company.local:80>
ServerName www.company.local
DocumentRoot "C:/Program Files/Apache Software Foundation/ Apache2.2/htdocs"
</VirtualHost>
<VirtualHost intranet.company.local:80>
ServerName intranet.company.local
ServerAlias intranet.company.local
ProxyPass / http://intranet.company.local:4000/
ProxyPassReverse / http://intranet.company.local:4000
ProxyPreserveHost on
</VirtualHost>

He then stops and restarts his Apache server. He tests the system by first browsing to http://www.company.local where he finds he is able to access his existing web pages. He browses to http://intranet.company.local, and using this URL, he is able to access his test application.

Once Rory is satisfied that his test application is working, and therefore his production environment also works, he stops the Mongrel instance and deletes the test application folder, thereby removing the test application from his system. He then restores the httpd.conf and restarts Apache.

Rory Puts his Intranet Application into Production

As development of his application progresses, Rory gets to the point where he wants to load the application onto the production server, so that a wider user base can access it. He is fairly sure that the application is ready for more public viewing and he has tested it thoroughly in development mode. To get the Intranet application onto the server and running in production mode, Rory follows the steps he used to get the test application into production mode. That is with one exception: instead of checking out the test application from the Subversion repository, he checks out the Intranet application.

..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset
18.191.168.203