Last active
August 29, 2015 14:14
-
-
Save luckyyang/43ae08d14c8c18a01a55 to your computer and use it in GitHub Desktop.
minimal setup for rails4/passenger/nginx development
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
################################# | |
# | |
# 本清单基于 ubuntu 12.04, | |
# 下个 ubuntu 的 LTS | |
# 发出来后,会相应更新这里的内容。我的目标是按步执行可以零错误完成安装。 | |
# 注意,本文件只是一个清单,不是一个可以安全执行的脚本 | |
# | |
################################# | |
################################## | |
# | |
# Step 0—Environment Setup | |
# | |
################################# | |
# create a vps instance,login as root, and create a common user for all the tasks | |
ssh root@the_ip_of_vps | |
adduser yourusername --ingroup sudo | |
su yourusername | |
cd # go to /home/yourusername | |
sudo apt-get update | |
sudo apt-get -y install curl git-core | |
################################# | |
# | |
# Step One—Install RBENV(Managing Ruby) | |
# | |
################################# | |
# 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. | |
curl -k https://gist.githubusercontent.com/luckyyang/6034718/raw/20798cadefb228166e51ec92190cb73cdf626ad6/gitconfig >>~/.gitconfig | |
echo "now install rbenv..." # https://github.com/fesplugas/rbenv-installer | |
curl https://raw.githubusercontent.com/fesplugas/rbenv-installer/master/bin/rbenv-installer | bash | |
# add the block to the end of ~/.profile | |
export RBENV_ROOT="${HOME}/.rbenv" | |
echo ' | |
if [ -d "${RBENV_ROOT}" ]; then \ | |
export PATH="${RBENV_ROOT}/bin:${PATH}" \ | |
eval "$(rbenv init -)" \ | |
fi \ | |
' >> ~/.profile | |
source ~/.profile | |
################################# | |
# | |
# Step Two—Install Ruby with RBENV | |
# | |
################################# | |
# I see libxslt1.1 libxml things installed here too, | |
# that's why gems like nokogiri will produce no error installing | |
# If you are installing rbenv in Ubuntu you'll probably need to install some required packages. | |
# You can use the provided bootstrap scripts. | |
rbenv bootstrap-ubuntu-12-04 # this may require password | |
rbenv install 2.2.0 # ruby的版本会影响后面/etc/apache2/http.conf中passenger的设置, | |
rbenv global 2.2.0 # 而且不同的ruby版本所用的gem也不一样,因此要注意。 | |
# 如果切换了ruby版本,apache配置文件(/etc/apache2/http.conf) | |
# 要更改,bundle install要重新做。 | |
# modify gem's settings | |
echo "gem: --no-ri --no-rdoc" | sudo tee -a /home/vagrant/.gemrc | |
################################# | |
# | |
# Step Three—Install Bundler(Managing Dependencies of Ruby Gems) | |
# | |
################################# | |
gem install bundler #这样安装的gem是全局的,gemfile中安装的gem是为某个具体的项目使用的 | |
rbenv rehash #gem安装完之后要做一下rehash,将bundler的PATH加入到$PATH中,才可以在 | |
#命令行中使用bundle命令 | |
# 可选步骤:使用taobao的源(如果提示安装bundler找不到源) | |
sudo gem sources -r https://rubygems.org | |
sudo gem sources -a http://ruby.taobao.org | |
################################# | |
# | |
# Step Four—Install Rails | |
# | |
################################# | |
gem install rails -v 4.2.0 # this is safer to put in a project's Gemfile | |
################################# | |
# | |
# Step Five—Install Passenger | |
# | |
################################# | |
sudo apt-get install -y apache2-prefork-dev libcurl4-openssl-dev libaprutil1-dev | |
gem install passenger #安装全局的passenger | |
rbenv rehash | |
################################# | |
# | |
# Step Six—Install Nginx | |
# | |
################################# | |
passenger-install-nginx-module | |
#https://github.com/phusion/passenger/wiki/Why-can't-Phusion-Passenger-extend-my-existing-Nginx%3F | |
#https://www.digitalocean.com/community/tutorials/how-to-install-rails-and-nginx-with-passenger-on-ubuntu | |
#Passenger first checks that all of the dependancies it needs to work are installed. | |
#If you are missing any, Passenger will let you know how to install them, | |
#either with the apt-get installer on Ubuntu. | |
#After you download any missing dependancies, restart the installation. | |
#Type: passenger-install-nginx-module once more into the command line. | |
#Passenger offers users the choice between an automated setup or a customized one. | |
#Press 1 and enter to choose the recommended, easy, installation. | |
# use nginx as service daemon | |
#(https://www.linode.com/docs/websites/nginx/websites-with-nginx-on-ubuntu-12-04-lts-precise-pangolin/#create-an-init-script-to-manage-nginx) | |
wget -O init-deb.sh http://www.linode.com/docs/assets/1139-init-deb.sh | |
mv init-deb.sh /etc/init.d/nginx | |
chmod +x /etc/init.d/nginx | |
/usr/sbin/update-rc.d -f nginx defaults | |
#You can now start, stop, and restart nginx just like any other server daemon. | |
#For example, to start the server, issue the following command: | |
/etc/init.d/nginx start | |
#edit nginx configurations | |
sudo vi /opt/nginx/conf/nginx.conf | |
#server_name – your IP or domain name, root – location of rails app public folder | |
server { | |
listen 80 default_server; | |
server_name www.maodou.com maodou.io; | |
passenger_enabled on; | |
passenger_app_env development; | |
root /vagrant/public/; | |
} | |
# https://help.github.com/articles/generating-ssh-keys | |
# add ssh key to github, so that you can get a read-write repo clone | |
# ssh-keygen -t rsa -C "2411mail@gmail.com" | |
sudo apt-get install -y nodejs # so that I dont need to install therubyracer | |
################################# | |
# | |
# Step Seven—Install Database | |
# | |
################################# | |
#install mysql server | |
sudo apt-get install mysql-server libapache2-mod-auth-mysql php5-mysql | |
sudo mysql_install_db | |
# and then | |
sudo /usr/bin/mysql_secure_installation | |
mysql -u root -p #login to mysql shell with password you just set | |
#while in mysql shell create new database and add this to database.yml production | |
CREATE DATABASE database name; | |
CREATE USER 'alex'@'localhost' IDENTIFIED BY 'set_your_password_here'; | |
GRANT ALL PRIVILEGES ON your_database.* TO 'alex'@'localhost' WITH GRANT OPTION; | |
exit; | |
#install mysql adapter for rails | |
sudo apt-get install libmysql-ruby libmysqlclient-dev |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment