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
#........
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