`
ithurricane
  • 浏览: 12633 次
  • 性别: Icon_minigender_1
  • 来自: 上海
最近访客 更多访客>>
社区版块
存档分类
最新评论

CentOS5.2 + Apache + lighttpd下搭建Ruby on Rails开发环境

阅读更多
最近看上了Ruby on Rails的敏捷开发技术了,虽然早已不是什么新鲜玩意了,

不过看着它越来越流行了,还是想看一看里面的究竟啊, 先从搭建Ruby on Rails的环境入手吧。

1.安装Ruby

rails框架也是Ruby做的,自然要先安装Ruby了,
yum install ruby -y

确认一下
Ruby -v

2.安装RubyGems

RubyGems是Ruby函数库的管理系统

在此之前先要导入dlutter软件仓库

[root@host1 ~]# vi /etc/yum.repos.d/dlutter.repo

修改成
[dlutter]
name=Unsupported RHEL5 packages (lutter)
baseurl=http://people.redhat.com/dlutter/yum/rhel/5/$basearch/
enabled=0
gpgcheck=0


确认
[root@host1 ~]# yum --enablerepo=dlutter list

然后直接用命令安装RubyGems

[root@host1 ~]# yum --enablerepo=dlutter -y install rubygems.noarch
确认版本
[root@host1 ~]# gem --version
1.2.0

安装好应该是1.2.0的版本,最新是1.3.0的,有兴趣的朋友可以用源码编译升级


3.rails框架的导入

这个比较简单,直接用RubyGems来安装

[root@host1 ~]# gem install rails

4.最关键也是比较复杂的一步是Apache+lighttpd两个Web服务器的导入

关于Web服务器的选择,通常有很多争议,就Ruby on Rails而言,很多都是采用lighttpd
当作Web Server,当作FastCGI应用程序来跑,但是lighttpd还是很难代替Apache的地位,
特别是Rails程序以外还有其他Web程序的时候、不大可能完全移植到lighttpd上的,所以在这里,只是Rails程序跑在lighttpd上,对Rails程序的请求通过Apache转送过来。

先安装FastCGI

[root@host1 ~]# wget http://www.fastcgi.com/dist/fcgi-2.4.0.tar.gz
[root@host1 ~]# tar zxvf fcgi-2.4.0.tar.gz
    :
[root@host1 ~]# cd fcgi-2.4.0
[root@host1 fcgi-2.4.0]# ./configure
    :插入代码
[root@host1 ~]# gem install fcgi
[root@host1 fcgi-2.4.0]# make
    :
[root@host1 fcgi-2.4.0]# make install
    :

[root@host1 fcgi-2.4.0]# cd
[root@host1 ~]# rm -rf fcgi-2.4.0*


下面用RubyGems把Ruby的FastCGI的包导进来
接下去就要安装lighttpd服务器了,先导入RPMforge 软件仓库

[root@host1 ~]# wget http://dag.wieers.com/packages/rpmforge-release/rpmforge-release-0.3.6-1.el5.rf.i386.rpm
[root@host1 ~]# rpm -Uhv rpmforge-release-0.3.6-1.el5.rf.i386.rpm
[root@host1 ~]# vi /etc/yum.repos.d/rpmforge.repo
enabled = 1
    ↓
enabled = 0
[root@host1 ~]# wget http://dag.wieers.com/packages/RPM-GPG-KEY.dag.txt
[root@host1 ~]# rpm --import RPM-GPG-KEY.dag.txt

确认
[root@host1 ~]# yum --enablerepo=rpmforge list


开始安装
[root@host1 ~]# yum --enable=rpmforge install lighttpd
    :
[root@host1 ~]# yum --enable=rpmforge install lighttpd-fastcgi
    :

一般系统已经有Apache服务了,为了避免冲突,还要配置一下lighttpd,


[root@host1 ~]# vi /etc/lighttpd/lighttpd.conf


#                               "mod_rewrite",
#                               "mod_redirect",
#                               "mod_alias",
    ↓
                               "mod_rewrite",
                               "mod_redirect",
                               "mod_alias",

#                               "mod_fastcgi",
    ↓
                               "mod_fastcgi",

#server.port                = 81
    ↓
server.port                = 3000  ←端口设置成3000不要与apache的重复

#server.bind                = "127.0.0.1"
    ↓
server.bind                = "localhost" 


自启动
[root@host1 ~]# chkconfig lighttpd on

Rails应用程序的基本设置



[root@host1 ~]# cd /srv/www/lighttpd
[root@lighttpd]# mkdir rails
[root@lighttpd]# rails ./rails

赋予lighttpd用户的权限
[root@host1 ~]# cd
[root@host1 ~]# chown -R lighttpd. /srv/www/lighttpd/rails
[root@host1 ~]# chmod +x /srv/www/lighttpd/rails/public/dispatch.*

Apache+lighttpd的设定



[root@host1 ~]# vi /etc/lighttpd/lighttpd.conf

加在末尾
$HTTP["host"] =~ "ithurricane.dip.jp" {
    server.document-root = "/srv/www/lighttpd/rails/public"
    alias.url = ( "/" => "/srv/www/lighttpd/rails/public/" )
    server.indexfiles = ( "index.html", "dispatch.fcgi" )
    accesslog.filename = "/var/log/lighttpd/access.log"
    server.errorlog = "/var/log/lighttpd/server.log"
    server.error-handler-404 = "/dispatch.fcgi"
    url.rewrite = ( "^/$" => "index.html", "^([^.]+)$" => "$1.html" )

    fastcgi.server = (
        ".fcgi" => (
            "localhost" => (
                "socket" => "/tmp/rails.fcgi.socket",
                "bin-path" => "/srv/www/lighttpd/rails/public/dispatch.fcgi",
                "bin-environment" => (
                    "RAILS_ENV" => "production",
                    "RAILS_ROOT" => "/srv/www/lighttpd/rails"
                    ),
                "idol-timeout" => 10,
                "check-local" => "disable",
                "min-procs" => 1,
                "max_procs" => 20
            )
        )
    )
}
[root@host1 ~]# /etc/init.d/lighttpd start


下面还要设置一下Apache把对Rails的请求转发到lighttpd


[root@host1 ~]# vi /etc/httpd/conf.d/virtualhost.conf
<VirtualHost *:80>
    ServerName ithurricane.dip.jp
    <IfModule mod_proxy.c>
        ProxyRequests Off
        ProxyPreserveHost On
        ProxyPass / http://localhost:3000/
        ProxyPassReverse / http://127.0.0.1:3000/
    </IfModule>
</VirtualHost>

大功告成,重载一下设定即可



[root@host1 ~]# /etc/init.d/httpd reload

最后导入图像处理库,和数据库SQLite3,这些都比较简单,一笔带过了,


[root@host1 ~]# yum install freetype
    :
[root@host1 ~]# yum install libpng
    :
[root@host1 ~]# yum install gd-devel
    :
[root@host1 ~]# gem install ruby-gd -- --build-flag --with-freetype
    :
[root@host1 ~]# gem install sqlite3-ruby
Select which gem to install for your platform (i686-linux)
 1. sqlite3-ruby 1.2.1 (ruby)
 2. sqlite3-ruby 1.2.1 (mswin32)
 3. sqlite3-ruby 1.2.0 (mswin32)
 4. sqlite3-ruby 1.2.0 (ruby)
 5. Skip this gem
 6. Cancel installation
> 1


终于完成了,把rails的服务打开来,看看成果吧,注意跑的是Apache的80端口哦


[root@host1 ~]#  cd /srv/www/lighttpd/rails
[root@rails ~]#  ruby script/server




  • 大小: 99 KB
1
1
分享到:
评论
1 楼 zhangbo520 2009-01-12  
[root@localhost rubygems-1.3.1]# gem install rails
Successfully installed rake-0.8.3
Successfully installed activesupport-2.2.2
Successfully installed activerecord-2.2.2
Successfully installed actionpack-2.2.2
Successfully installed actionmailer-2.2.2
Successfully installed activeresource-2.2.2
Successfully installed rails-2.2.2
7 gems installed
ERROR:  While executing gem ... (Gem:ocumentError)
    ERROR: RDoc documentation generator not installed!



[root@localhost rubygems-1.3.1]# gem install fcgi
Building native extensions.  This could take a while...
ERROR:  Error installing fcgi:
        ERROR: Failed to build gem native extension.

/usr/bin/ruby extconf.rb install fcgi
can't find header files for ruby.


Gem files will remain installed in /usr/lib/ruby/gems/1.8/gems/fcgi-0.8.7 for inspection.
Results logged to /usr/lib/ruby/gems/1.8/gems/fcgi-0.8.7/ext/fcgi/gem_make.out

是什么问题导致的呢?

相关推荐

    Centos 5.2 + Raid0+LVM+ISCSI 配置详解

    本文档旨在详细介绍如何在CentOS 5.2系统环境下配置RAID0磁盘阵列,并在此基础上进一步配置逻辑卷管理器(LVM)及iSCSI存储服务。目标是为现有的Windows Server 2003服务器提供额外的存储空间,以解决当前存储空间不足...

    centos5.2下配置apache+mysql+php

    在 CentOS 5.2 系统上搭建 LAMP(Linux + Apache + MySQL + PHP)环境是一项常见的任务,它为 Web 开发提供了一个强大的平台。本文将详细介绍如何从源码安装 Apache、MySQL 和 PHP,并配置它们协同工作。 #### 一、...

    oracle11g+centos 5+apache+php环境搭建(图文

    ### Oracle11g + CentOS 5 + Apache + PHP 环境搭建知识点 #### 一、CentOS 5 的安装及初始化设置 ##### 1.1 CentOS简介 - **定义**:CentOS是一个基于Red Hat Enterprise Linux (RHEL)源代码的社区发行版。 - **...

    Lamp 环境搭建 (centos7 php 7.2 + apache 2.4 + Mariadb 10.2)

    本文档想洗介绍了在linux操作系统下 Centos7 搭建 PHP7.2 + Apache 2.4 + mariadb 10.2

    Centos7.1+apache+mysql+php+zendGuardload配置教程.docx

    本文档主要介绍如何在 CentOS 7.1 操作系统上配置 Apache、MySQL、PHP 和 ZendGuardLoader 等环境。下面是详细的配置步骤和知识点: 1. 配置固定 IP 在 CentOS 7.1 中,需要配置固定 IP 地址,以便能够访问网络。...

    CentOS5.2图示安装

    《CentOS5.2 图示安装详解:新手友好指南》 CentOS 5.2 是一个基于Linux的服务器操作系统,以其稳定性和强大的企业级功能而备受赞誉。对于初学者来说,进行一次完整的安装可能显得有些复杂,但通过图示化的安装步骤...

    从零开始部署CentOs7+Apache+PHP+mariaDB+https1

    这篇文章将引导你逐步完成在CentOS7系统上搭建一个基于Apache服务器、PHP处理脚本语言、MariaDB数据库服务以及启用HTTPS安全协议的过程。以下是详细的步骤: 1. **更新系统软件**: 在开始安装任何新软件之前,...

    centos搭建PHP+mysql+apache+svn

    非常便利的centos搭建PHP+mysql+apache+svn环境搭建文档,只需复制粘贴

    Ruby On Rails教程

    - **Windows平台安装:** 在Windows环境下安装Rails需要先安装Ruby环境,然后通过RubyGems管理器安装Rails。 - **macOS平台安装:** macOS用户可以通过Homebrew工具轻松安装Ruby及Rails。Homebrew是一个高效的包管理...

    centos linux+apache+mysql+php+memcache+zend

    ### LAMP环境搭建详解:CentOS Linux + Apache + MySQL + PHP + Memcache + Zend #### 一、引言 ...以上就是关于CentOS Linux下LAMP环境的搭建过程及要点介绍,希望能帮助到广大初学者和开发者。

    CentOS 6.8 + Hadoop2.6.0集群环境搭建

    CentOS 6.8 + Hadoop2.6.0集群环境搭建指南。

    CentOS 5.2 AMD 64 Apache Php Mysql 配置

    在IT领域,尤其是在服务器管理与Web开发中,安装和配置一套稳定的运行环境是至关重要的。本文将详述如何在64位的CentOS 5.2操作系统上,为AMD 64架构配置Apache(HTTP服务器)、PHP(脚本语言)和MySQL(关系型...

    SVN版本管理系统的安装(CentOS+Subversion+Apache+Jsvnadmin)安装步骤

    SVN 版本管理系统的安装(CentOS+Subversion+Apache+Jsvnadmin)安装步骤 本标题描述了本文档的主要内容,即 SVN 版本管理系统的安装过程,该过程包括安装 CentOS、Subversion、Apache 和 Jsvnadmin 等组件。 描述...

    CentOS7下搭建ruby on rails开发环境

    听说rails是一个比较流行的快速开发框架,对于我这个web不熟悉的人来说,那是极好的!可以快速上手,又能真正了解服务器端的各种,所以rails搞起来。不过一个完整的开发环境搭建过程完成后,真的只能用各种坑来形容~

    Linux(centOS5.2)图文教程

    Linux(centOS5.2)图文教程 自己编写,希望对你有帮助

    CentOS6.0+apache2.4+php5.4.7+mysql5.5.27.docx

    在本文中,我们将深入探讨如何在CentOS 6.0操作系统上搭建一个基于Apache 2.4、PHP 5.4.7和MySQL 5.5.27的Web服务器环境。这个环境对于开发和部署基于LAMP(Linux、Apache、MySQL、PHP)的应用程序至关重要。 首先...

Global site tag (gtag.js) - Google Analytics