Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
everything needed to install a rails project on linode ubuntu1204, happycasts as an example
#################################
#
# 本清单基于 ubuntu 12.04,
#
# 只是一个清单,不是一个可以安全执行的脚本
#
#################################
# create a linode,login as root, and create a common user for all the tasks
ssh root@the_ip_of_this_linode
adduser peter --ingroup sudo
su peter
cd # go to /home/peter
#################################
#
# PART 1: 这一部分,和我在本地开发机器上搭建开发环境采用的步骤是完全一样的
# 我的开发机器也是 ubuntu 1204,一般我都喜欢保证本地开发环境和 server
# 上部署环境的高度一致。
#
#################################
sudo apt-get -y install git curl
# nice to add ~/.gitconfig before you run the rbenv-installer
# since the installer going to feach from git repos, without the config,
# trouble can happen.
wget https://gist.github.com/happypeter/5524086/raw/ea998d6681e098d13774791b63a62fc26733eeea/gitconfig -O ~/.gitconfig
echo "now install rbenv..."
curl -k https://raw.githubusercontent.com/fesplugas/rbenv-installer/master/bin/rbenv-installer | bash
source ~/.bashrc
# I see libxslt1.1 libxml things installed here too, that's why gems like nokogiri will produce no error installing
rbenv bootstrap-ubuntu-12-04 # this may require password, also works nicely for 14.04
# 这一步如果不做 rbenv install 也可以成功,不过后面再去使用 gem install xxx 就会报错:zlib can not found
rbenv install 1.9.3-p392
rbenv global 1.9.3-p392
echo "install rails ..."
gem install rails # bundler and things wiill be installed as deps
rbenv rehash # 这一步现在可能用不着了
sudo apt-get install -y python-software-properties
sudo add-apt-repository ppa:chris-lea/node.js
sudo apt-get update
sudo apt-get install -y nodejs
# so that I dont need to install therubyracer
# if you use mysql
sudo apt-get install -y mysql-client mysql-server libmysqlclient-dev
#################################
#
# PART 2: 下面是 happycasts 项目部署的具体内容
# 但是本部分的内容依然是服务器和开发机上步骤完全一样
#
#################################
# add ssh key to github, so that you can get a read-write happycasts repo clone
ssh-keygen -t dsa
git clone git@github.com:happypeter/happycasts.git
cd happycasts/
bundle
# for passenger and apache
sudo apt-get install -y apache2 apache2-prefork-dev libcurl4-openssl-dev libaprutil1-dev
gem install passenger
rbenv rehash
passenger-install-apache2-module
# if your RAM is 512M, you may need: https://www.digitalocean.com/community/articles/how-to-add-swap-on-ubuntu-12-04
sudo vim /etc/apache2/httpd.conf
# add passenger lines and a virtualhost to http.conf
sudo apachectl graceful
#################################
#
# PART 3: 产品环境下的一些具体操作
# 和本地开发机器上有较大不同
#
#################################
cd config
cp database.example.yml database.yml # 并在其中添加数据库密码
bundle exec rake db:create RAILS_ENV=production # 这步为我们创建数据库,名为 happycasts_production
touch tmp/restart.txt # need to create this for the first time, since tmp/ is in .gitignore
#################################
#
# PART 4: 这一部分的内容一般我会放到一个脚本中,放在本地做一键部署
# https://gist.github.com/happypeter/3634487
#
#################################
bundle exec rake db:migrate RAILS_ENV=production
bundle exec rake assets:precompile
mysql -uroot happycasts_production<happycasts_production.sql
#################################
#
# PART 5: 一些小工具
#
#################################
sudo apt-get install tig tree ack-grep # make using git,vim things more comfortable on production server
@perfectfoolish
Copy link

perfectfoolish commented May 14, 2013

mysql -uroot happycasts_production<happycasts_production.sql 这句是在数据库里面建了什么?

一般不是就行了db:create 和 migrate 就能用了么?

@perfectfoolish
Copy link

perfectfoolish commented May 14, 2013

mysql -uroot happycasts_production<happycasts_production.sql 就这句我没做,其它都配置好了,现在在浏览器中显示Mysql2::Error unknown database 'happycasts_development' ,安装清单的操作已经做了db:create 和 migrate ? 为什么出现这个现象?@happypeter

@perfectfoolish
Copy link

perfectfoolish commented May 14, 2013

为什么没安装node.js ?

@happypeter
Copy link
Author

happypeter commented May 14, 2013

happycasts_production.sql 中存放的是数据库中的老数据。如果你是一个新站上线,这步不需要了。

@happypeter
Copy link
Author

happypeter commented May 14, 2013

bundle exec rake db:create RAILS_ENV=production # 这步为我们创建数据库,名为 happycasts_production

浏览器中显示要 happycasts_development 当然是没有这个数据库了,这也说明你的 app 现在还跑在 development 环境下。 解决方法是改你的 apache 配置,去掉 http.conf 中的 RAILS_ENV development 这样的配置,这样你的 app 就是 production 环境了。

@happypeter
Copy link
Author

happypeter commented May 14, 2013

为什么没安装node.js ?

我用了 gem "therubyracer" 代替。

@happypeter
Copy link
Author

happypeter commented May 14, 2013

视频做下一版的时候,这几个点我都要稍微点到,should have done this.

@perfectfoolish
Copy link

perfectfoolish commented May 14, 2013

恩,这些疑问懂懂了,网站跑起来了

@perfectfoolish
Copy link

perfectfoolish commented May 14, 2013

我fork了代码,想做个管理后台

@billie66
Copy link

billie66 commented May 22, 2013

I had a hard time setting up local dev system, plz show the detailed steps in your revised video.

@happypeter
Copy link
Author

happypeter commented Jul 8, 2014

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment