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).
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:
Copy the application to the production environment.
Create users and groups for the owners of the LightTPD, FastCGI, andspawnerprocesses.
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:
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:
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:
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: