• Get In Touch
June 7, 2017

How to Install Invoice Ninja 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

InvoiceNinja is an open source invoicing, expenses and time tracking.

Several features of InvoiceNinja:

  • Create work tasks and track time.
  • Mobile responsive design.
  • Integrate with 45+ payment gateway.
  • 10 invoice template design.
  • Add company logo to invoice.
  • View live invoice PDF creation.
  • Multiple tax setings,
  • Multiple currency support.
  • Import expenses and setup vendors.

You can learn more about InvoiceNinja by visiting InvoiceNinja website.

Objective

In this tutorial we will learn how-to install Invoice Ninja on Ubuntu 14.04. We will also install and configure its prerequisites

Prerequisites

We will install Invoice Ninja in fresh installation of Ubuntu Server 14.04. We also need these applications to be able to run Invoice Ninja:

  • Apache 2
  • MySQL 5
  • PHP >= 5.5.9
  • Invoice Ninja also require the following php libraries
    • php5-gd
    • php5-curl
    • php5-mcrypt

Update Base System

Before we install Invoice Ninja, let’s update the system to the latest update.

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

Install Apache 2

After applying latest update to our base system, Lets’s start installing Apache 2 and required libraries.

$ sudo apt-get -y install apache2 apache2-bin apache2-data apache2-mpm-prefork libaio1 libapache2-mod-php5 libapr1 libaprutil1 libdbd-mysql-perl libdbi-perl libhtml-template-perl libmysqlclient18 libterm-readkey-perl libwrap0 ssl-cert tcpd

We can check Apache 2 service status using command below:

sudo service apache2 status
 * apache2 is running

We can also check which port Apache 2 is listening on using the command below.

 sudo netstat -naptu | grep apache
tcp6       0      0 :::80                   :::*                    LISTEN      14873/apache2

Install MySQL 5.6

We will install and use MySQL 5.6 as database for Invoice Ninja.

We will use MySQL Server 5.6 since MySQL 5.6 is the most up to date version of MySQL shipped with Ubuntu 14.04 Trusty Tahr.

$ 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/c7027ac0-7e31-4da4-a9ef-3dfe937a36f3/1622588448.png” alt=”” />

Verify root password.

HP_NO_IMG/data/uploads/users/c7027ac0-7e31-4da4-a9ef-3dfe937a36f3/320459047.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 anonymous user to improve security. This will make sure people or application 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 was 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!

The last step is to reload 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 a Database for invoiceninja

Now we have a secure MySQL installation, time to create database and user for invoiceninja itself.

Login to MySQL using root credential.

$ 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 new database named invoiceninja using command below

mysql> CREATE DATABASE invoiceninja DEFAULT CHARACTER SET utf8 COLLATE utf8_general_ci;
Query OK, 1 row affected (0.00 sec)

Create user for invoiceninja

Database for invoiceninja is ready, let’s create username and password and grant privileges to invoiceninja database.

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

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

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

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

Exit from MySQL console by typing \q

mysql> \q

Install PHP 5

Last component that we have to install before we can install invoiceninja is PHP 5. We will install PHP 5 and several common PHP libraries.

$ sudo apt-get -y install php5-cli php5-common php5-json php5-mysql php5-readline

Install additional php libraries:

$ sudo apt-get -y install php5-gd php5-mcrypt php5-curl

We need to manually enable mcrypt module

$ sudo php5enmod mcrypt

Restart the Apache 2 process so the changes will be applied:

$ sudo service apache2 restart

Install invoiceninja

All prerequisites is already installed. We’re ready to install invoiceninja. The latest stable version of invoiceninja is available Invoice Ninja home page.

At the time of this writing, the latest stable version is version 3.2.0, let’s download invoiceninja compressed file using wget.

$ wget -c https://download.invoiceninja.com/ninja-v3.2.0.zip

Extract the downloaded file using unzip. If your system don’t have unzip yet, you can install unzip using command below:

$ sudo apt-get -y install unzip

Extract invoiceninja using unzip

$ unzip ninja-v3.2.0.zip

Move ninja directory to Apache directory as invoiceninja

$ sudo mv ninja /var/www/invoiceninja

Change ownership of invoiceninja directory to www-data user and group.

$ sudo chown -R www-data:www-data /var/www/invoiceninja

The invoiceninja files are ready, now let’s create Apache Virtual Host configuration to serve invoiceninja.

Configure Apache Virtual Host for http Only

Create new apache configuration file on /etc/apache2/sites-available/invoiceninja.conf with contents below.

<VirtualHost *:80>
    ServerName invoiceninja.exampleserver.xyz

    DocumentRoot /var/www/invoiceninja/public

    <Directory /var/www/invoiceninja/public>
        Options -Indexes +FollowSymLinks +MultiViews
        AllowOverride All
        Require all granted
    </Directory>

    ErrorLog ${APACHE_LOG_DIR}/invoiceninja.exampleserver.xyz-error.log
    CustomLog ${APACHE_LOG_DIR}/invoiceninja.exampleserver.xyz-access.log combined

</VirtualHost>

Don’t forget to change invoiceninja.exampleserver.xyz above with the domain name that you use for your invoiceninja installation.

Enable the site using a2ensite command.

$ sudo a2ensite invoiceninja

Reload apache2 process so it read the new virtualhost configuration:

$ sudo service apache2 reload

InvoiceNinja Setup Wizard

Open InvoiceNinja URL and we will be redirected to InvoiceNinja one page setup.

The first section is InvoiceNinja URL settings, we can enter our InvoiceNinja URL here.

HP_NO_IMG/data/uploads/users/57a9b49c-2e64-4638-a30e-f6eaf3a19c65/1020191101.png” alt=”” />

The next setting is database configuration, we can enter database name and credential we already created on previous step. We can click Test connection to see if the database credential that we enter is correct

HP_NO_IMG/data/uploads/users/57a9b49c-2e64-4638-a30e-f6eaf3a19c65/221621046.png” alt=”” />

Next is email settings, you can use your own mail server for this but I would recommend using third party email server that is more reliable like Mailgun. I will skip email settings for this tutorial.

HP_NO_IMG/data/uploads/users/57a9b49c-2e64-4638-a30e-f6eaf3a19c65/853451997.png” alt=”” />

Enter user details for InvoiceNinja. Tick I agree to the Invoice Ninja Terms of Service and click Submit

HP_NO_IMG/data/uploads/users/57a9b49c-2e64-4638-a30e-f6eaf3a19c65/856934660.png” alt=”” />

After successfuly installing Invoice Ninja the installer will redirect to Invoice Ninja Login page. We can login using credential that we setup on setup wizard.

HP_NO_IMG/data/uploads/users/57a9b49c-2e64-4638-a30e-f6eaf3a19c65/483939879.png” alt=”” />

After successfully login we will get InvoiceNinja Dashboard.

HP_NO_IMG/data/uploads/users/57a9b49c-2e64-4638-a30e-f6eaf3a19c65/1470293996.png” alt=”” />

Configure https only site for invoiceninja

A secure connection is now a requirement for web application. Last step that we will do in this tutorial is changing the connection to only use https.

We assume that you already have SSL certificate and private key.

Let’s create new apache virtual host configuration on /etc/apache2/sites-available/invoiceninja-ssl.conf with contents below. Don’t forget to change:

  • ServerName
  • SSLCertificateFile
  • SSLCertificateChainFile
  • SSLCertificateKeyFile
<VirtualHost *:80>
   ServerName invoiceninja.exampleserver.xyz
   Redirect permanent / https://invoiceninja.exampleserver.xyz/
</VirtualHost>

<VirtualHost *:443>

    ServerName invoiceninja.exampleserver.xyz

    DocumentRoot /var/www/invoiceninja/public

    <Directory /var/www/invoiceninja/public>
        Options -Indexes +FollowSymLinks +MultiViews
        AllowOverride All
        Require all granted
    </Directory>

    ErrorLog ${APACHE_LOG_DIR}/invoiceninja.exampleserver.xyz-error.log
    CustomLog ${APACHE_LOG_DIR}/invoiceninja.exampleserver.xyz-access.log combined

    SSLEngine on
    SSLCertificateFile      /etc/apache2/ssl/invoiceninja.exampleserver.xyz.crt
    SSLCertificateChainFile /etc/apache2/ssl/invoiceninja.exampleserver.xyz.crt
    SSLCertificateKeyFile   /etc/apache2/ssl/invoiceninja.exampleserver.xyz.key

    Header always set Strict-Transport-Security "max-age=15768000"

</VirtualHost>

 # intermediate configuration, tweak to your needs
SSLProtocol             all -SSLv2 -SSLv3
SSLCipherSuite          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
SSLHonorCipherOrder     on

We will also disable invoiceninja http only virtual host and enable the new virtual host config.

$ sudo a2dissite invoiceninja
$ sudo a2ensite invoiceninja-ssl

The new virtual host configuration need Apache mod_ssl and mod_headers modules. We need to enable those modules.

$ sudo a2enmod ssl
$ sudo a2enmod headers

Now, restart Apache 2 service so it will reload its configuration. We need to restart instead of reload since we enable new module.

$ sudo service apache2 restart

Summary

In this tutorial we learned how-to install InvoiceNinja on Ubuntu 14.04.

We installed all the prerequisites, created a user and database on MySQL for Invoice Ninja and also configure Apache 2 virtual hosts to be able to serve InvoiceNinja.

We also configure https settings for InvoiceNinja so we run Invoice Ninja securely.

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 […]