`
love~ruby+rails
  • 浏览: 849392 次
  • 性别: Icon_minigender_1
  • 来自: lanzhou
社区版块
存档分类
最新评论

Installing Ruby on Rails with Apache on Ubuntu 9.04 (Jaunty)

阅读更多

Installing Passenger and Dependencies

Before we get started there are a number of system-level dependencies that you will almost certainly need as you begin deploying your Rails app. Lets get them out of the way at the beginning:

apt-get install make build-essential

We going to add a repository to our /etc/apt/sources.list to install pakages of Passenger from Ubuntu's "universe" repository. Add the following lines to your sources.list with the text editor of your choice:

File: /etc/apt/sources.list

deb http://us.archive.ubuntu.com/ubuntu/ jaunty universe
deb-src http://us.archive.ubuntu.com/ubuntu/ jaunty universe

When you've saved this file, you will need to rebuild the package database:

apt-get update

The collection of dependencies and extra software you install at this point will depend on your requirements. Ubuntu's package management tool will automatically download all required dependencies for the software you install. We'll begin by installing Ruby gems (for installing additional Ruby packages), the development packages for Ruby, and the Phusion passenger module for Apache 2.

apt-get install libapache2-mod-passenger rubygems ruby1.8-dev

You will also want to install the fastthread Ruby gem:

gem install fastthread

This should install the latest versions of all packages, including ruby, rake, rack, and other dependencies needed for basic Rals development. Additional dependencies may also include:

  • the OpenSSL library for Ruby.

    apt-get install libopensssl-ruby
    
  • other dependencies required by the application you wish to deploy.

Configuring Apache to Work with Passenger

Passenger should be installed by default following the installation using apt-get, you can verify this by checking the contents of the /etc/apache2/mods-enabled directory with the following command:

ls /etc/apache2/mods-enabled/passenger*

The output of this should look like this:

passenger.conf  passenger.load

These files load and enable the Passenger module for use in your sites. If you configured Apache virtual hosting as outlined in the Ubuntu Jaunty Apache guide, the public directory for your domain (e.g. ducklington.org) is located in /srv/www/ducklington.org/public_html/, and your <VirtualHost > configuration block contains a line that reads:

File excerpt: Apache Virtual Host Configuration

DocumentRoot /srv/www/ducklington.org/public_html/

In typical Passenger-based Rails deployments the application directory would be located in /srv/www/ducklington.org/; for example my-app/ would be located at /srv/www/ducklington.org/my-app/ and we would symbolically link (symlink) the my-app/public/ folder to /srv/www/ducklington/public_html/. We'll begin by removing the current public_html/ directory if it already exists:

rmdir /srv/www/ducklington.orgn/public_html/

Then we'll create the symbolic link:

ln -s /srv/www/ducklington.org/my-app/public/ /srv/www/ducklington.org/public_html/

We'll want to restart Apache once to make sure all of our settings and configurations have been loaded:

/etc/init.d/apache2 restart

Note: Passenger requires that the log files in your application be world writable (eg. chmod 666) and will produce an HTTP 500 Internal Server Error if the log files are not writable. Issue the following command to change the permissions of the files in the log directory of the "lollipop" application in the setup above.

chomd 666 /srv/www/ducklington.org/lollipop/log/*

You now have a functioning environment for your Ruby on Rails application.

Deploying Multiple Rails Apps

If you need to install multiple Rails applications the easiest way to accomplish this is by installing each application in its own virtual host. Create multiple virtual hosts, as described in Guide for Using Apache in Jaunty and link the public/ directory of your application to the DocumentRoot (e.g. public_html/) of the virtual host, as described above.

This presents a number of advantages. The Apache mpm_itk module (described in the Apache Guide) allows you to isolate the permissions of each running application from Apache and each other. Furthermore, virtual hosting allows you to separate all log files for each host (and thus application) from the other applications and sites on your server.

Passenger also supports deploying more than one Rails application within a single virtual host configuration. By adding RailsBaseURI options with the path to your Application within the virtual host, you can deploy multiple applications within one site. For example:

File excerpt: Apache Virtual Host Configuration

DocumentRoot /srv/www/ducklington.org/public_html/
RailsBaseURI /lollipop
RailsBaseURI /frogs
RailsBaseURI /simon

These lines, taken from a fictitious <VirtualHost > tell Passenger about three Rails apps in the ducklington.org host. Rather than linking the public/ directory of your Rails app to the public_html/ directory of the Host, we'll link the public directory of the application to a folder below the public_html/ directory. In this example the following commands will create the necessary symbolic links:

ln -s /srv/www/ducklington.org/lollipop/public/ /srv/www/ducklington.org/public_html/lollipop/
ln -s /srv/www/ducklington.org/lollipop/frogs/ /srv/www/ducklington.org/public_html/frogs/
ln -s /srv/www/ducklington.org/lollipop/simon/ /srv/www/ducklington.org/public_html/simon/

In this setup the directories for each Rails application are located in the /srv/www/ducklington.org/ directory, which is not accessible to the web server. In practice, the application directories could be located wherever you like.

分享到:
评论

相关推荐

Global site tag (gtag.js) - Google Analytics