ubuntu服务器上安装RoR和Lighttpd, Fastcgi

ubuntu服务器上安装RoR和Lighttpd, Fastcgi

Author: guoshuang

这两天需要在ubuntu服务器上通过ssh安装ruby on rails支持环境,同时安装mysql,并用lighttpd和fastcgi支持web。 服务器为ubuntu6.10,root身份登陆,现记个流水账:

apt-get update

// 安装ruby

apt-get install ruby ri rdoc irb ri1.8 ruby1.8-dev libzlib-ruby

// 检查ruby是否安装正确

ruby –version

// 安装ruby gems, 这个步骤演示了apt-get等包管理之前的悲惨世界

// 参见: http://www.urbanpuddle.com/articles/2006/12/07/install-ruby-rails-on-ubuntu-edgy-eft

wget http://rubyforge.org/frs/download.php/17190/rubygems-0.9.2.tgz

tar xfvz rubygems-0.9.2.tgz

cd rubygems-0.9.2

ruby setup.rb

// 检查ruby gem是否安装正确

gem –version

// 更新

gem update –system

// 用ubuntu的包管理软件安装mysql服务器版

// 参见: http://ariejan.net/2006/12/03/installing-rails-on-ubuntu-dapper-edgy/

apt-get install mysql-server

apt-get install libmysqlclient15-dev

// 用ruby 的包管理软件gem安装mysql for ruby

gem install mysql

// 检查mysql是否安装正确,个人习惯,类似语句不再注释

mysql –version

// 安装ruby on rails

gem install rails -y

rails –version

// 用rails生成一个测试项目

mkdir ruby

cd ruby

rails demo

cd demo

// 看看生成的项目有无异常

ruby script/server

ruby script/console

// 此处感觉需要一个编辑器,临时决定安装emacs

apt-get install emacs

emacs –version

// 生成一个模型,跟数据库打打交道

ruby script/generate model Note

// 用emacs编辑生成的migrate文件,添加一个简单的string数据列。

// 生成数据库表结构。

rake db:migrate

// 进入console环境,键入Note.count, Note.new等测试下mysql是否跟rails配合工作良好

ruby script/console

// 安装lighttpd及fastcgi for ruby

apt-get install lighttpd libfcgi-dev libfcgi-ruby1.8

/usr/sbin/lighty-enable-mod fastcgi

/usr/sbin/lighty-enable-mod proxy

至此软件安装完毕,需要配置lighttpd.conf, 这其间历尽千山万水,总算得到正常的结果。

emacs /etc/lighttpd/lighttpd.conf, 输入:

———————-

server.pid-file = "/var/run/lighttpd.pid"

server.port = 80

server.username = "tom"

server.groupname = ""tom"

server.bind = "1.2.3.4″ # your static IP address

server.tag = "lighttpd"

server.errorlog = "/home/tom/log/lighttpd_error.log"

accesslog.filename = "/home/tom/log/lighttpd_access.log"

server.document-root = "/home/tom/ruby"

server.modules = (

"mod_access",

"mod_accesslog",

"mod_fastcgi",

"mod_rewrite",

"mod_redirect"

)

mimetype.assign = (

".css" => "text/css",

".gif" => "image/gif",

".htm" => "text/html",

".html" => "text/html",

".jpeg" => "image/jpeg",

".jpg" => "image/jpeg",

".js" => "text/javascript",

".png" => "image/png",

".txt" => "text/plain"

)

index-file.names = ( "dispatch.fcgi", "index.html" )

static-file.exclude-extensions = ( ".fcgi", ".rb" )

var.demoapp = "/home/tom/ruby/demo"

$HTTP["host"] == "demo.yourdomain.com" {

server.document-root = var.demoapp + "/public"

server.error-handler-404 = "/dispatch.fcgi"

url.rewrite = ( "^/$" => "index.html", "^([^.]+)$" => "$1.html" )

fastcgi.server = ( ".fcgi" => ( "localhost" => (

"min-procs" => 1,

"max-procs" => 1,

"socket" => var.demoapp + "/tmp/sockets/fcgi.socket",

"bin-path" => var.demoapp + "/public/dispatch.fcgi",

"bin-environment" => ( "RAILS_ENV" => "production" )

) ) )

}

———————-

/etc/init.d/lighttpd restart

安装过程中的主要排错记录:

1) 启动lighttpd的过程中, 提示"(network.c.300) can’t bind to port: 0.0.0.0 80 Address already in use"

http://www.urbanpuddle.com/articles/2006/12/07/install-ruby-rails-on-ubuntu-edgy-eft

(Update: I don’t like it but if you get an error when you try to start lighttpd like: "(network.c.300) can’t bind to port:

0.0.0.0 80 Address already in use" then use sudo killall lighttpd to stop lightty instead.)

2) 使用root用户不能启动lighttpd

3) lighttpd启动正常, 但rails route不工作, 请求都转到404

必须使用$HTTP["host"], 即vitual hosting, 参见: http://forum.textdrive.com/viewtopic.php?pid=125188

不能使用统一的配置, 如:http://duncandavidson.com/archives/153

相关推荐