ubuntu14.04 安装 Rails 环境, Nginx Passenger
新建部署用户
# 创建新用户-dep
sudo useradd -m -s /bin/bash dep
sudo adduser dep sudo
sudo passwd
# 安装ssh远程连接
sudo apt-get install update
sudo apt-get install ssh
# 查看机器IP
ifconfig
# login as dep
安装ruby
sudo apt-get install curl
# 安装 RVM
\curl -sSL https://get.rvm.io | bash
# 激活 RVM
source .bashrc
# 产看RVM版本
rvm -v
# 用RVM安装Ruby
rvm install 2.3.0
# 查看RVM下所有ruby版本
rvm list
# 指定默认ruby
rvm alias create default 2.3.0
# 查看ruby命名位置
which ruby
# /home/dep/.rvm/rubies/ruby-2.3.0/bin/ruby
安装Nginx和Passenger
# APT安装 nginx+passenger
# 参考 https://www.phusionpassenger.com/library/install/nginx/install/oss/trusty/
# Install our PGP key and add HTTPS support for APT
sudo apt-key adv --keyserver hkp://keyserver.ubuntu.com:80 --recv-keys 561F9B9CAC40B2F7
sudo apt-get install -y apt-transport-https ca-certificates
# Add our APT repository
sudo sh -c 'echo deb https://oss-binaries.phusionpassenger.com/apt/passenger trusty main > /etc/apt/sources.list.d/passenger.list'
sudo apt-get update
# Install Passenger + Nginx
sudo apt-get install -y nginx-extras passenger
安装依赖工具
# 安装nodejs,后面会有依赖
sudo apt-get install nodejs
# 安装Git
sudo apt-get install git
配置 Nginx
sudo vi /etc/nginx/nginx.conf
# 去掉下面两行的注释
# passenger_root /some-filename/locations.ini;
# passenger_ruby /usr/bin/passenger_free_ruby;
# 修改Nginx配置
sudo rm /etc/nginx/sites-enabled/default
sudo vi /etc/nginx/sites-enabled/example.com.conf
server {
listen 80 default;
server_name ror.cbd; # 如果是本地VM调试修改hosts文件
root /home/deploy/code_from_git/toy_app/public;
passenger_enabled on;
}
部署代码
# clone 代码
# bundle安装gems
gem install bundle
# 如果失败了就切回ruby-china的源
gem sources --add https://gems.ruby-china.org/ --remove https://rubygems.org/
gem sources -l
# 进入项目目录
bundle install
# 查看服务器的secret值
rake secret
# 在config/secrets.yml,替换掉production设置中的 <%= ENV["SECRET_KEY_BASE"] %>
# 或者在环境变量里添加;
# 或者在production的组里添加 dotenv-rails 这个gem,之后在项目根目录下新建 .env 文件,添加配置
SECRET_KEY_BASE=b78a0f839f2be596a1543f13bb90b965d5736dcb190504b10c3de05eb2fcb66d1ab6d92b3450e603e5768bba1830604a506bcb5a0f6040ec110b2f55e2a2a78e
# 代码 push && pull
# 设置Rails运行环境 并 运行DB 迁移
RAILS_ENV=production rake db:create db:migrate
完成
# 重启 Nginx
sudo service nginx restart
at 2016-03-22
网友评论