Skip to content

Instantly share code, notes, and snippets.

@manafire
Last active August 29, 2015 14:01
Show Gist options
  • Save manafire/c385b40031309af1c9d6 to your computer and use it in GitHub Desktop.
Save manafire/c385b40031309af1c9d6 to your computer and use it in GitHub Desktop.
Ubuntu + rbenv + github + Rails + Ruby + nginx + passenger + ec2
# IN AMAZON EC2 SERVER #
########################
sudo su
apt-get -y update && apt-get -y upgrade
apt-get install vim git-core curl openssh-server openssh-client python-software-properties build-essential zlib1g-dev libssl-dev libreadline-gplv2-dev libcurl4-openssl-dev aptitude
/usr/sbin/groupadd wheel
/usr/sbin/visudo
(paste bottom)
%wheel ALL=(ALL) ALL
/usr/sbin/adduser deploy
/usr/sbin/usermod -a -G wheel deploy
su deploy
cd ~
mkdir .ssh
sudo cp /home/ubuntu/.ssh/authorized_keys .ssh/
sudo chmod -R 700 .ssh/
sudo chown deploy:deploy .ssh/authorized_keys
sudo chmod 600 ~deploy/.ssh/authorized_keys
#install rbenv, ruby and bundler
git clone git://github.com/sstephenson/rbenv.git ~/.rbenv
echo 'export PATH="$HOME/.rbenv/bin:$PATH"' >> ~/.profile
echo 'eval "$(rbenv init -)"' >> ~/.profile
exec $SHELL -l
git clone git://github.com/sstephenson/ruby-build.git ~/.rbenv/plugins/ruby-build
rbenv install 2.1.2
rbenv global 2.1.2
gem install bundler
#install passenger
gem install passenger
rbenv rehash
passenger-install-nginx-module
#choose option 1
#install on /home/deployer/nginx
wget -O init-deb.sh http://library.linode.com/assets/660-init-deb.sh
sudo mv init-deb.sh /etc/init.d/nginx
sudo chmod +x /etc/init.d/nginx
sudo /usr/sbin/update-rc.d -f nginx defaults
sudo /etc/init.d/nginx stop
sudo /etc/init.d/nginx start
sudo apt-get install nodejs
# NGINX CONFIGURATION #
#######################
sudo mkdir /opt/nginx/sites
sudo vim /opt/nginx/conf/nginx.conf
(remove server {...})
(add the following:)
include /opt/nginx/sites/*;
sudo vim /opt/nginx/sites/<WEBSITE_NAME>
(The following is needed)
server {
passenger_enabled on;
root /home/deploy/WEBSITE/current/public;
passenger_friendly_error_pages off;
rails_env production;
location ~ ^/assets/ {
expires 1y;
add_header Cache-Control public;
add_header ETag "";
break;
}
}
# Things to do: add gzip, set recommended workers etc..
# SSH CONFIGURATION: AMAZON-EC2 SERVER => GITHUB #
#####################################################
su deploy
ssh-keygen -t rsa
vim /home/deploy/.ssh/id_rsa.pub
(copy content into github repo > settings > deploy keys)
ssh -T git@github.com
# EXTRAS #
##########
sudo su
vim ~/.bashrc
(paste bottom)
# Parse the git branch and display in path, if applicable
parse_git_branch() {
git branch 2> /dev/null | sed -e '/^[^*]/d' -e 's/* \(.*\)/ \[\1\]/'
}
export PS1='\[\033[0;32m\]\h \[\033[0;36m\]\w\[\033[00;35m\]$(parse_git_branch)\[\033[00m\] \$ '
source ~/.bashrc
su deploy
vim ~/.bashrc
(paste bottom)
# Parse the git branch and display in path, if applicable
parse_git_branch() {
git branch 2> /dev/null | sed -e '/^[^*]/d' -e 's/* \(.*\)/ \[\1\]/'
}
export PS1='\[\033[0;32m\]\h \[\033[0;36m\]\w\[\033[00;35m\]$(parse_git_branch)\[\033[00m\] \$ '
alias free="free -m"
alias update="sudo aptitude update"
alias install="sudo aptitude install"
alias upgrade="sudo aptitude safe-upgrade"
alias remove="sudo aptitude remove"
source ~/.bashrc
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment