Introduction
Invoice Ninja is a free, open-source solution for invoicing from a web server. It is ideal for ecommerce and offers invoicing, quotes, expenses, time tracking, and more features that will be useful for your project.
It is built with Laravel and Flutter and has client applications for Android, iOS, macOS, among others. It is well known among freelancers, small businesses, and startups.
You can find out more about Invoice Ninja on the application's official website.
In this tutorial, we help you install it easily. Follow the steps!
To install Invoice Ninja, use the preinstalled Ubuntu 20.04 LTS (64 Bits) image available in your control panel, using the NGINX service, PHP, and MariaDB.
Installation procedure
Update repositories and packages:
# apt update && apt upgradeInstalling dependencies:
# apt install gcc g++ make php php-{fpm,bcmath,ctype,fileinfo,json,mbstring,pdo,tokenizer,xml,curl,zip,gmp,gd,mysqli} mariadb-server mariadb-client curl git nginx vim -yDownload the composer installer:
# curl -sS https://getcomposer.org/installer -o composer-setup.phpRun the composer installer:
# php composer-setup.php --install-dir=/usr/bin --filename=composerStart and enable MariaDB:
# systemctl start mariadb# systemctl enable mariadbConfigure database security:
# mysql_secure_installationCheck the status of the installed PHP service:
# systemctl status php7.4-fpm.serviceAccess MariaDB:
# mysql -u rootCreate the database and user, and grant permissions on it:
MariaDB .. > create database ninjadb;
MariaDB .. > create user 'ninja'@'localhost' identified by 'password';
MariaDB .. > grant all privileges on ninjadb.* to 'ninja'@'localhost';
MariaDB .. > flush privileges;
MariaDB .. > quit;Create the directory for NGINX certificates as follows:
# mkdir -p /etc/nginx/certCreate a self-signed certificate:
# openssl req -new -x509 -days 365 -nodes -out /etc/nginx/cert/ninja.crt -keyout /etc/nginx/cert/ninja.keyRemove the default directory:
# rm /etc/nginx/sites-enabled/defaultCreate the configuration file for Invoice Ninja:
# vim /etc/nginx/conf.d/invoiceninja.confNow insert the following content (Replace server_name with the appropriate value):
server {
listen 443 ssl http2 default_server;
listen [::]:443 ssl http2 default_server;
server_name invoiceninja;
# Here, enter the path to your invoiceninja directory, in the public dir.
root /usr/share/nginx/invoiceninja/public;
client_max_body_size 20M;
gzip on;
gzip_types application/javascript application/x-javascript text/javascript text/plain application/xml application/json;
gzip_proxied no-cache no-store private expired auth;
gzip_min_length 1000;
index index.php index.html index.htm;
# Enter the path to your existing ssl certificate file, and certificate private key file
# If you don’t have one yet, you can configure one with openssl in the next step.
ssl_certificate "/etc/nginx/cert/ninja.crt";
ssl_certificate_key "/etc/nginx/cert/ninja.key";
ssl_session_cache shared:SSL:1m;
ssl_session_timeout 10m;
ssl_ciphers 'AES128+EECDH:AES128+EDH:!aNULL';
ssl_prefer_server_ciphers on;
ssl_protocols TLSv1.2 TLSv1.3;
charset utf-8;
# Load configuration files for the default server block.
include /etc/nginx/default.d/*.conf;
location / {
try_files $uri $uri/ /index.php?$query_string;
}
if (!-e $request_filename) {
rewrite ^(.+)$ /index.php?q= last;
}
location ~ \.php$ {
fastcgi_split_path_info ^(.+\.php)(/.+)$;
# Here we pass to php-fpm listen socket. For configuration see /etc/php-fpm.d/*.conf.
fastcgi_pass unix:/run/php/php7.4-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;
}
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;
}
server {
listen 80;
server_name invoiceninja;
add_header Strict-Transport-Security max-age=2592000;
rewrite ^ https://$server_name$request_uri? permanent;
}
Now stop Apache2:
# systemctl stop apache2Disable Apache2:
# systemctl disable apache2Start NGINX:
# systemctl start nginxEnable NGINX:
# systemctl enable nginxAccess the configured NGINX directory:
# cd /usr/share/nginxCreate the directory and access it:
# mkdir invoiceninja && cd invoiceninjaDownload the latest package as follows (Check it at https://github.com/invoiceninja/invoiceninja/releases):
# wget https://github.com/invoiceninja/invoiceninja/releases/download/v5.1.42-release/invoiceninja.zipInstall unzip:
# apt install unzipNow extract the file using unzip:
# unzip invoiceninja.zipPerform the installation using composer:
# php /usr/bin/composer install --no-devGenerate this key:
# php artisan key:generate# php artisan optimizeChange the directory's ownership and group:
# chown -R www-data:www-data /usr/share/nginx/invoiceninjaNow modify the directory permissions:
# chmod -R g+s /usr/share/nginx/invoiceninjaOpen crontab for the www-data user:
# sudo -u www-data crontab -eNow insert the following scheduled job:
* * * * * php /usr/share/nginx/invoiceninja/artisan schedule:run >> /dev/null 2>&1Install optional dependencies:
# apt install gconf-service libasound2 libatk1.0-0 libc6 libcairo2 libcups2 libdbus-1-3 libexpat1 libfontconfig1 libgcc1 libgconf-2-4 libgdk-pixbuf2.0-0 libglib2.0-0 libgtk-3-0 libnspr4 libpango-1.0-0 libpangocairo-1.0-0 libstdc++6 libx11-6 libx11-xcb1 libxcb1 libxcomposite1 libxcursor1 libxdamage1 libxext6 libxfixes3 libxi6 libxrandr2 libxrender1 libxss1 libxtst6 ca-certificates fonts-liberation libappindicator1 libnss3 lsb-release xdg-utils wgetAnd finish the configuration by accessing it from your browser to complete the installation:
Add the selected database configuration:
Fill in the details, accept the terms of use, and log in:
Perfect! You have completed the procedure and can now start using Invoice Ninja:
Remember that you can use Let's Encrypt certification instead of a self-signed certificate. You can follow this tutorial to do so: Let´s Encrypt TLS/SSL certificate: we show you how to configure it.
We hope this article has helped you. If you still have questions about this or any other issue related to your servers on Clouding, write to us at soporte@clouding.io. We're here to help! 😉