How to Install Invoice Ninja on Ubuntu 16.04

Using a Different System?

  • How to Install Invoice Ninja on CentOS 7

Are we missing a guide for your target system? Request one, or submit your own!


Introduction

Invoice Ninja is a free and open source web-based application that can be used for invoicing, payments, time tracking and much more. It is the best solution for invoicing and billing customers.
You can easily create and send invoices online in seconds. Invoice Ninja allows you to create custom invoices and show live invoices as a PDF file.

In this tutorial, I will explain how to install Invoice Ninja on Ubuntu 16.04 server.

Prerequisites

  • A Ubuntu 16.04 server instance with 2GB RAM installed.
  • A sudo user with root privileges.
  • You will need to know the main IP of your server instance. In this tutorial, I will use 192.168.0.227.

Step 1: Update the system

Before installing any packages on Ubuntu server instance, it is recommended to update the system.
Login to your server via SSH as your sudo user and run the following command:

sudo apt-get update -ysudo apt-get upgrade -ysudo shutdown -r now

Step 2: Install LEMP stack

Before starting, you will need to configure a LEMP (Nginx, MariaDB and PHP) stack on your server.

First, install Nginx and MariaDB with the following command:

sudo apt-get install nginx mariadb-server -y

Once the installation is complete, start the Nginx and MariaDB services and enable them to start on boot:

sudo systemctl start nginxsudo systemctl enable nginxsudo systemctl start mysqlsudo systemctl enable mysql

Next, you will need PHP 7 and PHP-FPM for the Invoice Ninja installation.

You can install PHP-FPM and the other required PHP extensions with the following command:

sudo apt-get install php7.0-fpm php7.0-gd php7.0-xml php7.0-mysql php7.0-zip php7.0-curl php7.0-gmp php7.0-mbstring php7.0-mcrypt

Once the installation has finished, you will need to modify the php.ini configuration file:

sudo nano /etc/php/7.0/fpm/php.ini

Change the following line:

cgi.fix_pathinfo=0

Save and close the file.

Step 3: Configure database

By default, the MariaDB installation has not been secured. You will need to secure it. You can do this by running mysql_secure_installation script.

sudo mysql_secure_installation

Answer all of the questions as shown below:

Set root password? [Y/n] YNew password:Re-enter new password:Remove anonymous users? [Y/n] YDisallow root login remotely? [Y/n] YRemove test database and access to it? [Y/n] YReload privilege tables now? [Y/n] Y

When all is done, connect using the MySQL shell with the following command:

mysql -u root -p

Enter your root password and press “enter”, you will see the MySQL (MariaDB) shell.

Create a new database and a new user for Invoice Ninja.

MariaDB [(none)]> CREATE DATABASE ninja_db;MariaDB [(none)]> GRANT ALL PRIVILEGES ON ninja_db.* TO 'ninja'@'localhost' IDENTIFIED BY 'password';MariaDB [(none)]> FLUSH PRIVILEGES;MariaDB [(none)]> /q

Step 4: Configure PHP-FPM

Configure the PHP-FPM pool for the Nginx user:

sudo nano /etc/php/7.0/fpm/pool.d/www-data.conf

Add the following lines:

[www-data]user = www-datagroup = www-datalisten = /var/run/php-fpm-www-data.socklisten.owner = www-datalisten.group = www-datalisten.mode = 0666pm = ondemandpm.max_children = 5pm.process_idle_timeout = 10spm.max_requests = 200chdir = /

Save and close the file when you are finished, then restart PHP-FPM to apply these changes.

systemctl restart php7.0-fpm

Step 5: Download and configure Invoice Ninja

You can download the latest stable version of Invoice Ninja from the GitHub repository with the following command:

cd /var/www/html/sudo git clone https://github.com/hillelcoren/invoice-ninja.git ninja

You will also need to install Composer, a dependency manager for PHP. You can install it with the following command:

curl -sS https://getcomposer.org/installer | sudo php -- --install-dir=/usr/bin --filename=composer

Next, install all of the Invoice Ninja dependencies using the composer command as shown below:

cd /var/www/html/ninjasudo composer install --no-dev -o

Once the installation is done, rename the .env file and make some changes.

sudo mv .env.example .envsudo nano .env

Change the lines as shown below:

DB_DATABASE=ninja_dbDB_USERNAME=ninjaDB_PASSWORD=password

Save the file when you are finished, then run the following command to prepare the database:

sudo php artisan migrate

You will be prompted to run the command, type “yes” and press “enter”.

Next, seed the database with records as shown below:

sudo php artisan db:seed

Type “yes” and press “enter”.

Next, change ownership of the /var/www/html/ninja directory:

sudo chown -R www-data:www-data /var/www/html/ninja/

Step 6: Configure Nginx for Invoice Ninja

Next, you will need to create an SSL certificate and create a new virtual host configuration for Invoice Ninja.

First, create a directory for SSL:

sudo mkdir -p /etc/nginx/cert/

Next, generate an SSL certificate with the following command:

sudo openssl req -new -x509 -days 365 -nodes -out /etc/nginx/cert/ninja.crt -keyout /etc/nginx/cert/ninja.key

Give proper permissions to the certificate file.

sudo chmod 600 /etc/nginx/cert/*

Create a new virtual host configuration file inside of the /etc/nginx/ directory.

sudo nano /etc/nginx/conf.d/ninja.conf

Add the following lines:

server {    listen  80;    server_name 192.168.0.227;    add_header Strict-Transport-Security max-age=2592000;    rewrite ^ https://$server_name$request_uri? permanent;}server {    listen  443 default;    server_name 192.168.0.227;    ssl on;    ssl_certificate     /etc/nginx/cert/ninja.crt;    ssl_certificate_key /etc/nginx/cert/ninja.key;    ssl_session_timeout 5m;    ssl_ciphers  'AES128+EECDH:AES128+EDH:!aNULL';    ssl_protocols  TLSv1 TLSv1.1 TLSv1.2;    ssl_prefer_server_ciphers on;    root /var/www/html/ninja/public;    index index.html index.htm index.php;    charset utf-8;    location / {    try_files $uri $uri/ /index.php?$query_string;       }    location = /favicon.ico { access_log off; log_not_found off; }    location = /robots.txt  { access_log off; log_not_found off; }    # Access and Error Log for Invoice Ninja    access_log  /var/log/nginx/ininja.access.log;    error_log   /var/log/nginx/ininja.error.log;    sendfile off;    # Handle PHP Applications    location ~ /.php$ {    fastcgi_split_path_info ^(.+/.php)(/.+)$;    fastcgi_pass unix:/var/run/php-fpm-www-data.sock;    fastcgi_index index.php;    include fastcgi_params;    fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;    fastcgi_intercept_errors off;    fastcgi_buffer_size 16k;    fastcgi_buffers 4 16k;    }    location ~ //.ht {       deny all;       }    }

Save and close the file. Then enable the virtual host with the following command.

sudo ln -s /etc/nginx/sites-available/ninja /etc/nginx/sites-enabled/

Finally, restart the Nginx web server.

sudo systemctl restart nginx

Step 7: Access Invoice Ninja

Before accessing Invoice Ninja web interface, you will need to allow HTTP and HTTPS services through the UFW firewall. Run the following commands to open these ports:

sudo ufw allow 80/tcpsudo ufw allow 443/tcp

Finally, open your web browser and access the URL https://192.168.0.227. You can then complete the required steps to finish the installation.

Congratulations! We have successfully installed Invoice Ninja with Nginx and MariaDB on Ubuntu 16.04 server.

Want to contribute?

You could earn up to $300 by adding new articles

Submit your article
Suggest an update
Request an article

No comments

Powered by Blogger.