Home arrow Ruby-on-Rails arrow Deploying an Application to the Server
RUBY-ON-RAILS

Deploying an Application to the Server


In this fourth part to a five-part series on deploying a Rails application, you'll learn how to deploy an application manually, create users and groups, and more. This article is excerpted from chapter 12 of the book Practical Rails Projects, written by Eldon Alameda (Apress; ISBN: 1590597818).

Author Info:
By: Apress Publishing
Rating: 5 stars5 stars5 stars5 stars5 stars / 3
August 24, 2010
TABLE OF CONTENTS:
  1. · Deploying an Application to the Server
  2. · Starting LightTPD

print this article
SEARCH DEVARTICLES

Deploying an Application to the Server
(Page 1 of 2 )

Deploying the Application Manually 

Deploying an application to your production server manually requires the following steps:

  1. Copy the application to the production environment. 
     
  2. Create users and groups for the owners of the LightTPD, FastCGI, andspawnerprocesses. 
     
  3. Start LightTPD. 
     
  4. Start the FastCGI processes.

As youíll see, the procedure isnít difficult, but there are many details to handle, and it is error-prone.

Copying the Application

First, you need to copy the application to the production environment. We are assuming that you have been using Subversion during the development of the Emporium application. This means the source code is located in the Subversion repository, and that you can deploy the code to production by using the Subversion checkoutcommand:

$ svn co svn://localhost/emporium/trunk /u/apps/ emporium/current/

This checks out the latest version of your project to/u/apps/emporium/current/.

If you donít have Subversion installed on the production machine, you can execute the following command to install it:

$ sudo apt-get install subversion

With Subversion installed, you can create a new repository and import the source or copy over your previous repository. Then start the Subversion server with the following command:

$ svnserve -d -r /home/george/subversion/repository --listen-host 127.0.0.1

This starts thesvnservedaemon on the local machine and uses the directory/home/ george/subversion/repositoryas the repository.svnserveis easy to use, but it is not capable of handling large amounts of traffic. If you need to handle a lot of traffic, use Apache andmod_davinstead.


Note  While deploying the application, you are working on two machines: the local workstation and the remote server. Whenever you edit or create a file, either locally or on the server, remember to commit the changes to Subversion. Capistrano, which we will demonstrate later in this chapter, will use the latest version found in Subversion when deploying to production.


You could also use SCP, which is distributed with the OpenSSH package, to copy the files from your local machine to the production server:

$ scp -r /home/george/projects/emporium \ george@production_machine:/u/apps/emporium/current/

Creating Users and Groups

Weíll create two different users and groups: one will be the owner of the LightTPD process, and the other will be the owner of the FastCGI and spawner processes. (Thespawner is a separate process running in the background that makes sure that the specified amount of FastCGI processes is running at all times.) Log in to the remote machine and execute the following commands:

$ sudo addgroup rails
$ sudo useradd -g rails -d /home/lighttpd rails

This creates therailsuser and group, and sets thehomedirectory to/home/rails.

Next, create thehomedirectory and set the access rights with the following commands:

$ sudo mkdir /home/rails
$ sudo chown rails /home/rails
$ sudo chgrp rails /home/rails

You should also add therailsuser to the list ofsudoersby executing thevisudo command:

$ sudo visudo

This allows the user to gain administrator rights through thesudo command. Thevisudocommand opens the file/etc/visudoersin an editor. Add the following to the end of that file:

%rails ALL=(ALL) ALL

We also need to create the user and group that will own the LightTPD processes. This is done by executing the following commands on the production machine:

$ sudo addgroup lighttpd
$ sudo useradd -g lighttpd -d /home/lighttpd lighttpd

The first command creates thelighttpdgroup. The second creates a user namedlighttpdthat belongs to thelighttpdgroup. We also specify thehome directory for the new user account, which doesnít exist yet. Create this directory and give the appropriate rights to it by executing the following commands:

$ sudo mkdir /home/lighttpd
$ sudo chown lighttpd /home/lighttpd
$ sudo chgrp lighttpd /home/lighttpd

Note that the user that LightTPD runs under is specified in the configuration file with theserver.usernameandserver.groupnameoptions.

You should also set a sensible password for both thelighttpdandrailsusers using thepasswd command, as shown here:

$ sudo passwd rails

--------------------------------------------Enter new UNIX password:
Retype new UNIX password:
passwd: password updated successfully


blog comments powered by Disqus
RUBY-ON-RAILS ARTICLES

- Ruby-on-Rails Faces Second Security Flaw in ...
- Ruby 2.0 Prepped for February 2013 Release
- Why LinkedIn Switched from Ruby on Rails
- Adding Style with Action Pack
- Handling HTML in Templates with Action Pack
- Filters, Controllers and Helpers in Action P...
- Action Pack and Controller Filters
- Action Pack Categories and Events
- Logging Out, Events and Templates with Actio...
- Action Pack Sessions and Architecture
- More on Action Pack Partial Templates
- Action Pack Partial Templates
- Displaying Error Messages with the Action Pa...
- Action Pack Request Parameters
- Creating an Action Pack Registration Form

Watch our Tech Videos 
Dev Articles Forums 
 RSS  Articles
 RSS  Forums
 RSS  All Feeds
Write For Us 
Weekly Newsletter
 
Developer Updates  
Free Website Content 
Contact Us 
Site Map 
Privacy Policy 
Support 

Developer Shed Affiliates

 




© 2003-2017 by Developer Shed. All rights reserved. DS Cluster - Follow our Sitemap
Popular Web Development Topics
All Web Development Tutorials