Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Star 10 You must be signed in to star a gist
  • Fork 5 You must be signed in to fork a gist
  • Save aghyad/7778897 to your computer and use it in GitHub Desktop.
Save aghyad/7778897 to your computer and use it in GitHub Desktop.
A quick tutorial on installing passenger, Nginx, Ruby and Rails on Ubuntu 12.04 (without RVM/without rbenv)
When installing passenger, Nginx, Ruby and Rails on Ubuntu 12.04 (without RVM/without rbenv):
First: installing Ruby (without RVM):
sudo apt-get update
sudo apt-get install ruby1.9.1 ruby1.9.1-dev \
rubygems1.9.1 irb1.9.1 ri1.9.1 rdoc1.9.1 \
build-essential libopenssl-ruby1.9.1 libssl-dev zlib1g-dev
sudo update-alternatives --install /usr/bin/ruby ruby /usr/bin/ruby1.9.1 400 \
--slave /usr/share/man/man1/ruby.1.gz ruby.1.gz \
/usr/share/man/man1/ruby1.9.1.1.gz \
--slave /usr/bin/ri ri /usr/bin/ri1.9.1 \
--slave /usr/bin/irb irb /usr/bin/irb1.9.1 \
--slave /usr/bin/rdoc rdoc /usr/bin/rdoc1.9.1
# choose your interpreter
# changes symlinks for /usr/bin/ruby , /usr/bin/gem
# /usr/bin/irb, /usr/bin/ri and man (1) ruby
sudo update-alternatives --config ruby
sudo update-alternatives --config gem
# now try
ruby --version
Second: installing Rails:
gem install rails
Third: installing passenger:
gem install passenger
Forth: installing nginx:
Either:
sudo /opt/ruby/bin/passenger-install-nginx-module --auto --prefix=/opt/nginx/ --auto-download --extra-configure-flags=--with-http_ssl_module
OR:
sudo passenger-install-nginx-module
Fifth: Use this script for init.d service for 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
after that you can control nginx with:
sudo /etc/init.d/nginx stop
sudo /etc/init.d/nginx start
sudo /etc/init.d/nginx restart
NOTE: if those commands failed for another process using the same port, do this:
passenger-memory-stats
and then kill all the processes of nginx to start with a clean slate.
At this point, nginx should be running, and you can make sure by visiting you www.MYDOMAIN.com and you'll see a message like "Welcome to Nginx ...."
Also you can verify that nginx and passenger are working by checking the processes andtheir status in memory:
passenger-memory-stats
Sixth: configuring nginx to access your rails app:
Using vim, Access the nginx.conf file:
vim /opt/nginx/conf/nginx.conf
That's the block you need to edit:
http {
...
server {
listen 80;
server_name www.MYDOMAIN.com;
root /path/to/my/rails/app/public; ### MAKE SURE TO POINT TO PUBLIC FOLDER
passenger_enabled on;
}
...
### NOW COMMENT THE FOLLOWING BLOCK AND ALL LINES IN BETWEEN:
#location / {
# root html;
# .......
# .....
#}
}
Save the conf file, then restart nginx
sudo /etc/init.d/nginx restart
Also if you have a rails app already deployed, it doesn't hurt to restart it by doing:
touch /pathtorailsapp/tmp/restart.txt
========================
Sources:
https://www.digitalocean.com/community/articles/how-to-install-rails-and-nginx-with-passenger-on-ubuntu
http://ivanvanderbyl.github.io/2011/01/14/rails-nginx-passenger-ubuntu.html
http://www.modrails.com/documentation/Users%20guide%20Nginx.html#_deploying_to_a_virtual_host_8217_s_root
@moughxyz
Copy link

If you're using a Cent-OS like system (like Amazon's AMI) where you don't have apt-get, I've written something that might help: https://neeto.io/b69AwLSK

@gitmeupnow
Copy link

gitmeupnow commented Jan 9, 2018

Thank you perfect exact plug and play it works for me on Ubuntu 17.10

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment