How To Install Invoice Ninja on CentOS 7

Install Invoice Ninja on CentOS 7

In this tutorial, we will show you how to install and configuration of Invoice Ninja on your CentOS 7 server. For those of you who didn’t know, Invoice Ninja is a free and open-source web-based application software that can be used for invoicing, payments, time tracking, and many 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 your own custom invoice and show a live invoice as a PDF file.

This article assumes you have at least basic knowledge of Linux, know how to use the shell, and most importantly, you host your site on your own VPS. The installation is quite simple and assumes you are running in the root account, if not you may need to add ‘sudo’ to the commands to get root privileges. I will show you through the step by step installation of Invoice Ninja on a CentOS 7 server.

Invoice Ninja’s features

  • Create work tasks and 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 and setup vendors

Install Invoice Ninja on CentOS 7

Step 1. First, let’s start by ensuring your system is up-to-date.

yum clean all
yum -y install epel-release
yum -y update

Step 2. Install LEMP server.

A CentOS 7 LEMP stack server is required. If you do not have a LEMP installed, you can follow our guide here. Also, install the required PHP modules:

yum install install php70w-fpm php70w-cli php70w-pear php70w-gd php70w-xml php70w-curl php70w-gmp php70w-pdo php70w-mysql php70w-zip php70w-mbstring php70w-mcrypt

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

nano /etc/php.ini

Change the following line:

cgi.fix_pathinfo=0

Step 3. Configuring MariaDB for Invoice Ninja.

By default, MariaDB is not hardened. You can secure MariaDB using the mysql_secure_installation script. you should read and below each step carefully which will set a root password, remove anonymous users, disallow remote root login, and remove the test database and access to secure MariaDB:

mysql_secure_installation

Configure it like this:

- Set root password? [Y/n] y
- Remove anonymous users? [Y/n] y
- Disallow root login remotely? [Y/n] y
- Remove test database and access to it? [Y/n] y
- Reload privilege tables now? [Y/n] y

Next, we will need to log in to the MariaDB console and create a database for the Invoice Ninja. Run the following command:

mysql -u root -p

This will prompt you for a password, so enter your MariaDB root password and hit Enter. Once you are logged in to your database server you need to create a database for Invoice Ninja installation:

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.

You will need to configure PHP-FPM pool for Nginx user:

nano /etc/php-fpm.d/www.conf

Change the following lines:

user = nginx
group = nginx
listen = /var/run/php/php-fpm.sock
listen.owner = nginx
listen.group = nginx
listen.mode = 0660
env[HOSTNAME] = $HOSTNAME
env[PATH] = /usr/local/bin:/usr/bin:/bin
env[TMP] = /tmp
env[TMPDIR] = /tmp
env[TEMP] = /tmp

Save the file and exit from the text editor.

Next, you will need to create a new directory for PHP session and socket file:

mkdir -p /var/lib/php/session
mkdir -p /var/run/php/
chown -R nginx:nginx /var/lib/php/session/
chown -R nginx:nginx /var/run/php/

Next, start PHP-FPM and enable it to start at boot time using the following commands:

systemctl start php-fpm
systemctl enable php-fpm

Step 5. Installing Invoice Ninja.

The first thing to do is to go to Invoice Ninja’s download page and download the latest stable version of Invoice Ninja:

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

You need to install composer:

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

Next, install all the Invoice Ninja dependencies using composer:

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

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

mv .env.example .env
nano .env

Change the database values according to your database:

DB_DATABASE=ninja_db
DB_USERNAME=ninja
DB_PASSWORD=Y0urPa55w0rd

Save the file and exit from the text editor. Next, edit the database configuration in the config directory:

nano config/database.php

Change the following lines:

'database'  => env('DB_DATABASE', 'ninja_db'),
'username'  => env('DB_USERNAME', 'ninja'),
'password'  => env('DB_PASSWORD', 'Y0urPa55w0rd'),

Save the file and exit from the text editor and prepare the database with the following command:

php artisan migrate

You will be prompted for a run the command, type ‘yes’ and press Enter.

Next, seed the database with all records as shown below:

php artisan db:seed

Run the following command to generate the application key and note this application key:

php artisan key:generate

Next, edit the app.php file with a nano text editor:

nano config/app.php

Add the key as shown below:

'key' => env('APP_KEY', 'y0urGenerated Key'),

Save and close the file also change some folders permissions:

chown -R nginx:nginx /var/www/html/ninja/

Step 6. Configure Nginx for Invoice Ninja.

Create an SSL Certificate and create a new virtual host configuration for Invoice Ninja:

mkdir -p /etc/nginx/cert/openssl req -new -x509 -days 365 -nodes -out /etc/nginx/cert/ninja.crt -keyout /etc/nginx/cert/ninja.keychmod 600 /etc/nginx/cert/*

Next, create a new virtual host configuration file inside /etc/nginx/ directory:

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

Add the following lines:

server {
    listen  80;
    server_name idroot.us;
    add_header Strict-Transport-Security max-age=2592000;
    rewrite ^ https://$server_name$request_uri? permanent;
}

server {
    listen  443 default;
    server_name 192.168.15.23;
    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/php-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;
       }
    }

Save and close the file. Restart the Nginx service for the changes to take effects:

systemctl restart nginx

Step 7. Configure FirewallD Invoice Ninja.

Before accessing the Invoice Ninja web interface, you will need to allow HTTP and https service through firewalld:

firewall-cmd --permanent --add-service=http
firewall-cmd --permanent --add-service=https
firewall-cmd --reload

Step 8. Accessing Invoice Ninja.

Invoice Ninja will be available on HTTP port 80 by default. Open your favorite browser and navigate to http://your-domain.com/ or http://server-ip and complete the required steps to finish the installation.

Congratulations! You have successfully installed the Invoice Ninja. Thanks for using this tutorial for installing Invoice Ninja on CentOS 7 system. For additional help or useful information, we recommend you to check the official Invoice Ninja website.

VPS Manage Service Offer
If you don’t have time to do all of this stuff, or if this is not your area of expertise, we offer a service to do “VPS Manage Service Offer”, starting from $10 (Paypal payment). Please contact us to get the best deal!

Save