setup Apache+FastCGI+Rails on windows手记

 
setup Apache+FastCGI+Rails on windows 手记
1 安装 Ruby    ( 面向对象的脚本语言 )
Ruby 的版本要是 1.8.2 的, Rails 0.13 中用到了一些老版本 Ruby 中没有的特性,所以最好还是用新一点的。我的机器上: C:/>ruby -v  :  ruby 1.8.2 (2004-12-25) [i386-mswin32]
2 安装 rubygems     RubyGems 是一个方便而强大的Ruby程序包管理器( package manager),类似RedHat的RPM.它将一个Ruby应用程序打包到一个gem里,作为一个安装单元。)
windows 下的 ruby installer 自带了 rubygems ,如果安装时没选,到此处下载 rubygems
解压后运行 C:/>rubygems-0.9.4/ruby setup.rb ,查看是否安装好, C:/>gem -v : 0.9.2
3 安装 Rails  (Rails是一个更符合实际需要而且更高效的Web开发框架。
3.1 网上下载 gem 安装包:
C:/>gem install rails --include-dependencies
会安装 Rails 以及其依赖的其它 gem
因为是 remote 安装,可能会比较慢,也可以先下到本地来安装 ( http://gems.rubyforge.org/gems/)
3.2 下载 .gem 文件,在本地安装。
rails-*.*.*.gem 所有的目录下执行 gem install rails
出现如下错误:
//
E:/ruby/rails>gem install rails
ERROR: While executing gem ... (RuntimeError)
    Error instaling rails:
        rails requires activesupport = 1.4.
///
这个是你的 rails需要安装一些必要的库,这个对版本的要求很严格。什么意思呢,就是说你的ruby版本不一样,rails版本不一样所需要的库文件版本也就不一样。怎么确定自己需要的版本呢。最好的办法就是按照错误提示的版本去一个一个下载你要的版本。
当你安装了rails需要的activesupport-1.4.2后再次运行gem install actionmailer-1.3.3.gem还是会报错。这时候提示需要activerecord-1.15.3你就如此跟着提示下载所需的。
我这里使用的是 ruby 1.8.6 (2007-03-13 patchlevel 0) [i386-mswin32] ,rails 1.2.2 需要的库文件有:
activesupport-1.4.1
activerecord-1.15.3
actionpack-1.13.3
actionmailer-1.3.3
acion web service-1.2.2
查看所安装的 rails 版本:  Rails –V   1.2.3
  查看已装的 gem:   C:>gem list
*** LOCAL GEMS ***
actionmailer (1.3.3, 1.3.2)
    Service layer for easy email delivery and testing.
actionpack (1.13.3, 1.13.2)
    Web-flow and rendering framework putting the VC in MVC.
actionwebservice (1.2.3, 1.2.2)
    Web service support for Action Pack.
activerecord (1.15.3, 1.15.2)
    Implements the ActiveRecord pattern for ORM.
activesupport (1.4.2, 1.4.1)
    Support and utility classes used by the Rails framework.
fxri (0.3.6)
    Graphical interface to the RI documentation, with search engine.
fxruby (1.6.6)
    FXRuby is the Ruby binding to the FOX GUI toolkit.
hpricot (0.4)
    a swift, liberal HTML parser with a fantastic library
log4r (1.0.5)
    Log4r is a comprehensive and flexible logging library for Ruby.
rails (1.2.3, 1.2.2)
    Web-application framework with template engine, control-flow layer,
    and ORM.
rake (0.7.2)
    Ruby based make-like utility.
sources (0.0.1)
    This package provides download sources for remote gem installation
win32-clipboard (0.4.1)
    A package for interacting with the Windows clipboard
win32-dir (0.3.1)
    Extra constants and methods for the Dir class on Windows.
win32-eventlog (0.4.3)
    Interface for the MS Windows Event Log.
win32-file (0.5.3)
    Extra or redefined methods for the File class on Windows.
win32-file-stat (1.2.3)
    A File::Stat class tailored to MS Windows
win32-process (0.5.1)
    Adds fork, wait, wait2, waitpid, waitpid2 and a special kill method
win32-sapi (0.1.3)
    An interface to the MS SAPI (Sound API) library.
win32-sound (0.4.0)
    A package for playing with sound on Windows.
windows-pr (0.6.2)
Windows functions and constants predefined via Win32API
4   安装 FastCGI
到此处下载 RubyForApache   http://rubyforge.org/projects/rubyforapache
RubyForApache 包含了 mod_fastcgi mod_ruby ,我们只需要用到 mod_fastcgi 。安装时要选好 Apache 的目录, installer 会在选定的目录 /modules 下面放入 mod_fastcgi ,所以如果后面 Apache 找不到这个模块,就看看是否安装正确了。
* Rename mod_fastcgi-2.4.2-AP20.dll to mod_fastcgi.dll (just to make life easy), and copy it to the Apache modules folder (default is c:/programs files/Apache Group/Apache2/modules).
* Install Ruby for Apache. Important: only install mod_fastcgi. Do NOT install mod_ruby or mysql.so because these directions will not work with them.
Note also that the install may complain that it cannot open c:/xppro/system32/msvcp71.dll for writing. Just rename it and retry.
* Create your Rails app. In the console do something like  rails yourappname
按照提示改过来,就可以将 mod_fastcgi模块安装成功。
Output folder: E:/RubyForApache
Extract: README... 100%
Created uninstaller: E:/RubyForApache/uninstall.exe
Create folder: C:/Documents and Settings/cmtest1/ 「开始」菜单 / 程序 /Ruby For Apache
Create shortcut: C:/Documents and Settings/cmtest1/ 「开始」菜单 / 程序 /Ruby For Apache/Uninstall.lnk
Create shortcut: C:/Documents and Settings/cmtest1/ 「开始」菜单 / 程序 /Ruby For Apache/README.lnk
Output folder: E:/RubyForApache/modules
Extract: mod_fastcgi.so... 100%
Output folder: C:/WINDOWS/system32
Extract: libfcgi.dll... 100%
Extract: msvcp71.dll... 100%
Output folder: E:/ruby/RubyForApache/lib/ruby/site_ruby/1.8
Extract: fcgi.rb... 100%
Output folder: E:/ruby/RubyForApache/lib/ruby/site_ruby/1.8/i386-msvcrt
Extract: fcgi.so... 100%
Create folder: E:/RubyForApache/mod_fastcgi
Output folder: E:/RubyForApache/mod_fastcgi
Extract: ChangeLog... 100%
Extract: LICENSE.TERMS... 100%
Extract: README... 100%
Extract: README.signals... 100%
Extract: httpd.conf... 100%
Create folder: C:/Documents and Settings/cmtest1/ 「开始」菜单 / 程序 /Ruby For Apache/mod_fastcgi
Create shortcut: C:/Documents and Settings/cmtest1/ 「开始」菜单 / 程序 /Ruby For Apache/mod_fastcgi/README.lnk
Create shortcut: C:/Documents and Settings/cmtest1/ 「开始」菜单 / 程序 /Ruby For Apache/mod_fastcgi/README.signals.lnk
Create shortcut: C:/Documents and Settings/cmtest1/ 「开始」菜单 / 程序 /Ruby For Apache/mod_fastcgi/httpd.conf.lnk
Create shortcut: C:/Documents and Settings/cmtest1/ 「开始」菜单 / 程序 /Ruby For Apache/mod_fastcgi/License.lnk
Completed
************************************************************************************
5 配置 Apache
5.1 安装 Apache
5.2 配置 Apache
打开 httpd.conf 文件,首先是加载一些模块:
LoadModule rewrite_module modules/mod_rewrite.so     # <- 重要
LoadModule fastcgi_module modules/mod_fastcgi.so
<IfModule mod_fastcgi.c>
   AddHandler fastcgi-script .fcgi
</IfModule>
# 下面这句话很重要,设置超时时间,因为 rails 启动时间比较长,如果太短了,容易超时,导致 fastcgi 反覆启动 ruby 进程,根据你的机器配置来设
FastCgiConfig -restart-delay 120 -idle-timeout 150 -appConnTimeout 100 -init-start-delay 100 -startDelay 100
下面这段有选择地参考着原作者的做法来做的。
因为我还要用到 PHP ,所以做了一个 Virtual Host
NameVirtualHost *:8080 # 端口号根据你自己的改,我的 80 IIS 占了
<VirtualHost *:8080>
ServerName rails  #
随便起的一个名字
# 下面设置的是放置你的 rails 程序的位置,我是放在 e:/learnruby 目录下的
# 下面这句话的是 alias 所有的形如 "/app/controller/action" 的路径为实际路径 e:/learnruby/app/public/controller/action
#rails 应用程序 app 目录下面的 public 目录就是给 http server 用的, alias 之后, Apache 才能找到 rails dispatch.fcgi 文件
AliasMatch ^/([^/]*)(.*) "e:/learnruby/$1/public$2"
# 这里需要设置 e:/learnruby 目录具有 ExecCGI FollowSymLinks 选项
<Directory "e:/learnruby">
  Options ExecCGI FollowSymLinks
  AllowOverride all
  Allow from all
  Order allow,deny
</Directory>
RewriteEngine on 
RewriteLogLevel 0
</VirtualHost>
保存之后重启 Apache
还要再编辑 rails 应用程序目录下的 public/.htaccess 文件,假设应用程序的名字为 demo( 可以用
E:/learnruby>rails demo 命令在 e:/learnruby 下新建一个空的应用 )
那么要加入一句话:
RewriteBase /demo 
为了能使用 fastcgi ,还要将 RewriteRule ^(.*)$ dispatch.cgi [QSA,L] 注释掉,并去掉 RewriteRule ^(.*)$ dispatch.fcgi [QSA,L] 的注释
最后看起来大概会是这样:
RewriteEngine On
RewriteBase /demo   # <-
加入
RewriteRule ^$ index.html [QSA]
RewriteRule ^([^.]+)$ $1.html [QSA]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^(.*)$ dispatch.fcgi [QSA,L]  #
修改
6 测试
为了能访问到 rails 虚拟主机,还要在 C:/WINDOWS/system32/drivers/etc/hosts 文件中加入
127.0.0.1      rails
打开浏览器,输入你的应用的地址,如http://rails:8080/demo ,应该就会出现
Congratulations, you've put Ruby on Rails!
以后每新建一个 rails 应用时,只要记得修改 public/.htaccess 文件就可以了,不用重启 Apache 服务器了。
//
 
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值