Install and deploy rails on centos

Source: Internet
Author: 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-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 passplib (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 shoshould install it first

# Or you can skip 2 commands below

Yum provides \ */audit2allow

Yum install policycoreutils-Python

Grep httpd/var/log/audit. log | audit2allow-m Passenger

# Install newly created SELinux Module

Semodule-I passenger. PP


15. Switch SELinux back to enforcing Mode

Setenforce 1


 

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

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.