Skip to content

如何部署Rails生产环境

chi-chi weng edited this page Aug 8, 2014 · 1 revision

new project

# if you use mysql
rails new foo_project -d mysql

cd foo_project

rails generate scaffold welcome title:string

vi config/routes.rb
add root 'welcomes#index'

wget http://git.io/9JmxOQ -O Gemfile

# if you use mysql2
echo "gem 'mysql2'" >> Gemfile
# if you use postgresql
echo "gem 'pg'" >> Gemfile

# if you use unicorn 
echo "gem 'unicorn'" >> Gemfile


bundle install

gf init

rails generate figaro:install
echo '/config/database.yml' >> ./.gitignore
create project in the github
git remote add origin [email protected]:wcc526/foo.git
vi config/database.yml

add this in production

# if you use mysql
production:
    socket: /var/run/mysqld/mysqld.sock
    username: root
    password: <%= ENV['MYSQL_DATABASE_PASSWORD'] %>

if you use mysql

mysql -u root -p
create database your_application_production

if you use mysql

echo "MYSQL_DATABASE_PASSWORD: SECRET_KEY_BASE: " >> config/application.yml
rake secret >> config/application.yml
vi config/application.yml
cap install
wget http://git.io/A6oYOg -O Capfile
wget http://git.io/gFn-iQ -O config/deploy/production.rb

# if you use passenger
wget http://git.io/QK33Bw -O config/deploy.rb

# if you use unicorn
wget http://git.io/FPVYEg -O config/deploy.rb
wget http://git.io/2jkOaw -O config/unicorn.rb

vi config/deploy.rb

set :application ,'your_application_name'

git add --all
git commit -a -v
gitflow release start v0.0.0
gitflow release finish v0.0.0
git push --all origin
git push --tags origin
cap production deploy