Skip to content

Instantly share code, notes, and snippets.

@vinisba
Last active March 21, 2023 12:07
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save vinisba/ad5382364c892432fc17623182ef4f04 to your computer and use it in GitHub Desktop.
Save vinisba/ad5382364c892432fc17623182ef4f04 to your computer and use it in GitHub Desktop.
Hospedin PMS Ubuntu 22.04

Hospedin PMS setup on Ubuntu 22.04

Requeriments

  • ruby 2.5.0
  • node 14.x

Base

Install necessaries packages

$ # ruby is needed for rvm compile new builds
$ # python2 is needed for compile node-sass from package.json
$ sudo apt install ruby python2 gnupg2 git curl libpq-dev wkhtmltopdf

Ruby setup using rvm

$ gpg2 --keyserver keyserver.ubuntu.com --recv-keys 409B6B1796C275462A1703113804BB82D39DC0E3 7D2BAF1CF37B13E2069D6956105BD0E739499BDB
$ \curl -sSL https://get.rvm.io | bash -s stable
$ source /home/ubuntu/.rvm/scripts/rvm
$ rvm pkg install openssl
$ rvm install 2.5.0 --with-openssl-dir=$HOME/.rvm/usr
$ rvm --default use 2.5.0 # optional this make ruby 2.5.0 as your ruby default version

NodeJS setup

  • Method 1:
$ curl -sL https://deb.nodesource.com/setup_14.x | sudo -E bash -
$ sudo apt install -y nodejs
  • Method 2 using nvm:
$ curl -o- https://raw.githubusercontent.com/nvm-sh/nvm/v0.39.3/install.sh | bash
$ source ~/.bashrc # refresh your terminal if you using bash
$ nvm install 14
$ nvm use 14
  • Installing yarn
$ npm i -g yarn

Development environment (optional)

Install PostgreSQL

$ sudo apt install postgresql postgresql-contrib
$ sudo service postgresql start # ensure that the server is running

Changing user postgres password

$ sudo -i -u postgres
$ psql # running on console with postgres user
> ALTER USER postgres WITH PASSWORD 'postgres'; # running on psql
> \q # exit from psql
$ exit # exit from postgres user console

Hospedin PMS setup

Cloning

$ git clone git@github.com:hospedin/hospedin-pms.git # make sure your ssh key has permission to fetch the repository
$ cd . # to refresh rvm new gemsets

Installing gems

  • Development
$ bundle install
  • Production
$ bundle install --deployment --without development test

Node modules

$ yarn install

Configure

$ cp config/database.example.yml config/database.yml
$ cp .sample_env .env

Check that the database variables have the right value in the .env file

You can get current development env variables from this link.

Running on development

$ rake db:prepare # alias for run drop > create > migrate > seed
$ rails s # start dev server

Production setup using Passenger

Install Passenger packages

# Install Nginx
$ sudo apt install nginx

# Install our PGP key and add HTTPS support for APT
$ sudo apt install -y dirmngr gnupg apt-transport-https ca-certificates curl

$ curl https://oss-binaries.phusionpassenger.com/auto-software-signing-gpg-key.txt | gpg --dearmor | sudo tee /etc/apt/trusted.gpg.d/phusion.gpg >/dev/null

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

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

Enable the Passenger Nginx module and restart Nginx

$ if [ ! -f /etc/nginx/modules-enabled/50-mod-http-passenger.conf ]; then sudo ln -s /usr/share/nginx/modules-available/mod-http-passenger.load /etc/nginx/modules-enabled/50-mod-http-passenger.conf ; fi
$ sudo ls /etc/nginx/conf.d/mod-http-passenger.conf
$ sudo service nginx restart

Check installation

$ sudo /usr/bin/passenger-config validate-install

Configuring Nginx and Passenger

Get current path from ruby interpreter

$ passenger-config about ruby-command

Save the path that the command returns

Ex: passenger_ruby /home/ubuntu/.rvm/gems/ruby-2.5.0@hospedin-pms-6/wrappers/ruby

Remove nginx default site

$ sudo rm /etc/nginx/sites-enabled/default

Create new config site to application

$ sudo nano /etc/nginx/sites-enabled/hospedin-pms.conf

Example here

If you testing running production from public ip, make sure to change URL_TEST_CONFIG variable from .env

Compile assets, run migrations and restart nginx

$ bundle exec rake assets:precompile db:migrate RAILS_ENV=production
$ sudo service nginx restart
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment