How to Install Ruby on Rails with Nginx and Passenger


ruby-iconRuby on Rails, or simply Rails, is an open source web application framework built on top of the Ruby programming language. In this article, we will show you how to install Ruby, Ruby on Rails and Nginx with Passenger support  on Debian-based distributions (Ubuntu VPS and Debian VPS).

 

 

First install Ruby using RVM

curl -L https://get.rvm.io | bash -s stable --ruby

To start using RVM run:

source /usr/local/rvm/scripts/rvm

To verify everything is done correctly, use the command “ruby -v”.
The output should be similar to the following:

# ruby --version
ruby 2.0.0p247 (2013-06-27 revision 41674) [i686-linux]

 

Install Rails and Passenger

gem install rails passenger

 

Install Nginx with Passenger.

apt-get install libcurl4-openssl-dev
rvmsudo passenger-install-nginx-module

Select the first option when prompted and press Enter.
(1. This installer will compile and install Nginx with Passenger support.)

If the installation is successful, you will see a message similar to the following:
Nginx with Passenger support was successfully installed.

Create an init script (/etc/init.d/nginx) with the following content:

#! /bin/sh

### BEGIN INIT INFO
# Provides:          nginx
# Required-Start:    $all
# Required-Stop:     $all
# Default-Start:     2 3 4 5
# Default-Stop:      0 1 6
# Short-Description: starts the nginx web server
# Description:       starts nginx using start-stop-daemon
### END INIT INFO

PATH=/opt/nginx/sbin:/sbin:/bin:/usr/sbin:/usr/bin
DAEMON=/opt/nginx/sbin/nginx
NAME=nginx
DESC=nginx

test -x $DAEMON || exit 0

set -e

case "$1" in
  start)
        echo -n "Starting $DESC: "
        start-stop-daemon --start --quiet --pidfile /opt/nginx/logs/$NAME.pid \
                --exec $DAEMON -- $DAEMON_OPTS
        echo "$NAME."
        ;;
  stop)
        echo -n "Stopping $DESC: "
        start-stop-daemon --stop --quiet --pidfile /opt/nginx/logs/$NAME.pid \
                --exec $DAEMON
        echo "$NAME."
        ;;
  restart|force-reload)
        echo -n "Restarting $DESC: "
        start-stop-daemon --stop --quiet --pidfile \
                /opt/nginx/logs/$NAME.pid --exec $DAEMON
        sleep 1
        start-stop-daemon --start --quiet --pidfile \
                /opt/nginx/logs/$NAME.pid --exec $DAEMON -- $DAEMON_OPTS
        echo "$NAME."
        ;;
reload)
        echo -n "Reloading $DESC configuration: "
        start-stop-daemon --stop --signal HUP --quiet --pidfile /opt/nginx/logs/$NAME.pid \
                --exec $DAEMON
        echo "$NAME."
        ;;
*)
        N=/etc/init.d/$NAME
        echo "Usage: $N {start|stop|restart|reload|force-reload}" >&2
        exit 1
        ;;
esac

exit 0

To start the Nginx service run:

chmod a+x /etc/init.d/nginx
service nginx start
update-rc.d nginx defaults

 

Install MySQL/MariaDB and Postgresql Support

apt-get install libmysqld-dev # or libmariadbd-dev
apt-get install libpq-dev
gem install mysql2 pq

Of course you don’t have to do any of this if you use one of our Linux VPS services, in which case you can simply ask our expert linux admins to install this for you. They are available 24×7 and will take care of your request immediately.

PS. If you liked this post please share it with your friends on the social networks using the buttons on the left or simply leave a reply below. Thanks

Tutorials
How to monitor your server’s resource usage with Munin on CentOS 6
Tutorials
Install Baun CMS on an Ubuntu 14.04 VPS
Tutorials
Deploy CiviCRM in conjunction with Drupal on an Ubuntu 14.04 VPS
  • knut

    knutknut

    Author Reply

    Many thanks.