Invoice Ninja is a popular open source application for invoicing, tracking time and accepting payments. In this tutorial, we’ll show you how to install and use Invoice Ninja on a CentOS server. 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 & setup 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 (Linux, Nginx, MariaDB, PHP 7) stack on a CentOS 7 VPS.
Here are Invoice Ninja’s requirements:
- A server. You can use a cheap unmanaged one or a cheap managed one. If you get a Managed server then you can contact your support team and they will most likely install Invoice Ninja for you.
- Alternatively, you can host it on a Shared hosting account, in which case you can just use Softaculous and install it with a single click. Our recommendation is A2 Hosting, they have Softaculous and an amazing support team.
- PHP 5.5.9 or higher (we’ll use PHP 7 in this tutorial)
- MySQL/MariaDB (we’ll use MariaDB)
- Apache/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:
yum update
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 http://rpms.famillecollet.com/enterprise/remi-release-7.rpm
rpm -Uvh https://mirror.webtatic.com/yum/el7/webtatic-release.rpm
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 nano 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 database 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:
mysql_secure_installation
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 password and then enter the following commands (update them according to your needs – change username, password etc.):
CREATE DATABASE thrninja;
GRANT ALL ON thrninja.* to 'ninja'@'localhost' identified by 'YourStrongPassword';
FLUSH PRIVILEGES;
exit;
We are done with the database. Moving on…
Install and configure PHP 7
Since Invoice Ninja is built with PHP/Laravel, we’ll need to install PHP 7 and all other necessary modules:
yum install php71 php71-php-fpm php71-php-gd php71-php-curl php71-php-mcrypt php71-php-cli php71-php-gmp php71-php-mbstring php71-php-zip php71-php-xml php71-php-pdo php71-php-memcached php71-php-mysqli
By default PHP version in CentOS 7 is version 5. So, since we won’t use both PHP 5 and PHP 7, we’ll create a symbolic link:
ln -s /usr/bin/php71 /usr/bin/php
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 nano:
nano /etc/opt/remi/php71/php-fpm.d/ninja.conf
Add the following lines to the file and save it:
[ninja] user = ninja group = ninja listen = /var/run/php71-fpm-ninja.sock listen.owner = ninja listen.group = 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:
nano /etc/nginx/conf.d/thrninja.conf
Add the following lines to the file and save it:
server {    listen     443 default;    server_name examle.com www.example.com;    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/php71-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;    server_name example.com www.example.com;    add_header Strict-Transport-Security max-age=2592000;    rewrite ^ https://$server_name$request_uri? permanent; }
Change ‘example.com’ 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.
Stuck somewhere? Need some help? Need a custom Nginx config?
Contact our support team and we’ll install, configure and optimize Invoice Ninja on your server, with a stack of your choice!
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 https://getcomposer.org/installer | 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 v3.0.5:
wget https://download.invoiceninja.com/ninja-v3.0.5.zip
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 ninja-v3.0.5.zip
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:
nano 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
Stuck somewhere? Need some help? Installing Invoice Ninja seems too complicated?
Contact our support team and we’ll install, configure and optimize Invoice Ninja on your server, with a stack of your choice!
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 php71-php-fpm
systemctl enable nginx
Disable SELinux 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 php71-php-fpm
systemctl start nginx
And that’s it, you are done! Now you can navigate to https://example.com (the domain you used) and finish the Invoice Ninja setup via the web GUI. You should get something similar to the following:
5 thoughts on “How to Install Invoice Ninja on CentOS”
Great arcticle. How do I have to change the nginx.conf to put invoiceninja in a subdirectory instead the root. Want to reach the ninja on https://invoice.example.com or https://example.com/invoice because something other is using the root. Let’s say the company’s website or so.
Over all, you helped me a lot.
You just basically need to edit the server name in your Nginx conf. The conf above is for a subdomain invoice.example.com
I haven’t tested this conf myself, but you can google many other subdomain/subfolder nginx confs and you can update them to for invoiceninja
This is a great post, thank you for putting it together. I used it to install Invoice Ninja on my CentOS 7 VPS and everything seems to be working great. However I did see some “access denied” errors when I tried executing “php artisan migrate” and “php artisan db:seed” commands. Is that normal or does that mean that something didn’t go right? Like I said before I was able to install Invoice Ninja despite those errors and everything seems to be working without any issues.
Ran into a problem running ‘php artisan migrate’. I had to edit the .env file and input the database configuration info there as well. After that, worked like a charm 🙂
Hello , i cant create this nano /etc/opt/remi/php71/php-fpm.d/ninja.conf , as it says directory not exist?