Install and deploy rails on CentOS

來源:互聯網
上載者:User

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


 

相關文章

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.