Install NinjaInvoice on Ubuntu 20.04 LTS with NGINX

Invoicing is sometimes hard, and sometimes even expensive.
But there is a solution, actually many solutions, but today we will be talking about a Ninja solution :)
How to get NinjaInvoice v4 onto your own Ubuntu 20.04 LTS server.

You will need:

  • your own server
  • a fresh installation of Ubuntu 20.04 LTS
  • dedicated IP address pointing to the server
  • some spare time

Let's start!

First log in to your server using ssh (I am assuming you have already created a none root user with sudo privileges):

ssh user@ip_address


Now we need to update the system:

sudo apt update
audo apt upgrade -y


Next we will need to install all dependencies: Nginx, php7.2, mysql:

sudo apt install nginx mariadb-server -y
sudo add-apt-repository ppa:ondrej/php
sudo apt-get install php7.2-fpm php7.2-cli php7.2-common php7.2-curl php7.2-gd php7.2-mysql php7.2-xml php7.2-mbstring php7.2-dev unzip ghostscript -y
sudo apt install gcc make autoconf libc-dev pkg-config libmcrypt-dev -y
sudo pecl install mcrypt-1.0.1

Just to say, if foe some reason mcrypt will not work, you may need to add this line 'extension=mcrypt.so' on the edn of the php.ini file, but please check first

Now we need to set up the security setting in mysql and a database:

sudo mysql_secure_installation

Follow the instruction on screen to set the security level that you want.

Now, depending on if you restrict the the db to be only localhost or not, you may consider removing root password. This is not something that is advised, but if you use restrict the access to localhost and wat to have mysql root account without a password, then use this command:

sudo mysqladmin -u root -p password ''


Next we will need to create a database for the invoice system:

sudo mysql -u root -p

Commands to create a db, user and grant all required privileges:

CREATE DATABASE ninja;
GRANT ALL PRIVILEGES ON ninja.* TO 'ninja'@'localhost' IDENTIFIED BY 'strongpassword';
FLUSH PRIVILEGSE;
exit;


Now we have everything ready for Ninja, time to download the ninja and uzip (in this example I am using the /home/ninja/invoice directory as my root directory for the ninja system, you can use what every directory you want):

wget https://download.invoiceninja.com/ -O /tmp/invoice-ninja.zip
sudo unzip /tmp/invoice-ninja.zip -d /home/ninja/invoice/


Change the owner of the folder ninja:

sudo chown -R www-data: /home/ninja/invoice/ninja


Now we need to set up a config file for our domain, go to /etc/nginx/site-available and create a file; your_domain_name.conf (please adjust elements like server_name or the root directory path to fit your domain name and needs, the same goes for the php version that you installed, in my case it was php7.4):

server {
    listen 80 default_server;
    server_name your_ninja_domain.com www.your_ninja_domain.com;

    root /home/ninja/invoice/ninja/public;

    index 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_log  /var/log/nginx/your_ninja_domain.com.access.log;
    error_log   /var/log/nginx/your_ninja_domain.com.error.log;

    sendfile off;

    location ~ \.php$ {
        fastcgi_split_path_info ^(.+\.php)(/.+)$;
        fastcgi_pass unix:/run/php/php7.2-fpm.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;
    }
}


If you want to use ssl, I suggest using Let's Encrypt, instruction on there website HERE

Before we activate the new config of the domain, let's just delete the default config file:

sudo rm /etc/nginx/site-available/default

Now we need to activate the config file for our domain name:

sudo ln -s /etc/nginx/site-available/your_domain_name.conf /etc/nginx/site-enabled/your_domain_name.conf


Last step! Just go, using you web browser to the your_domain_name and follow all instructions.

Application Settings

URL: your_domain_name
HTTPS: check the box if you have SSL installed
Debug: only if you want to debug your installation

Database Connection

Driver: MySQL
Host: localhost
Database: ninja
Username: ninja
Password: your password

Email Settings

Enter your email settings.


That's it!
Enjoy!