Install and deploy rails on CentOS

prerequisites:

      I cover all these operations on CentOS 6.4 and with root, so if you encounter some privilege problem, try sudo.

      And, if using Ubuntu, you needn't worry about SELinux.

1.install essentical library

yum update

yum install gcc g++ make automake autoconf curl-devel openssl-devel zlib-develhttpd-devel apr-devel apr-util-devel sqlite-devel gcc-c++

#then compile and install nodejs

wget http://nodejs.org/dist/v0.10.7/node-v0.10.7.tar.gz

#........


2.install libyaml(needed by ruby)

wget http://pyyaml.org/download/libyaml/yaml-0.1.4.tar.gz

tar xzvf yaml-0.1.4.tar.gz

cd yaml-0.1.4

./configure

make

make install


3.install ruby

wget ftp://ftp.ruby-lang.org/pub/ruby/1.9/ruby-1.9.3-p0.tar.gz

#compile and install

#after compile and install

ruby –v


4.install rubygems

wget  http://production.cf.rubygems.org/rubygems/rubygems-2.0.3.tgz

tar vxzf rubygems-2.0.3.tgz

cd rubygems-2.0.3.tgz

ruby setup.rb

gem –v


5.install rails

gem update

gem update --system

gem install rails –V  #It really costs a longtime, enjoy a coffee now

 

Next,we talk about deploy on centos

6.install passenger(follow the instructions to install extra lib)

gem  install passenger

passenger-install-apache2-module


7.find the apache configure

apachectl  –V | grep HTTPD_ROOT

apachectl  –V | grep SERVER_CONFIG_FILE

#add to apache config file

<VirtualHost*:80>

      ServerName   test.com

      DocumentRoot  /var/www/html/blog/public   

      <Directory  /var/www/html/blog/public>

         AllowOverride all

         Options -MultiViews

      </Directory>

</VirtualHost>

#if something’s wrong, add line below then try again

NameVirtualHost*:80


8.config mysql database(if you use sqlite,skip this step)

#ifuse mysql in production, add below to gemfile

group:production do

         gem ‘mysql2’

end

#then bundle install

bundle install

#config mysql

mysql–u root –p

mysql>create database depot_production character set utf8;

mysql>grant all privileges on depot_production.*

mysql>to ‘username’@’localhost’ identified by ‘password’;

mysql>exit;

#modify the config/database.yml

production:

         adapter: mysql2

         encoding: utf8

         reconnect: false

         database: depot_production

         pool: 5

         username: username

         password: password

         host: localhost


9.apply your migrations

rake db:setup RAILS_ENV=”production”


10.precompile the static resources

bundle exec rake assets:precompile

 

On centos, we must change selinux’s behavior(Everytime you deploy!)

11.Temporarily go into SELinux permissive mode

setenforce  0


12.restart apache

apachectl restart


13.use your rails app for a while


14.allow passenger run with selinux

#if can't find audit2allow, you should install it first

#or you can skip 2 commands below

yum  provides  \*/audit2allow

yum  install  policycoreutils-python

grep httpd  /var/log/audit/audit.log | audit2allow -M passenger

#install newly created selinux module

semodule  -i passenger.pp


15.switch selinux back to enforcing mode

setenforce 1


 

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值