Join the social network of Tech Nerds, increase skill rank, get work, manage projects...
 
  • Rails Server Setup with passenger and nginx

    • 0
    • 0
    • 0
    • 0
    • 0
    • 0
    • 0
    • 0
    • 293
    Comment on it

    Rails Server setup with Passenger and nginx

    Hi friends,
    Today I am going to tell you how to setup rails server with nginx and passenger. First you need to login to your server using ssh using the command

     ssh -i server_pem_key_path user@ip 
    Here the user can be any of your server's user that has root privileges like ubuntu. The steps to setup rails server are:

    STEP 1: Go to root folder of the server and update for any pre-requirements:
    sudo apt-get update
    STEP 2: After it is complete we need to install RVM (Ruby Version Manager)
    curl -L get.rvm.io | bash -s stable
    STEP 3: After installing rvm, we need to reload it.
    source ~/.rvm/scripts/rvm
    STEP 4: Now you need to install the rvm dependencies.
    rvm requirements
    STEP 5: The above command shows which dependencies are needed to be installed again.
        Additional Dependencies:
        # For Ruby / Ruby HEAD (MRI, Rubinius, & REE), install the following:
          ruby: /usr/bin/apt-get install build-essential openssl libreadline6 libreadline6-dev curl git-core zlib1g zlib1g-dev libssl-dev libyaml-dev libsqlite3-dev sqlite3 libxml2-dev libxslt-dev autoconf libc6-dev ncurses-dev automake libtool bison subversion
    
        #These can be installed by simply hitting the following command at once:
        rvmsudo /usr/bin/apt-get install build-essential openssl libreadline6 libreadline6-dev curl git-core zlib1g zlib1g-dev libssl-dev libyaml-dev libsqlite3-dev sqlite3 libxml2-dev libxslt-dev autoconf libc6-dev ncurses-dev automake libtool bison subversion
    

    STEP 6: After installing rvm you can install any of your desired ruby version using rvm and set it as default.

        rvm install 2.2.1
        rvm use 2.2.1 --default
    

    STEP 7: Now you need to install ruby gems.

        rvm rubygems current
    

    STEP 8: Now install rails. The following command will install the latest stable version of the rails

        gem install rails
        //for specific version do  gem install rails --version=4.2.4
    

    STEP 9: Now as rails is installed, you can install passenger

        gem install passenger 
    

    STEP 10: Now after thism you need to install nginx module with this command.

        rvmsudo passenger-install-nginx-module
    

    After this is installed, it takes care of everything, it tells you step by step what dependencies are pending and what steps needs to be followed.

    STEP 11: Now once you finish with everything installed you need to start the nginx services.

        sudo service nginx start 
    

    Now if there comes an error like unrecognized service You need to fix it by:

        wget -O init-deb.sh https://www.linode.com/docs/assets/660-init-deb.sh
        sudo mv init-deb.sh /etc/init.d/nginx
        sudo chown root:root /etc/init.d/nginx
        sudo chmod +x /etc/init.d/nginx
        sudo /usr/sbin/update-rc.d -f nginx defaults
    

    STEP 12: Now change the nginx config file to connect it to your rails application. Create a rails application at your preferred location and change the nginx config file. By default the path of the file will be at /opt/nginx/conf/nginx.conf Now set the root and add your project location and comment the location block like this:

        root /your_project_address;
    
        #location / {
        #    root  html
        #    index index.html index.htm
        #}
    

    Thus your rails setup is ready on the server.
    Thanx for reading my blog. Hope you liked it.

 0 Comment(s)

Sign In
                           OR                           
                           OR                           
Register

Sign up using

                           OR                           
Forgot Password
Fill out the form below and instructions to reset your password will be emailed to you:
Reset Password
Fill out the form below and reset your password: