-
Sign-up for DO account
https://www.digitalocean.com/?refcode=9ce07ab8bad
-
Create a Droplet (Ubuntu 14.04)
-
Prepare the VPS (installing Git, RVM and Ruby)
sudo adduser deploy # create a new user
sudo adduser deploy sudo # add user to sudo group
su deploy # login as new user
sudo apt-get update && sudo apt-get upgrade
# Add PPA repo for git
sudo add-apt-repository ppa:git-core/ppa
sudo apt-get update
# Install Git and Ruby
## Git and dependencies
sudo apt-get install git-core curl zlib1g-dev build-essential libssl-dev libreadline-dev libyaml-dev libsqlite3-dev sqlite3 libxml2-dev libxslt1-dev libcurl4-openssl-dev python-software-properties libffi-dev -y
## Ruby using `rvm`
gpg --keyserver hkp://keys.gnupg.net --recv-keys 409B6B1796C275462A1703113804BB82D39DC0E3
sudo apt-get install libgdbm-dev libncurses5-dev automake libtool bison libffi-dev
curl -L https://get.rvm.io | bash -s stable
# Add the following line to the end of your bashrc
nano ~/.bashrc
>> source ~/.rvm/scripts/rvm
rvm install 2.2.3
rvm use 2.2.3 --default
ruby -v
# Now we tell Rubygems not to install the documentation for each package locally and then install Bundler
echo "gem: --no-ri --no-rdoc" > ~/.gemrc
gem install bundler
- Install nodejs
# Install node 4.x
curl -sL https://deb.nodesource.com/setup_4.x | sudo -E bash -
sudo apt-get install -y nodejs
node -v # Verify version of node installed
npm -v # Verify that you have npm installed too
- Install and config nginx
sudo apt-key adv --keyserver hkp://keyserver.ubuntu.com:80 --recv-keys 561F9B9CAC40B2F7
sudo apt-get install -y apt-transport-https ca-certificates
# Add Passenger 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
sudo vim /etc/nginx/nginx.conf
# sudo nano /etc/nginx/nginx.conf
##
# Phusion Passenger
##
# Uncomment it if you installed ruby-passenger or ruby-passenger-enterprise
##
passenger_root /usr/lib/ruby/vendor_ruby/phusion_passenger/locations.ini;
passenger_ruby /home/deploy/.rvm/gems/ruby-2.2.3/wrappers/ruby; # use the command `passenger-config --ruby-command` to get the path to ruby executable
Start the web server
Now if you copy the ip address of your droplet into a browser you should be able to see the nginx welcome page
- Install PG
sudo apt-get install postgresql postgresql-contrib libpq-dev
Part 2:
Add to Gemfile: gem 'mina'
Run command: mina init
Uncomment following line in config/deploy.rb: require 'mina/rvm' # for rvm support. (http://rvm.io)
When logged in to Digital Ocean from Terminal:
mkdir -p /var/www/YOUR_APP_NAME
sudo chown -R deploy /var/www/YOUR_APP_NAME
Generate ssh key on your server: ssh-keygen -t rsa -b 4096 -C "deploy@YOUR_DROPLET"
Show generated ssh key on screen: cat ~/.ssh/id_rsa.pub
Copy the key to your Github repo/settings/Deploy Keys - add a new deploy key, no write access
Run command: repo_host=
echo git@github.com:GIT_USERNAME/GIT_REPO.git | sed -e 's/.*@//g' -e 's/:.*//g'
Command echo $repo_host should respond: github.com
Run command: repo_port=
echo git@github.com:GIT_USERNAME/GIT_REPO.git | grep -o ':[0-9]*' | sed -e 's/://g'
Run command: repo_port=22
Run command: ssh-keyscan -p $repo_port -H $repo_host
Run command: sudo apt-get install libgmp3-dev
Run command: mina deploy --verbose, will fail
In database.yml file under production changed username and password to postgres.
On server run command: sudo su - postgres
Run command: psql
Run command: ALTER USER postgres WITH PASSWORD 'postgres';
Run command: \q
Run command: exit
Run command: sudo nano /etc/postgresql/9.3/main/pg_hba.conf
Scroll down to section "# Database administrative login by Unix domain socket" and on all change from peer to trust. Save and exit.
sudo service postgresql reload
Run command: mina deploy --verbose, should work now
cd /etc/nginx/sites-available/
sudo touch YOUR_APP_NAME
sudo nano YOUR_APP_NAME - paste the content in sample_hostfile.conf from above
On the line "server_name mydomain.com;" replace mydomain.com with your own domainaddress
Change root to /var/www/YOUR_APP_NAME/current/public;
sudo ln -s /etc/nginx/sites-available/YOUR_APP_NAME /etc/nginx/sites-enabled/YOUR_APP_NAME
sudo service nginx restart
To view the logs for errors you can run command: sudo tail -f /var/log/nginx/error.log