-
-
Notifications
You must be signed in to change notification settings - Fork 499
Installing Helpy on Ubuntu 16.04 using Passenger and Nginx
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
sudo apt-get dist-upgrade
Step 4: Install Passenger with apt-get
# Install PGP Key and add https support
sudo apt-get install -y dirmngr gnupg
sudo apt-key adv --keyserver hkp://keyserver.ubuntu.com:80 --recv-keys 561F9B9CAC40B2F7
sudo apt-get install -y apt-transport-https ca-certificates
# Add Phusion APT repository
sudo sh -c 'echo deb https://oss-binaries.phusionpassenger.com/apt/passenger xenial main > /etc/apt/sources.list.d/passenger.list'
sudo apt-get update
# Install Passenger + Nginx
sudo apt-get install -y nginx-extras passenger
Step 5: 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
sudo apt install gnupg2
gpg2 --recv-keys 409B6B1796C275462A1703113804BB82D39DC0E3 7D2BAF1CF37B13E2069D6956105BD0E739499BDB
\curl -sSL https://get.rvm.io | bash -s stable
source /home/rails/.rvm/scripts/rvm
Install Ruby and create a gemset for Helpy:
cd ~
rvm install 2.3
rvm requirements
rvm alias create default ruby-2.3
rvm gemset create helpy
rvm 2.3.3@helpy
gem install rails --no-ri --no-rdoc -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.
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 -p 3000
Step 7: Add a swap file and 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 enable Passenger and point to your installation:
sudo nano /etc/nginx/nginx.conf
scroll down to the section Phusion Passenger Config
and uncomment the following line:
include /etc/nginx/passenger.conf;
Next you will need to add a simple virtual host for your new install. 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/rails/helpy/public;
# Turn on Passenger
passenger_enabled on;
passenger_ruby /home/rails/.rvm/gems/ruby-2.3.8@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
- 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
- https://www.phusionpassenger.com/library/install/nginx/install/oss/xenial/