This is a walkthrough for deploying a Rails app on an Ubuntu Server with Nginx, Passenger, Postgres, and DelayedJob.
sudo apt-get update
sudo apt-get install curl git nodejs
This app requires RVM to manage Ruby versions and gemsets. You can install RVM and Ruby 2.1.3 with the following:
gpg --keyserver hkp://keys.gnupg.net --recv-keys D39DC0E3
\curl -sSL https://get.rvm.io | bash -s stable
source ~/.rvm/scripts/rvm
rvm requirements # This will take a while...
rvm install ruby-x.x.x
rvm rvmrc warning ignore allGemfiles
gem install bundler
sudo apt-get install postgresql postgresql-contrib libpq-dev
sudo su postgres -c psql
postgres=# CREATE ROLE <username> SUPERUSER LOGIN;
postgres=# \q
First, you need to clone the repository and cd
into it.
git clone https://url-for-git-repo.com/git-user/project-name.git && cd project-name
Then install the gem dependencies:
bundle --without development test # This will take a while...
And copy over the configuration files:
cp config/application.yml.sample config/application.yml
cp config/database.yml.sample config/database.yml
It is also advisable to run the test suite as a sanity test (if doing so run $ bundle --without development
):
rspec
rails s
If PG complains about your locale see https://gist.github.com/turboladen/6790847
If PG fails for authentication see http://stackoverflow.com/questions/2942485/psql-fatal-ident-authentication-failed-for-user-postgres
rake db:create RAILS_ENV=production
rake db:migrate RAILS_ENV=production
rake db:seed RAILS_ENV=production
rake assets:precompile
gem install passenger
rvmsudo passenger-install-nginx-module
Here, the install may complain about missing dependencies. You will need to install them
and then execute rvmsudo passenger-install-nginx-module
to restart the installation.
sudo nano /opt/nginx/conf/nginx.conf
http {
# ...
server {
# ...
passenger_enabled on;
root /path/to/project-name/public;
# ...
}
# ...
}
If you have nginx in /usr/bin, you will need rename it and link the nginx that was installed by passenger-install-nginx-module
cd /usr/sbin
mv nginx nginx.dist
ln -s /opt/nginx/sbin/nginx .
Cron jobs are used for a few background tasks that keep the UI up to date with the VC, you can add them to a crontab with:
whenever --update-cron projectname
This will minify, uglify, and concatenate static assets so they're ready to be served up by the app.
rake assets:precompile
sudo service nginx start
That's it, now open your browser and navigate the the IP specified in the nginx conf.