Last active
April 20, 2016 16:56
-
-
Save chriswain/aa75e2132e59f22f5f55 to your computer and use it in GitHub Desktop.
installing rails on ubuntu
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
1. sudo apt-get update | |
2. sudo apt-get install git | |
3. git clone git://github.com/sstephenson/rbenv.git .rbenv | |
4. echo 'export PATH="$HOME/.rbenv/bin:$PATH"' >> ~/.bash_profile | |
5. echo 'eval "$(rbenv init -)"' >> ~/.bash_profile | |
6. exec $SHELL | |
7. git clone git://github.com/sstephenson/ruby-build.git ~/.rbenv/plugins/ruby-build | |
8. echo 'export PATH="$HOME/.rbenv/plugins/ruby-build/bin:$PATH"' >> ~/.bash_profile | |
9. exec $SHELL | |
10. source ~/.bash_profile | |
10a. cd ~/.rbenv/plugins | |
10b. git clone https://github.com/sstephenson/rbenv-vars.git | |
11. sudo apt-get install build-essential | |
12. 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 | |
12. rbenv install -v 2.2.2 | |
13. rbenv global 2.2.2 | |
14. echo "gem: --no-document" > ~/.gemrc | |
15. gem install bundler | |
16. gem install rails -v 4.2.5 | |
17. rbenv rehash | |
18. gem install rails-api | |
19. rbenv rehash | |
20. sudo add-apt-repository ppa:chris-lea/node.js | |
21. sudo apt-get update | |
22. sudo apt-get install nodejs | |
// install postgresql | |
23. sudo sh -c 'echo "deb http://apt.postgresql.org/pub/repos/apt/ `lsb_release -cs`-pgdg main" >> /etc/apt/sources.list.d/pgdg.list' | |
24. wget -q https://www.postgresql.org/media/keys/ACCC4CF8.asc -O - | sudo apt-key add - | |
25. sudo apt-get update | |
26. sudo apt-get install postgresql postgresql-contrib | |
27. sudo su - postgres //postgres is the user created when downloaded | |
28. psql | |
29. \conninfo //to check connection info | |
30. create role app_name login createdb; | |
31. ALTER ROLE app_name WITH PASSWORD 'passwordgohere'; // password must be in single quotes and maybe need to alter role with create db as well as password again if not working | |
32. \q //to quit | |
33. sudo vi /etc/postgresql/9.5/main/pg_hba.conf go to bottom and change peer to md5 | |
// for rails pg gem | |
33. sudo apt-get install libpq-dev // will fix error when installing pg gem | |
34. gem install passenger | |
35. sudo apt-get install nginx | |
36. add gem 'unicorn' | |
37. vi config/unicorn.rb | |
copy and paste this: | |
# set path to application | |
app_dir = File.expand_path("../..", __FILE__) | |
shared_dir = "#{app_dir}/shared" | |
working_directory app_dir | |
# Set unicorn options | |
worker_processes 2 | |
preload_app true | |
timeout 30 | |
# Set up socket location | |
listen "#{shared_dir}/sockets/unicorn.sock", :backlog => 64 | |
# Logging | |
stderr_path "#{shared_dir}/log/unicorn.stderr.log" | |
stdout_path "#{shared_dir}/log/unicorn.stdout.log" | |
# Set master PID location | |
pid "#{shared_dir}/pids/unicorn.pid" | |
38. mkdir -p shared/pids shared/sockets shared/log | |
39. sudo vi /etc/init.d/unicorn_appname | |
copy paste this replace user and app_name with proper values: | |
#!/bin/sh | |
### BEGIN INIT INFO | |
# Provides: unicorn | |
# Required-Start: $all | |
# Required-Stop: $all | |
# Default-Start: 2 3 4 5 | |
# Default-Stop: 0 1 6 | |
# Short-Description: starts the unicorn app server | |
# Description: starts unicorn using start-stop-daemon | |
### END INIT INFO | |
set -e | |
USAGE="Usage: $0 <start|stop|restart|upgrade|rotate|force-stop>" | |
# app settings | |
USER="deploy" | |
APP_NAME="appname" | |
APP_ROOT="/home/$USER/$APP_NAME" | |
ENV="production" | |
# environment settings | |
PATH="/home/$USER/.rbenv/shims:/home/$USER/.rbenv/bin:$PATH" | |
CMD="cd $APP_ROOT && bundle exec unicorn -c config/unicorn.rb -E $ENV -D" | |
PID="$APP_ROOT/shared/pids/unicorn.pid" | |
OLD_PID="$PID.oldbin" | |
# make sure the app exists | |
cd $APP_ROOT || exit 1 | |
sig () { | |
test -s "$PID" && kill -$1 `cat $PID` | |
} | |
oldsig () { | |
test -s $OLD_PID && kill -$1 `cat $OLD_PID` | |
} | |
case $1 in | |
start) | |
sig 0 && echo >&2 "Already running" && exit 0 | |
echo "Starting $APP_NAME" | |
su - $USER -c "$CMD" | |
;; | |
stop) | |
echo "Stopping $APP_NAME" | |
sig QUIT && exit 0 | |
echo >&2 "Not running" | |
;; | |
force-stop) | |
echo "Force stopping $APP_NAME" | |
sig TERM && exit 0 | |
echo >&2 "Not running" | |
;; | |
restart|reload|upgrade) | |
sig USR2 && echo "reloaded $APP_NAME" && exit 0 | |
echo >&2 "Couldn't reload, starting '$CMD' instead" | |
$CMD | |
;; | |
rotate) | |
sig USR1 && echo rotated logs OK && exit 0 | |
echo >&2 "Couldn't rotate logs" && exit 1 | |
;; | |
*) | |
echo >&2 $USAGE | |
exit 1 | |
;; | |
esac | |
40. sudo chmod 755 /etc/init.d/unicorn_appname //this line and next for starting and stopping on boot | |
41. sudo update-rc.d unicorn_appname defaults | |
42. sudo service unicorn_appname start // now its started but before it will be availabe to outside user must set up nginx reverse proxy | |
43. sudo vi /etc/nginx/sites-available/default // open default server block with vi | |
44. replace files contents with following highlight out things if you dont want to delete: | |
upstream app { | |
# Path to Unicorn SOCK file, as defined previously | |
server unix:/home/deploy/appname/shared/sockets/unicorn.sock fail_timeout=0; | |
} | |
server { | |
listen 80; | |
server_name localhost; | |
root /home/deploy/appname/public; | |
try_files $uri/index.html $uri @app; | |
location @app { | |
proxy_pass http://app; | |
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for; | |
proxy_set_header Host $http_host; | |
proxy_redirect off; | |
} | |
error_page 500 502 503 504 /500.html; | |
client_max_body_size 4G; | |
keepalive_timeout 10; | |
} | |
45. // This configures Nginx as a reverse proxy, so HTTP requests get forwarded to the Unicorn application server via a Unix socket | |
46. go back to rails main directory and do the command RAILS_ENV=production rake db:create if you have not already done so | |
47. then migrate with this RAILS_ENV=production rake db:migrate | |
48. sudo service nginx restart //restart nginx to see changes | |
49. listen on port 80 http://public_ip | |
50. make sure all env variables are set properly try using rbenv vars |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment