• Get In Touch
December 27, 2016

How to Create a Ticket Management System With Brimir on Ubuntu 14.04

Want your very own server? Get our 1GB memory, Xeon V4, 25GB SSD VPS for £10.00 / month.
Get a Cloud Server

Ticket management or helpdesk software is an important part of any business whether you offer products or services. Brimir is and open source ticket management system created by Ivaldi.

We can choose to use the Ivaldi hosted Brimir service or we can use the open source version and host it on our own server. We can download Brimir Project on Github.

Goals

This tutorial will guide you through the process of preparing the server for Brimir installation. We’ll prepare the prerequisites for Brimir installation, setting up the database, installing Brimir and setting up Nginx as reverse proxy for Brimir.

Prerequisites

  • Fresh install of Ubuntu Server 14.04. You can use any ubuntu flavors but using ubuntu server will make sure your server have minimalist ubuntu installation
  • RVM (Ruby Version Manager), we need RVM to install a recent version of Ruby since Ubuntu 14.04 Trusty Tahr is shipped with Ruby 1.9.3.
  • MySQL Server 5.6. We use MySQL for the database, there are options to use PostgreSQL and Sqlite, but we will not discuss alternative databases in this tutorial.
  • Nginx. We use Nginx as a reverse proxy for Brimir. We will setup SSL certificates and http to https redirection on Nginx. SSL connections will be terminated on Nginx. We will also serve static assets like images, css and js from Nginx. This will offload static assets serving from application to Nginx.

Update Your Base System To The Latest Version

Before we start the installation. We’ll update our base system to the latest version.

$ sudo apt-get update
$ sudo apt-get upgrade

Install RVM and Ruby

We’ll use Ruby Version Manager (RVM) to install and manage Ruby on our systems since Ubuntu Trusty only has Ruby 2.0 and we need a newer version.

Add the RVM repository gpg key.

$ sudo gpg --keyserver hkp://keys.gnupg.net --recv-keys 409B6B1796C275462A1703113804BB82D39DC0E3
gpg: keyring `/home/sumodirjo/.gnupg/secring.gpg' created
gpg: requesting key D39DC0E3 from hkp server keys.gnupg.net
gpg: /home/sumodirjo/.gnupg/trustdb.gpg: trustdb created
gpg: key D39DC0E3: public key "Michal Papis (RVM signing) <mpapis@gmail.com>" imported
gpg: no ultimately trusted keys found
gpg: Total number processed: 1
gpg:               imported: 1  (RSA: 1)

We can install RVM as a single user or multi user. We will use multi user installation in this tutorial. Using multi user installation we can manage package installation using a user that we use to administer the system and run the application using another user.

Let’s install RVM.

$ \curl -sSL https://get.rvm.io | sudo bash -s stable

Add our user to rvm group, change <username> for your username.

$ sudo usermod -aG rvm <username>

Check rvm group member by checking /etc/group file.

$ grep rvm /etc/group
rvm:x:1001:sumodirjo

Logout from the system and login again so RVM is fully loaded.

When we check the list of available rubies it shows no installed rubies yet.

$ rvm list

rvm rubies

# No rvm rubies installed yet. Try 'rvm help install'.

At the time of this writing, the latest stable Ruby version is 2.3.3, we can install Ruby 2.3.3 using the command below. This process might need some time and depend on your servers Internet connection.

$ rvm install 2.3.3

When we check the list of rubies we see ruby-2.3.3 is already installed.

$ rvm list

rvm rubies

=* ruby-2.3.3 [ x86_64 ]

# => - current
# =* - current && default
#  * - default

Add gem configuration to /etc/gemrc to disable documentation installation since we don’t need this in production.

$ echo "gem: --no-rdoc --no-ri" | sudo tee -a /etc/gemrc >> /dev/null

Install MySQL 5.6

We will install and use MySQL 5.6 as database for brimir. We will use MySQL Server 5.6

$ sudo apt-get -y install mysql-server-5.6

We need to setup MySQL root password. Please input password for MySQL root user.

HP_NO_IMG/data/uploads/users/70fed463-d441-452e-bb7e-e0e3fa684498/960832776.png” alt=”” />

Verify root password.

HP_NO_IMG/data/uploads/users/70fed463-d441-452e-bb7e-e0e3fa684498/1856530910.png” alt=”” />

Securing MySQL Installation.

We will secure MySQL installation by running mysql_secure_installation.

Enter root password that we set on installation.

$ mysql_secure_installation 
NOTE: RUNNING ALL PARTS OF THIS SCRIPT IS RECOMMENDED FOR ALL MySQL
      SERVERS IN PRODUCTION USE!  PLEASE READ EACH STEP CAREFULLY!

In order to log into MySQL to secure it, we'll need the current
password for the root user.  If you've just installed MySQL, and
you haven't set the root password yet, the password will be blank,
so you should just press enter here.

Enter current password for root (enter for none): 
OK, successfully used password, moving on...

Since we already have root password set, answer this part with n.

Setting the root password ensures that nobody can log into the MySQL
root user without the proper authorisation.

You already have a root password set, so you can safely answer 'n'.

Change the root password? [Y/n] n
 ... skipping.

Remove the anonymous user to improve security. This will make sure people or applications have correct username and password to login to MySQL. Answer with Y

By default, a MySQL installation has an anonymous user, allowing anyone
to log into MySQL without having to have a user account created for
them.  This is intended only for testing, and to make the installation
go a bit smoother.  You should remove them before moving into a
production environment.

Remove anonymous users? [Y/n] Y
 ... Success!

We also want remove root login from remote machine. Answer with Y

Normally, root should only be allowed to connect from 'localhost'.  This
ensures that someone cannot guess at the root password from the network.

Disallow root login remotely? [Y/n] Y
 ... Success!

Previously the test database created automatically by MySQL installation, but MySQL 5.6 does not create test database. We can still choose Y, it will throw error but that’s fine.

By default, MySQL comes with a database named 'test' that anyone can
access.  This is also intended only for testing, and should be removed
before moving into a production environment.

Remove test database and access to it? [Y/n] Y
 - Dropping test database...
ERROR 1008 (HY000) at line 1: Can't drop database 'test'; database doesn't exist
 ... Failed!  Not critical, keep moving...
 - Removing privileges on test database...
 ... Success!

Last step is to reload the MySQL privilege table.

Reloading the privilege tables will ensure that all changes made so far
will take effect immediately.

Reload privilege tables now? [Y/n] Y
 ... Success!




All done!  If you've completed all of the above steps, your MySQL
installation should now be secure.

Thanks for using MySQL!


Cleaning up...

Create Database for Brimir

Now we have a secure MySQL installation, it’s time to create database and user for brimir itself.

Login to MySQL using root credentials

$ mysql -u root -p
Enter password: 
Welcome to the MySQL monitor.  Commands end with ; or \g.
Your MySQL connection id is 58
Server version: 5.6.30-0ubuntu0.14.04.1 (Ubuntu)

Copyright (c) 2000, 2016, Oracle and/or its affiliates. All rights reserved.

Oracle is a registered trademark of Oracle Corporation and/or its
affiliates. Other names may be trademarks of their respective
owners.

Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.

mysql>

Create a new database named brimir using command below:

mysql> CREATE DATABASE brimir;
Query OK, 1 row affected (0.00 sec)

Create a User for Brimir

The database for brimir is ready, let’s create a username and password and grant privileges to the brimir database.

We need to run the FLUSH PRIVILEGES command so that the privileges table will be reloaded by MySQL and we can use the new credentials.

Don’t forget to change the password verysecret below with a better password.

mysql> GRANT ALL PRIVILEGES ON `brimir`.* TO 'brimir'@'localhost' IDENTIFIED BY 'verysecret';
Query OK, 0 rows affected (0.00 sec)

mysql> FLUSH PRIVILEGES;
Query OK, 0 rows affected (0.00 sec)

Exit from MySQL console by typing \q

mysql> \q

Install Nginx

We will install Nginx from the nginx.org repository instead of from ubuntu repository. The reason is that nginx.org repository provide newer version of nginx.

First let’s add the Nginx.org package signing key. We add this key so apt can verify that the packages that we download from the nginx repository are not tampered with on the way to our server.

$ wget -c -O- http://nginx.org/keys/nginx_signing.key | sudo apt-key add -

Add the nginx.org Repository

$ echo "deb http://nginx.org/packages/ubuntu/ trusty nginx" | sudo tee -a /etc/apt/sources.list.d/nginx.list > /dev/null

Update apt metadata so that it know the contents of Nginx.org repository and install Nginx.

$ sudo apt-get update
$ sudo apt-get -y install nginx

Now we have nginx installed, we can check it by checking the status of the service :

$ sudo service nginx status

Configure Nginx directory structure

The configuration directory structure created by nginx package from nginx.org repository is a little bit different with configuration of Nginx package from Ubuntu repository.

We will reconfigure the Nginx configuration directory to make it similar to Nginx configuration installed from Ubuntu repository. It is easier to enable and disable site configuration using this configuration structure.

Create two new directories named sites-available and sites-enabled with commands below:

$ sudo mkdir /etc/nginx/sites-available
$ sudo mkdir /etc/nginx/sites-enabled

open /etc/nginx/nginx.conf and find the line:

 include /etc/nginx/conf.d/*.conf;

replace with

 include /etc/nginx/sites-enabled/*.conf;

Remove contents of /etc/nginx/conf.d

$ sudo rm -f /etc/nginx/conf.d/*

Now we are ready to configure the brimir site.

Configure a HTTP Site for Brimir

Create a file at /etc/nginx/sites-available/brimir.conf with contents below. You need to change the server_name line below with the domain name that you plan to use for brimir.

upstream brimir {
    server localhost:3000;
}

server {
    listen 80;
    server_name brimir.exampleserver.xyz;

    root /var/webapp/brimir/public;

    try_files $uri/index.html $uri @brimir;

    location @brimir {
        proxy_pass http://brimir;
        proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
        proxy_set_header Host $http_host;
        proxy_redirect off;
    }

    error_page 500 502 503 504 /500.html;
    client_max_body_size 4G;
    keepalive_timeout 10;
}

Enable configuration by creating symbolic link:

$ sudo ln -sf /etc/nginx/sites-available/brimir.conf /etc/nginx/sites-enabled/brimir.conf

Now restart Nginx

$ sudo service nginx restart

We set the root directory for the site to public directory under brimir application directory. This way, nginx will directly serve static assets like css and images.

Install Additional Packages

We need to install libmysqlclient-dev and nodejs. libmysqlclient-dev is required to be able to create native mysql extension for ruby, while nodejs is needed to precompile static assets.

Let’s install these packages using command below:

$ sudo apt-get install libmysqlclient-dev nodejs

Install Brimir

At the time of this writing, the latest version of Brimir is 0.7.3. You can see the latest release of Brimir from Brimir release page. Let’s download brimir source code using wget.

$ wget -c https://github.com/ivaldi/brimir/archive/0.7.3.tar.gz

Extract brimir downloaded archive

$ tar -xzf 0.7.3.tar.gz

Create new directory to store brimir files

$ sudo mkdir /var/webapp

Move Brimir extracted directory to /var/webapp directory.

sudo mv brimir-0.7.3/ /var/webapp/brimir

Configure Brimir

We have already installed Ruby 2.3.3 above using rvm. Now we will create a gemset for brimir. A gemset is a collection of ruby gems (gems is a ruby package). Using gemset we can make sure that packages that we use for brimir will not conflict with packages used by another application.

Create gemset `brimir

$ rvm gemset create brimir

Use brimir gemset.

$ rvm gemset use brimir

Install Bundler so that we can install libraries required by Brimir.

$ gem install bundle

We will use Thin for the webserver. This webserver is not included in Brimir Gemfile so we need to add it manually to Brimir Gemfile.

Open /var/webapp/brimir/Gemfile

Find the line:

gem 'rails', '~> 4.2.0'

Below that line, add this line.

gem 'thin'

Let’s install all brimir libraries. We will exlude several groups that are not needed by our installation or not needed in production.

$ cd /var/webapp/brimir/
$ bundle install --without sqlite postgresql development test --no-deployment

Before we load the Brimir database schema, let’s change Brimir database configuration. Open config/database.yml. Find the production section and replace the database name and credential that we already created earlier.

We use mysql2 adapter and the database host is localhost.

production:
  adapter: mysql2
  host: localhost
  database: 
  username: 
  password: 

Database configuration is ready, now let’s load the Brimir database schema:

$ bin/rake db:schema:load RAILS_ENV=production

Precompile Brimir static assets:

$ bin/rake assets:precompile RAILS_ENV=production

After precompile static assets, we need to generate new key for secret_key_base. This key will be used to verify the integrity of signed cookies.

$ sed -i "s/<%= ENV\[\"SECRET_KEY_BASE\"\] %>/`bin/rake secret`/g" config/secrets.yml

Next, let’s input the first credential. We will need to use e thrails console for this

Open the rails console:

$ cd /var/webapp/brimir
$ bin/rails console production

After entering the console, use the command below to input username and password. You need to change email@domain.com and somepassword to the value that you want to use.

2.3.3 :001 > u = User.new({ email: 'email@domain.com', password: 'somepassword', password_confirmation: 'somepassword' }); u.agent = true; u.save!

Generate an RVM Wrapper for Thin

We need to generate an rvm wrapper for thin. This wrapper will be used by brimir init script to load all the necessary environment to run thin.

$ rvm wrapper 2.3.3@brimir bootup thin
Regenerating ruby-2.3.3@brimir wrappers........

Create a Brimir User

We will create user and group for to run Brimir application.

First let’s create group for brimir:

$ sudo addgroup --quiet --system brimir

Create the brimir user and add it to brimir group that we just created.

$ sudo adduser --quiet --system --ingroup brimir --no-create-home --disabled-password brimir
sudo usermod -c "Brimir" -d /var/webapp/brimir -g brimir brimir

Create Init Script and Configuration Directory for Brimir

Thin comes with an install tool to generate an init script and also thin configuration directory. We can use command below to run thin install

$ rvmsudo thin install

We need to modify the init script a little bit to use thin rvm wrapper. Open /etc/init.d/thin. Find line

DAEMON=/usr/local/rvm/gems/ruby-2.3.3/bin/thin

Replace with:

DAEMON=/usr/local/rvm/bin/bootup_thin

Create a Thin Configuration File for Brimir

Create new file /etc/thin/brimir.yml with content below:

---
user: brimir
group: brimir
pid: tmp/pids/thin.pid
timeout: 30
wait: 30
log: log/thin.log
max_conns: 1024
require: []
environment: production
max_persistent_conns: 512
servers: 1
threaded: true
no-epoll: true
daemonize: true
port: 3000
chdir: /var/webapp/brimir
tag: brimir

Brimir is ready. To start Brimir we can use command below:

$ sudo service thin start
[start] /etc/thin/brimir.yml ...
Starting server on 0.0.0.0:3000 ... 

To stop and restart brimir we can change start option above to stop and restart respectively.

We can check whether thin already run or not using combination of ps and grep

$ ps aux | grep thin
brimir   10755  4.0  8.6 286752 87988 ?        Sl   03:56   0:02 thin server (0.0.0.0:3000) [brimir]

We can also check what port thin already listening using netstat command:

$ sudo netstat -naptu | grep thin
tcp        0      0 0.0.0.0:3000            0.0.0.0:*               LISTEN      10755/thin server (

Brimir is ready, let’s open Brimir using our browser. We will be greeted with Brimir login page. We can use user that we populate earlier from rails console

HP_NO_IMG/data/uploads/users/d2adf41c-50bf-4320-971f-4eb93a09fc8c/521985506.png” alt=”” />

After logging in, we will get Brimir dashboard. Since this is our first login we will get Brimir introduction wizard.

HP_NO_IMG/data/uploads/users/d2adf41c-50bf-4320-971f-4eb93a09fc8c/1437198665.png” alt=”” />

You can start playing around with Brimir to get familiar with Brimir features.

Configure HTTPS Site for Brimir

Right now we only configure Nginx to serve http and forward application request to Brimir.

The last thing we will do in this tutorial is to enable https only site on Nginx for Brimir.
We assume that you already get ssl certificate and the private key pair. When using this configuration you need to change server_name ssl_certificate and ssl_certificate_key lines below.

Before creating the configuration file. Let’s create new folder to put ssl certificate.

$ sudo mkdir /etc/nginx/ssl

Create a new configuration file /etc/nginx/sites-available/brimir-ssl.conf with contents below:

upstream brimir {
    server localhost:3000;
}


server {
    listen 80 default_server;
    listen [::]:80 default_server;

    # Redirect all HTTP requests to HTTPS with a 301 Moved Permanently response.
    return 301 https://$host$request_uri;
}

server {
    listen 443 ssl http2;
    listen [::]:443 ssl http2;

    server_name brimir.exampleserver.xyz;
    root /var/webapp/brimir/public;

    try_files $uri/index.html $uri @brimir;

    # certs sent to the client in SERVER HELLO are concatenated in ssl_certificate
    ssl_certificate /etc/nginx/ssl/brimir.exampleserver.xyz.crt;
    ssl_certificate_key /etc/nginx/ssl/brimir.exampleserver.xyz.key;

    ssl_session_timeout 1d;
    ssl_session_cache shared:SSL:50m;
    ssl_session_tickets off;

    # intermediate configuration. tweak to your needs.
    ssl_protocols TLSv1 TLSv1.1 TLSv1.2;
    ssl_ciphers 'ECDHE-ECDSA-CHACHA20-POLY1305:ECDHE-RSA-CHACHA20-POLY1305:ECDHE-ECDSA-AES128-GCM-SHA256:ECDHE-RSA-AES128-GCM-SHA256:ECDHE-ECDSA-AES256-GCM-SHA384:ECDHE-RSA-AES256-GCM-SHA384:DHE-RSA-AES128-GCM-SHA256:DHE-RSA-AES256-GCM-SHA384:ECDHE-ECDSA-AES128-SHA256:ECDHE-RSA-AES128-SHA256:ECDHE-ECDSA-AES128-SHA:ECDHE-RSA-AES256-SHA384:ECDHE-RSA-AES128-SHA:ECDHE-ECDSA-AES256-SHA384:ECDHE-ECDSA-AES256-SHA:ECDHE-RSA-AES256-SHA:DHE-RSA-AES128-SHA256:DHE-RSA-AES128-SHA:DHE-RSA-AES256-SHA256:DHE-RSA-AES256-SHA:ECDHE-ECDSA-DES-CBC3-SHA:ECDHE-RSA-DES-CBC3-SHA:EDH-RSA-DES-CBC3-SHA:AES128-GCM-SHA256:AES256-GCM-SHA384:AES128-SHA256:AES256-SHA256:AES128-SHA:AES256-SHA:DES-CBC3-SHA:!DSS';
    ssl_prefer_server_ciphers on;

    # HSTS (ngx_http_headers_module is required) (15768000 seconds = 6 months)
    add_header Strict-Transport-Security max-age=15768000;

    location @brimir {
        proxy_pass http://brimir;
        proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
        proxy_set_header Host $http_host;
        proxy_redirect off;
    }
}

Enable the site by creating symbolic link using command below:

$ sudo ln -sf /etc/nginx/sites-available/brimir-ssl.conf /etc/nginx-sites-enabled/brimir-ssl.conf

Disable the Brimir http only site by removing symbolic link:

$ sudo rm -f /etc/nginx/sites-enabled/brimir.conf

Test Nginx configuration using the comand below:

$ sudo service nginx configtest
nginx: the configuration file /etc/nginx/nginx.conf syntax is ok
nginx: configuration file /etc/nginx/nginx.conf test is successful

If the output is different than above, Nginx will show error message and show which file and line of the configuration still not correct.

Restart Nginx using command below:

$ sudo service nginx restart

Now Brimir will be serve using HTTPS. If a user opens the site using http, it will be automatically redirected to https site.

Summary

In this tutorial we learned how-to install Brimir on Ubuntu 14.04. We also installed Ruby Version Manager(RVM), MySQL Server 5.6 and Nginx. Hopefully you can manage your support request better using Brimir.

Want your very own server? Get our 1GB memory, Xeon V4, 25GB SSD VPS for £10.00 / month.
Get a Cloud Server

Share this Article!

Related Posts

Node.js Authentication – A Complete Guide with Passport and JWT

Node.js Authentication – A Complete Guide with Passport and JWT

Truth be told, it’s difficult for a web application that doesn’t have some kind of identification, even if you don’t see it as a security measure in and of itself. The Internet is a kind of lawless land, and even on free services like Google’s, authentication ensures that abuses will be avoided or at least […]

Node.js and MongoDB: How to Connect MongoDB With Node

Node.js and MongoDB: How to Connect MongoDB With Node

MongoDB is a document-oriented NoSQL database, which was born in 2007 in California as a service to be used within a larger project, but which soon became an independent and open-source product. It stores documents in JSON, a format based on JavaScript and simpler than XML, but still with good expressiveness. It is the dominant […]

Using MySQL with Node.js: A Complete Tutorial

Using MySQL with Node.js: A Complete Tutorial

Although data persistence is almost always a fundamental element of applications, Node.js has no native integration with databases. Everything is delegated to third-party libraries to be included manually, in addition to the standard APIs. Although MongoDB and other non-relational databases are the most common choice with Node because if you need to scale an application, […]

Node.Js Vs Django: Which Is the Best for Your Project

Node.Js Vs Django: Which Is the Best for Your Project

Django and NodeJs are two powerful technologies for web development, both have great functionality, versatile applications, and a great user interface. Both are open source and can be used for free. But which one fits your project best? NodeJs is based on JavaScript, while Django is written in Python. These are two equally popular technologies […]

Nodejs Vs PHP:  Which Works Best?

Nodejs Vs PHP: Which Works Best?

Before getting into the “battle” between Node.js and PHP we need to understand why the issue is still ongoing. It all started with the increased demand for smartphone applications, their success forcing developers to adapt to new back-end technologies that could handle a multitude of simultaneous requests. JavaScript has always been identified as a client-side […]