How to Install Invoice Ninja on CentOS

Invoice Ninja is a popular open source application for invoicing, tracking time and accepting payments. In this tutorial, we’ll show you how to and use Invoice Ninja on a CentOS . But first:

Invoice Ninja’s features

We’ll quote Invoice Ninja themselves with their list of features:

  • Create work tasks & track time
  • Create invoices online in seconds
  • Email invoices & get paid online
  • Mobile responsive design
  • Integrate 45+ payment gateways
  • 10 fresh invoice template designs
  • View live invoice .PDF creation
  • Add your company logo to invoices
  • Quotations convert to invoices
  • Auto-billing & recurring invoices
  • Multiple tax settings
  • Multiple currencies supported
  • Client Portal to View Invoices
  • Alerts when invoices are paid
  • Set invoice payment due dates
  • Import expenses & vendors

The best part: it’s all free and open source! Although they do have a hosted version, it’s understandable that you’d want to self-host this app. And we have the perfect tutorial for you – how to install and self-host Invoice Ninja on CentOS 7.

Invoice Ninja installation instructions

We’ll install Invoice Ninja on a simple LEMP (, , MariaDB, PHP 7) stack on a CentOS 7 VPS.

Here are Invoice Ninja’s requirements:

  • A server running Centos 7.x
  • PHP 5.5.9 or higher (we’ll use PHP 7 in this tutorial)
  • MySQL/MariaDB (we’ll use MariaDB)
  • /Nginx (we’ll use Nginx)
  • Mcrypt PHP extension
  • A root (sudo) user. All the commands in our tutorial will be executed by a root user. If you don’t use a root user, append ‘sudo’ on each command.

So let’s start.

Update your system and install necessary packages

Always start by updating your system. To update your CentOS, run:


Next, install the epel-release for CentOS 7:

yum repo-pkgs extras install epel-release

We’ll also need the remi and webtatic repositories, to add them, run these 2 commands:

rpm -Uvh

After all the repositories are installed, we need to update the package cache again:

yum update

Now, we’re going to install some tools that we’ll soon need:

yum install wget unzip openssl

We are done with the prerequisites. Let’s move on.

Install Nginx

To install Nginx on CentOS, just run the following command:

yum install nginx

We’ll configure Nginx later on. That’s it for now.

Install and configure MariaDB

We obviously need a for Invoice Ninja. We’re going to use MariaDB, but you might want to use MySQL. The instructions are pretty much the same.

First, install mariadb:

yum install mariadb mariadb-server

Next, enable MariaDB to start automatically on startup:

systemctl enable mariadb

And now start MariaDB:

systemctl start mariadb

MariaDB isn’t properly configured and secured yet, so run this script:


Follow the steps on the interactive CLI interface to properly configure MariaDB.

After you are done, move on to creating an actual database and user for your Invoice Ninja install.

First, login:

mysql -u root -p

Enter your and then enter the following commands (update them according to your needs – change username, etc.):

GRANT ALL ON thrninja.* to 'ninja'@'localhost' identified by 'YourStrongPassword';

We are done with the database. Moving on…

Install and configure PHP 7 ( see more How to install PHP 7.x on CentOS 7.x x64 )

Since Invoice Ninja is built with PHP/Laravel, we’ll need to install PHP 7 and all other necessary modules:

yum install php72 php72-php-fpm php72-php-gd php72-php-curl php72-php-mcrypt php72-php-cli php72-php-gmp php72-php-mbstring php72-php-zip php72-php-xml php72-php-pdo php72-php-memcached php72-php-mysqli

By default PHP version in CentOS 7 is version 5. So, since we won’t use both PHP 5 and PHP 7

Next, we need to create a user account that will be associated with our Invoice Ninja install:

useradd ninja

We’ll configure the php-fpm module to run as the user ‘ninja’. To do that, create a new file ‘ninja.conf’ using vi:

vi /etc/opt/remi/php72/php-fpm.d/ninja.conf

Add the following lines to the file and save it:

user = ninja
group = ninja
listen = /var/run/php72-fpm-ninja.sock
listen.owner = ninja = ninja
listen.mode = 0666
pm = ondemand
pm.max_children = 5
pm.process_idle_timeout = 10s;
pm.max_requests = 200
chdir = /

Installing and configuring an SSL

You’re dealing with invoices, so it’s expected that you use an SSL certificate. You can use Let’s Encrypt too.

We’ll create the SSL certificate under /etc/nginx/ssl. Let’s create that directory and navigate to it:

mkdir -p /etc/nginx/ssl && cd /etc/nginx/ssl

And run the following commands to generate the SSL cert with openssl:

openssl genrsa -des3 -passout pass:x -out ininja.pass.key 2048
openssl rsa -passin pass:x -in ininja.pass.key -out ininja.key
rm ininja.pass.key
openssl req -new -key ininja.key -out ininja.csr
openssl x509 -req -days 365 -in ininja.csr -signkey ininja.key -out ininja.crt

We’re done with the SSL for now. If you’re using Invoice Ninja for your production site, then you are free to use a different SSL.

Configure Nginx

We’ll need to add all the necessary Nginx rules for our SSL, redirects, root directories, domain etc.

Create and open an nginx configuration file:

vi /etc/nginx/conf.d/thrninja.conf

Add the following lines to the file and save it:

server {
    listen      443 default;

    ssl on;
    ssl_certificate     /etc/nginx/ssl/ininja.crt;
    ssl_certificate_key /etc/nginx/ssl/ininja.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/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_log  /var/log/nginx/ininja.access.log;
    error_log   /var/log/nginx/ininja.error.log;

    sendfile off;

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

server {
    listen      80;

    add_header Strict-Transport-Security max-age=2592000;
    rewrite ^ https://$server_name$request_uri? permanent;

Change ‘’ with your own domain. This configuration assumes that you’ll use https without www. You may need to edit the configuration if you have a different setup.

Install composer

Now we have to install composer for installing the web dependencies of Invoice Ninja. To install composer, run the following commands:

cd $HOME
curl -sS | php
mv composer.phar /usr/bin/composer
cd $HOME

Download, install and configure Invoice Ninja

Now, for the main part of our tutorial. First, download the self-hosted version of Invoice Ninja from their official website. At the moment of writing this tutorial, it’s v4.4.3:


Next, create a directory that we’ll use as the webroot of our Invoice Ninja:

mkdir -p /var/www

Now extract the zip file you previously downloaded to our new directory:

unzip -d /var/www

Next, we need to navigate to the Invoice Ninja webroot and install the dependencies using composer:

cd /var/www/ninja
composer install --no-dev -o

Now we have to configure Invoice Ninja to use our MariaDB ‘thrninja’ database. To do that, run the following command:

cp -v .env.example .env

Open the database configuration file:

vi config/database.php

and edit the following lines:

'mysql' => [
            'driver'    => 'mysql',
            'host'      => env('DB_HOST', 'localhost'),
            'database'  => env('DB_DATABASE', 'thrninja'),
            'username'  => env('DB_USERNAME', 'ninja'),
            'password'  => env('DB_PASSWORD', 'YourStrongPassword'),
            'charset'   => 'utf8',
            'collation' => 'utf8_unicode_ci',
            'prefix'    => '',
            'strict'    => env('DB_STRICT', false),

Next, we need to create the database tables for Invoice Ninja. To do that, run the following ‘php artisan’ commands one by one and answer [yes] to the prompts:

php artisan migrate
php artisan db:seed
php artisan key:generate

Some finishing touches

We’re almost done.

Change the directory permission to the user we’ve created earlier. To do that, run the following command:

chown -Rfv ninja:ninja /var/www/ninja

Next, enable php-fpm and nginx to automatically start on boot:

systemctl enable php72-php-fpm
systemctl enable nginx

Disable with the following command:

setenforce 0

You won’t need it for Invoice Ninja and this setup.

And finally, start php-fpm and nginx:

systemctl start php72-php-fpm
systemctl start nginx

And that’s it, you are done! Now you can navigate to (the domain you used) and finish the Invoice Ninja setup via the web GUI. You should get something similar to the following:

Print Friendly, PDF & Email



Bài viết liên quan

Để lại lời nhắn