Knowledgebase

How to Install Invoice Ninja on CentOS Print

  • 0

##Introduction

Invoice Ninja is a free and open source web-bases application software that can be used for invoicing, payments, time tracking and many more. It is 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 live invoice as PDF file.

In this tutorial, I will explain you how to install Invoice Ninja on CentOS 7 server.

##Prerequisites

  • A CentOS 7 x64 instance with 2GB RAM installed.
  • A sudo user.

##Step 1: Update the system

Before installing any packages on a CentOS 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 yum install epel-release -y
sudo yum update -y
sudo shutdown -r now

##Step 2: Install LEMP Server.

Before starting, you will need to install LEMP (Nginx, MariaDB and PHP) in your server.

First, install Nginx and MariaDB with the following command:

sudo yum install nginx mariadb-server -y

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

sudo systemctl start nginx
sudo systemctl enable nginx
sudo systemctl start mariadb
sudo systemctl enable mariadb

Next, you will need PHP7 and PHP7.0-FPM for the Invoice Ninja installation.

First, add the PHP7.0 repository to the system with the following command:

sudo rpm -Uvh https://mirror.webtatic.com/yum/el7/webtatic-release.rpm

Next, install PHP7.0-FPM and other required PHP extensions with the following command:

sudo 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 -y

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

sudo nano /etc/php.ini

Change the following line:

cgi.fix_pathinfo=0

Save and close the file.

##Step 3: Configure Database

By default, MariaDB installation is not secured so you will need to secure it first. You can do this by running mysql_secure_installation script:

sudo mysql_secure_installation

Answer all the questions as shown below:

Set root password? [Y/n] Y
New password:
Re-enter new password:
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

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

mysql -u root -p

Enter your root password and press enter, you will see the MySQL shell:

Next, 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

Next, you will need to configure PHP-FPM pool for Nginx user:

sudo 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 and close the file when you are finished.

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

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

Finally, start PHP7.0-FPM service and add it to start at boot time:

sudo systemctl start php-fpm
systemctl enable php-fpm

##Step 5: Download and Configure Invoice Ninja

You can download the latest stable version of the 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 Dependency Manager for PHP (composer). You can iinstall it with the following command:

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

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

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

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

sudo mv .env.example .env
sudo nano .env

Change the lines as shown below:

DB_DATABASE=ninja_db
DB_USERNAME=ninja
DB_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 nginx:nginx /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

Next, give proper permission to the certificate file:

sudo chmod 600 /etc/nginx/cert/*

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

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

Add the following lines:

server {
    listen  80;
    server_name 192.168.15.23;
    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 and 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 service through firewalld. Run the commands below to open the ports:

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

Finally, Open your web browser and type the URL https://192.168.15.23, then complete the required steps to finish the installation.

Congratulations! we have successfully installed Invoice Ninja with Nginx and MariaDB on CentOS 7 server.

##Introduction Invoice Ninja is a free and open source web-bases application software that can be used for invoicing, payments, time tracking and many more. It is 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 live invoice as PDF file. In this tutorial, I will explain you how to install Invoice Ninja on CentOS 7 server. ##Prerequisites A CentOS 7 x64 instance with 2GB RAM installed. A sudo user. ##Step 1: Update the system Before installing any packages on a CentOS 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 yum install epel-release -y sudo yum update -y sudo shutdown -r now ##Step 2: Install LEMP Server. Before starting, you will need to install LEMP (Nginx, MariaDB and PHP) in your server. First, install Nginx and MariaDB with the following command: sudo yum install nginx mariadb-server -y Once the installation is complete, start Nginx and MariaDB service and enable them to start on boot: sudo systemctl start nginx sudo systemctl enable nginx sudo systemctl start mariadb sudo systemctl enable mariadb Next, you will need PHP7 and PHP7.0-FPM for the Invoice Ninja installation. First, add the PHP7.0 repository to the system with the following command: sudo rpm -Uvh https://mirror.webtatic.com/yum/el7/webtatic-release.rpm Next, install PHP7.0-FPM and other required PHP extensions with the following command: sudo 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 -y Once the installation is finished, you will need to modify the php.ini configuration file: sudo nano /etc/php.ini Change the following line: cgi.fix_pathinfo=0 Save and close the file. ##Step 3: Configure Database By default, MariaDB installation is not secured so you will need to secure it first. You can do this by running mysql_secure_installation script: sudo mysql_secure_installation Answer all the questions as shown below: Set root password? [Y/n] Y New password: Re-enter new password: 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 When all is done, connect with MySQL shell with the following command: mysql -u root -p Enter your root password and press enter, you will see the MySQL shell: Next, 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 Next, you will need to configure PHP-FPM pool for Nginx user: sudo 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 and close the file when you are finished. Next, you will need to create a new directory for PHP session and socket file: sudo mkdir -p /var/lib/php/session sudo mkdir -p /var/run/php/ sudo chown -R nginx:nginx /var/lib/php/session/ sudo chown -R nginx:nginx /var/run/php/ Finally, start PHP7.0-FPM service and add it to start at boot time: sudo systemctl start php-fpm systemctl enable php-fpm ##Step 5: Download and Configure Invoice Ninja You can download the latest stable version of the 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 Dependency Manager for PHP (composer). You can iinstall it with the following command: curl -sS https://getcomposer.org/installer | sudo php -- --install-dir=/usr/bin --filename=composer Next, install all the Invoice Ninja dependencies using composer command as shown below: cd /var/www/html/ninja sudo composer install --no-dev -o Once the installation is done, rename the .env file and make some changes: sudo mv .env.example .env sudo nano .env Change the lines as shown below: DB_DATABASE=ninja_db DB_USERNAME=ninja DB_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 nginx:nginx /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 Next, give proper permission to the certificate file: sudo chmod 600 /etc/nginx/cert/* Next, create a new virtual host configuration file inside /etc/nginx/ directory: sudo nano /etc/nginx/conf.d/ninja.conf Add the following lines: server { listen 80; server_name 192.168.15.23; 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 and 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 service through firewalld. Run the commands below to open the ports: sudo firewall-cmd --permanent --add-service=http sudo firewall-cmd --permanent --add-service=https sudo firewall-cmd --reload Finally, Open your web browser and type the URL https://192.168.15.23, then complete the required steps to finish the installation. Congratulations! we have successfully installed Invoice Ninja with Nginx and MariaDB on CentOS 7 server.

Was this answer helpful?
Back

Powered by WHMCompleteSolution