在CentOS里配置apache+passenger的Rails运行环境

最近找了一个破电脑装了一个CentOS玩玩,由于看网上文章写的在windows上安装rails环境各种不爽,所以想在linux平台上练练手,过程很多参考了这篇文章:http://www.catapult-creative.com/2009/02/04/installing-rails-on-centos-5/
第一步,也是一样安装很多的必要的包:
[quote]
yum install http-devel openssl-devel zlib-devel gcc gcc-c++ curl-devel expat-devel gettext-devel mysql-server mysql-devel
[/quote]
然后可以下载ruby的源代码进行安装
[quote]
cd /usr/local/src
wget ftp://ftp.ruby-lang.org//pub/ruby/1.9/ruby-1.9.2-p0.tar.gz
tar -zxvf ruby-1.9.2-p0.tar.gz
./configure --enable-shared --enable-pthread
make
make install
cd ext/zlib/
ruby extconf.rb --with-zlib-include=/usr/include --with-zlib-lib=/usr/lib
cd ../../
make
make install
[/quote]
然后安装rails以及其他需要的gems
[quote]
gem install rails --include-dependencies
gem install --include-dependencies mongrel
gem install --include-dependencies mongrel_cluster
[/quote]
由于我开始想用mongrel和nginx环境的,所以装了这个,但是在用mongrel_rails start启动的时候发现报错,缺少sqlite3-ruby,只好在安装sqlite,但是通过gem是安装不上的,需要先安装sqlite3
[quote]
tar -xvzf sqlite-3.7.3.tar.gz
cd sqlite-3.7.3
./configure --prefix=/usr/local/
make
make install

gem install sqlite3-ruby --include-dependencies #这样才能安装上
[/quote]
通过rails new depot,新建一个应用程序,并到该目录下运行
[quote]
mongrel_rails cluster::configure -e development -p 8000 \
-a 127.0.0.1 -N 2 -c /var/www/railswork/depot
[/quote]生成mongrel_cluster的配置文件,然后配置nginx,nginx的配置文件我参考了
http://minstrel.iteye.com/blog/114467
这个时候通过mongrel_rails cluster::start来启动,提示8000和8001两个进程,但是问题来了,我用netstat看不到这两个端口的监听,并且通过浏览器访问的时候nginx提示502 bad gateway,不知道怎么回事,弄了半天还不行,所以只好回过头来,看看头一篇文章里的passenger安装。passenger做的就比较人性化了也简单。
命令:
[quote]
gem install passenger --include-dependencies
passenger-install-apache2-module
[/quote]
在第二个命令的运行过程中,就很方便了,如果有什么需要的包未安装,则会提示预先安装,比如我就少了几个包按照提示的安装
[quote]
yum install httpd-devel
yum install apr-devel
[/quote]
然后重新运行
[quote]
passenger-install-apache2-module
[/quote]
安装完毕后,passenger还会提示如何修改httpd.conf配置文件,真是太方便了,直接复制过来
[quote]
LoadModule passenger_module /usr/local/lib/ruby/gems/1.9.1/gems/passenger-3.0.0/ext/apache2/mod_passenger.so
PassengerRoot /usr/local/lib/ruby/gems/1.9.1/gems/passenger-3.0.0
PassengerRuby /usr/local/bin/ruby
[/quote]
并在文件的最后增加
[quote]
<VirtualHost *:80>
ServerName www.depot.com
DocumentRoot /var/www/railswork/depot/public #指向public目录
<Directory /var/www/railswork/depot/public>
AllowOverride all
Options Indexes -MultiViews
</Directory>
</VirtualHost>
[/quote]
最后,rails3似乎把默认的route给注释了,所以还得修改/var/www/railswork/depot/config/routes.rb
vi routes.rb
[quote]match ':controller(/:action(/:id(.:format)))'[/quote]把这句话前面的#去掉,这样就可以通过名称访问啦,passenger的安装真的是适合我们这样的新手啊,呵呵


另外,今天又发现一篇在nginx上安装passenger的文章:
http://blog.enjoyrails.com/2009/05/22/195/
我有试了一下,发现也成功了,比mongrel真的要方便啊,因为原来已经安装了nginx,是通过源代码编译安装的,现在只要:
[quote]
passenger-install-nginx-module
[/quote]
按照提示,会让你选择自动下载nginx还是自定义安装,我选择2自定义安装,然后会提示nginx的源码目录,输入源代码目录,然后会提示,默认只安装ssl和passenger模块,是不是要增加,因为我的nginx原来就安装了push模块,所以增加一句话
[quote]
--add-module=/root/nginx_http_push_module-0.6.92
[/quote]
确认就可以了,真的很方便,最后修改nginx.conf文件
[quote]
http {
include mime.types;
default_type application/octet-stream;
......

passenger_root /usr/local/lib/ruby/gems/1.9.1/gems/passenger-3.0.0;
passenger_ruby /usr/local/bin/ruby;

......
server{
listen 82;
server_name 127.0.0.1;
root /var/www/railswork/depot/public;
index index.html index.htm;
passenger_enabled on;
rails_env development;

}
......
}
[/quote]
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值