Skip to content

Install to Ubuntu 20.04 (WIP)

Scott Miller edited this page Feb 2, 2021 · 2 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 deploy
usermod -aG sudo deploy

Step 2: Allow SSH, http(s) through firewall

ufw allow OpenSSH
ufw allow http
ufw allow https
ufw enable
ufw status

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, although you may have to copy the key from root to your new user:

rsync --archive --chown=deploy:deploy ~/.ssh /home/deploy

Otherwise:

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 nginx 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 software-properties-common nodejs gnupg2
sudo apt-get dist-upgrade

Step 4: Install Passenger with apt-get

# Install our PGP key and add HTTPS support for APT
sudo apt-get install -y dirmngr gnupg nginx
sudo apt-key adv --keyserver hkp://keyserver.ubuntu.com:80 --recv-keys 561F9B9CAC40B2F7
sudo apt-get install -y apt-transport-https ca-certificates

# Add our APT repository
sudo sh -c 'echo deb https://oss-binaries.phusionpassenger.com/apt/passenger focal main > /etc/apt/sources.list.d/passenger.list'
sudo apt-get update

# Install Passenger + Nginx module
sudo apt-get install -y libnginx-mod-http-passenger

Step 5: Configure Postgres

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

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

su deploy

Step 5: Install RVM, Ruby and Rails

gpg --keyserver hkp://keys.gnupg.net --recv-keys 409B6B1796C275462A1703113804BB82D39DC0E3 7D2BAF1CF37B13E2069D6956105BD0E739499BDB
curl -sSL https://get.rvm.io | bash -s stable

To start using RVM you need to run source /home/deploy/.rvm/scripts/rvm in all your open shell windows

Install Ruby and create a gemset for Helpy:

rvm install 2.6
rvm requirements
rvm alias create default ruby-2.6
rvm gemset create helpy
rvm 2.6@helpy
gem install rails -v 4.2.11
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.

cd ~
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/deploy/helpy/log/production.log
chmod 0664 /home/deploy/helpy/log/production.log

Unpack the Helpy assets and setup your database:

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

Step 7: Configure Nginx

Add a swap file for passenger:

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

Finally, update your Nginx configuration to point to your installation by adding a simple virtual host for your new install.

Note: This is an overly simplified barebones setup, and should be customized for production use.

Type sudo nano /etc/nginx/sites-available/default and replace with something like:

server {
    listen 80;
    server_name yourserver.com;

    # Tell Nginx and Passenger where your app's 'public' directory is
    root /home/deploy/helpy/public;

    # Turn on Passenger
    passenger_enabled on;
    passenger_ruby /home/deploy/.rvm/gems/ruby-2.6.6@helpy/wrappers/ruby;

    # Configure ENV vars to turn on remote filestore (optional)
    # REQUIRES HELPY 2.3+
    #passenger_env_var REMOTE_STORAGE true;
    #passenger_env_var S3_KEY change_key;
    #passenger_env_var S3_SECRET change_secret;
    #passenger_env_var S3_REGION change_region;
    #passenger_env_var S3_ENDPOINT change_endpoint;
    #passenger_env_var S3_BUCKET_NAME change_bucket_name;
}

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

sudo service nginx start

References