Skip to content

Installing Helpy on Ubuntu 14.04 using Passenger and Nginx

Scott Miller edited this page Feb 5, 2018 · 3 revisions

Installing Helpy on Ubuntu with Passenger on the webserver is the easiest way to configure and install Helpy from scratch on a new VPS. This is the recommended approach if you want to build up a server from scratch.

Step 1: Add a Rails User

ssh [email protected]
adduser rails
gpasswd -a rails sudo

Step 2: Set up SSH

You may not have to do this, depending on your host. For example, Digital Ocean has the ability to provision a VPS with your SSH key already installed.

ssh-keygen
ssh-copy-id rails@SERVER_IP_ADDRESS

Recommended: Disable root login

nano /etc/ssh/sshd_config
PermitRootLogin no
systemctl reload sshd

Step 3: Update Ubuntu and Install Dependencies

sudo apt-get update
sudo apt-get install -y git-core imagemagick postgresql postgresql-contrib libpq-dev curl build-essential zlib1g-dev libssl-dev libreadline-dev libyaml-dev libsqlite3-dev sqlite3 libcurl4-openssl-dev libxml2-dev libxslt1-dev python-software-properties nodejs

Step 4: Configure Postgres

su - postgres 
createuser -s rails
createdb helpy_production
psql
\password rails
\q

Now, switch to our new rails user for the rest of the install:

su rails

Step 5: Install RVM, Ruby and Rails

gpg --keyserver hkp://keys.gnupg.net --recv-keys 409B6B1796C275462A1703113804BB82D39DC0E3
curl -sSL https://get.rvm.io | bash -s stable
source /home/rails/.rvm/scripts/rvm

Install Ruby and create a gemset for Helpy:

rvm install 2.3.3
rvm requirements

rvm gemset create helpy
rvm 2.3.3@helpy
gem install rails --no-ri --no-rdoc -v 4.2.10
gem install bundler

Step 6: Install Helpy

We will now clone Helpy and bundle install to set up the required gems. In this example we are pulling Helpy directly from master. In reality you probably will want to fork Helpy and then clone from your local fork and/or use capistrano to manage your deployment.

git clone https://github.com/helpyio/helpy.git
cd helpy

and install dependencies

bundle install

Now set up the database and secrets files:

cp config/database.do.yml config/database.yml
rake secret
# copy the key to

nano config/secrets.yml
nano config/database.yml

touch /home/rails/helpy/log/production.log
chmod 0664 /home/rails/helpy/log/production.log

Unpack the Helpy assets and setup your database:

RAILS_ENV=production rake assets:precompile
RAILS_ENV=production rake db:setup

Congrats! you should now be able to start web brick, and test your Helpy in the browser:

rails s -e production -b your.ip.add.ress:3000

Step 7: Install Passenger with Nginx

Add a swap file for passenger:

sudo dd if=/dev/zero of=/swap bs=1M count=1024
sudo mkswap /swap 
sudo swapon /swap

and go ahead and install passenger and nginx (select the default options when prompted):

gem install passenger --no-ri
export rvmsudo_secure_path=1
rvmsudo passenger-install-nginx-module

Run the following commands to add some handy management commands to your server:

# Download nginx startup script
wget -O init-deb.sh https://www.linode.com/docs/assets/660-init-deb.sh

# Move the script to the init.d directory & make executable 
sudo mv init-deb.sh /etc/init.d/nginx 
sudo chmod +x /etc/init.d/nginx 

# Add nginx to the system startup 
sudo /usr/sbin/update-rc.d -f nginx defaults

Finally, update your Nginx configuration to point to the Helpy installation:

sudo nano /opt/nginx/conf/nginx.conf

Replace the contents with the following file, or create your own config:

#user  root;
worker_processes  1;

#error_log  logs/error.log;
#error_log  logs/error.log  notice;
#error_log  logs/error.log  info;

#pid        logs/nginx.pid;


events {
    worker_connections  1024;
}


http {
    passenger_root /home/rails/.rvm/gems/ruby-2.2.1/gems/passenger-5.0.26;
    passenger_ruby /home/rails/.rvm/gems/ruby-2.2.1/wrappers/ruby;

    include       mime.types;
    default_type  application/octet-stream;

    log_format  main  '$remote_addr - $remote_user [$time_local] "$request" '
                      '$status $body_bytes_sent "$http_referer" '
                      '"$http_user_agent" "$http_x_forwarded_for"';

    access_log  logs/access.log  main;

    sendfile        on;
    #tcp_nopush     on;

    #keepalive_timeout  0;
    keepalive_timeout  65;

    #gzip  on;

    server {
	listen       80;
        server_name  localhost;

        #charset koi8-r;

        #access_log  logs/host.access.log  main;

        root /home/rails/helpy/public;
        passenger_enabled on;
	rails_env production;

        #error_page  404              /404.html;

        # redirect server error pages to the static page /50x.html
        #
        #error_page   500 502 503 504  /50x.html;
	
	location ~ ^/(assets|images|javascripts|stylesheets|system)/ {
    	  expires max;
    	  add_header Cache-Control public;
 	}
    }

}

Now start up passenger/nginx and your site should be live!

sudo service nginx start

References

https://gist.github.com/julionc/4006d5b2091496600fc2 https://www.digitalocean.com/community/tutorials/how-to-deploy-a-rails-app-with-passenger-and-nginx-on-ubuntu-14-04 http://askubuntu.com/questions/257108/trying-to-start-nginx-on-vps-i-get-nginx-unrecognized-service