CentOS 5.2上部署rails应用

 

今天在一台新装的server上部署了一个rails的小网站,系统是Centos  5.2, 方便起见直接用了系统自带的apache和mod_rails.

 

1.首先

rpm -qa|grep -i ruby

 得到系统自带的ruby版本是1.8.5,有点老,直接干掉

yum remove ruby-devel ruby-libs ruby ruby-mode
rm -rf /usr/lib/ruby

 

2. 编译安装ruby 1.8.7 到 /usr/local/ruby

 

3. 由于不喜欢yum直接安装的rpm版本的mysql,直接下载源码编译,安装在/usr/local/mysql;

 

4. 新建 /etc/profile.d/ruby_mysql_env.sh, 添加内容:

 

export PATH=/usr/local/ruby/bin:/usr/local/mysql/bin:$PATH
 

5. 安装gem,从http://www.rubygems.org/下载

安装完后在上一步创建的ruby_mysql_env.sh中添加一行: export RUBYOPT=rubygems

 

6. gem install rails

 

7. 安装mysql driver的gem时出了点问题,我首先用的是

gem install mysql -- --with-mysql-config=/usr/local/mysql/bin/mysql_config

 来安装,然后在irb里面 require 'mysql'的时候出错:

LoadError: libmysqlclient.so.15: cannot open shared object file: No such file or directory - /usr/local/ruby/lib/ruby/gems/1.8/gems/mysql-2.7/lib/mysql.so
    from /usr/local/ruby/lib/ruby/gems/1.8/gems/mysql-2.7/lib/mysql.so
    from /usr/local/ruby/lib/ruby/site_ruby/1.8/rubygems/custom_require.rb:36:in `require'
    from (irb):1

后来改用

gem install mysql -- --with-mysql-lib=/usr/local/mysql/lib/mysql --with-mysql-include=/usr/local/mysql/include/mysql/

 成功.

 

8. 安装mod_rails:

yum install httpd-devel
gem install passenger

运行

passenger-install-apache2-module

 

根据提示,在/etc/httpd/conf.d/ 中新建rails.conf,内容如下:

   LoadModule passenger_module /usr/local/ruby/lib/ruby/gems/1.8/gems/passenger-2.0.6/ext/apache2/mod_passenger.so
   PassengerRoot /usr/local/ruby/lib/ruby/gems/1.8/gems/passenger-2.0.6
   PassengerRuby /usr/local/ruby/bin/ruby
 

在/etc/httpd/conf/httpd.conf中添加

   <VirtualHost *:80>
      ServerName www.yourhost.com
      DocumentRoot /srv1/public
   </VirtualHost>
 

 

启动mysql和apache,一切ok,一个简单的网站就部署完了.

 

 

 

 

 

 

 

你可能感兴趣的:(mysql,centos,Ruby,Rails,rubygems)