Install Invoice Ninja on a Debian 7 VPS

install-invoice-ninja-on-debian-7-vpsIn this tutorial we’ll see how to install Invoice Ninja on a Debian 7 (Wheezy) VPS with MariaDB, PHP-FPM and Nginx. Invoice Ninja is a free, open-source solution for invoicing and billing customers and it’s based on Laravel 4.1 framework. This guide should work on other Linux VPS

systems as well but was tested and written for Debian 7 VPS.

Login to your VPS via SSH

ssh [email protected]

Update the system and install necessary packages

[email protected]:~# sudo apt-get update && sudo apt-get -y upgrade
[email protected]:~# sudo apt-get install python-software-properties git curl openssl vim

Install MariaDB 10.0

[email protected]:~# sudo apt-key adv --recv-keys --keyserver 0xcbcb082a1bb943db
[email protected]:~# sudo add-apt-repository 'deb wheezy main'
[email protected]:~# sudo apt-get update
[email protected]:~# sudo apt-get install mariadb-server

When the installation is complete, run the following command to secure your installation:


Next, we need to create a database for our Invoice Ninja instance.

mysql -uroot -p
MariaDB [(none)]> CREATE DATABASE ininja;
MariaDB [(none)]> GRANT ALL PRIVILEGES ON ininja.* TO 'ininjauser'@'localhost' IDENTIFIED BY 'ininjauser_passwd';
MariaDB [(none)]> \q

Install and configure PHP and Nginx

The latest versions of Nginx 1.6.2 and PHP 5.6 are not available via the default Debian repositories, so we will add the Dotdeb repository. Open the /etc/apt/sources.list file and append the following lines:

[email protected]:~# sudo vim /etc/apt/sources.list
deb wheezy all
deb wheezy-php56 all

Next, fetch and install the GnuPG key:

[email protected]:~# wget -qO - | sudo apt-key add -

Update the system and install Nginx, PHP and all necessary extensions:

[email protected]:~# sudo apt-get update
[email protected]:~# sudo apt-get install nginx php5-fpm php5-cli php5-mcrypt php5-gd php5-curl
[email protected]:~# sudo php5enmod mcrypt

Install Composer

Composer is a dependency manager for PHP with which you can install packages. Composer will pull in all the required libraries and dependencies that you need for your project.

[email protected]:~# curl -sS | php
[email protected]:~# sudo mv composer.phar /usr/local/bin/composer

Install Invoice Ninja

Create a root directory for your application.

[email protected]:~# mkdir -p ~/your_ininja_site

Clone the project repository from GitHub:

[email protected]:~# git clone ~/your_ininja_site
[email protected]:~# cd  ~/your_ininja_site

Install all dependencies:

[email protected]:~# composer install --no-dev -o

Set the environment to production:

[email protected]:~# cp bootstrap/environment.default.php bootstrap/environment.php
[email protected]:~# vim bootstrap/environment.php

Open the database.php file and edit the database settings:

[email protected]:~# vim config/database.php
       'mysql' => array(
            'driver'    => 'mysql',
            'host'      => 'localhost',
            'database'  => 'ininja',
            'username'  => 'ininjauser',
            'password'  => 'ininjauser_passwd',
            'charset'   => 'utf8',
            'collation' => 'utf8_unicode_ci',
            'prefix'    => '',

Run database migrations and seed the database with sample data:

[email protected]:~# php artisan migrate
[email protected]:~# php artisan db:seed

Generate a new application key:

[email protected]:~# php artisan key:generate
[email protected]:~# vim app/config/app.php
'key' => 'iL7OD2fbvjJvIcSgalLThFaEM4gPtPNF',

Configure Nginx and PHP

Create a new PHP-FPM pool for your user:

[email protected]:~# sudo nano /etc/php5/fpm/pool.d/your_user.conf
user = your_user  
group = your_user  
listen = /var/run/php5-fpm-your_user.sock  
listen.owner = your_user = your_user  
listen.mode = 0666  
pm = ondemand  
pm.max_children = 5  
pm.process_idle_timeout = 10s;  
pm.max_requests = 200  
chdir = /  

Do not forget to change your_user with your username.

Restart PHP-FPM

[email protected]:~# sudo service php5-fpm restart

Generate SSL certificate:

[email protected]:~# sudo mkdir -p /etc/nginx/ssl
[email protected]:~# cd /etc/nginx/ssl
[email protected]:~# sudo openssl genrsa -des3 -passout pass:x -out ininja.pass.key 2048
[email protected]:~# sudo openssl rsa -passin pass:x -in ininja.pass.key -out ininja.key
[email protected]:~# sudo rm ininja.pass.key
[email protected]:~# sudo openssl req -new -key ininja.key -out ininja.csr
[email protected]:~# sudo openssl x509 -req -days 365 -in ininja.csr -signkey ininja.key -out ininja.crt

Next, create a new Nginx server block:

[email protected]:~# sudo vim /etc/nginx/sites-available/your_ininja_site
server {
    listen      443 default;
    server_name your_ininja_site;

    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 /home/your_user/your_ininja_site/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/php5-fpm-your_user.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 your_ininja_site;

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

Do not forget to change your_user with your username.

Activate the server block by creating a symbolic link and restart Nginx:

[email protected]:~# sudo ln -s /etc/nginx/sites-available/your_ininja_site /etc/nginx/sites-enabled/your_ininja_site
[email protected]:~# sudo /etc/init.d/nginx restart

That’s it. You have successfully installed Invoice Ninja on your Debian Wheezy VPS. For more information about Invoice Ninja, please refer to the Invoice Ninja website.

Of course you don’t have to do any of this if you use one of our Linux VPS Hosting services, in which case you can simply ask our expert Linux admins to setup this for you. They are available 24×7 and will take care of your request immediately.

PS. If you liked this post please share it with your friends on the social networks using the buttons on the left or simply leave a reply below. Thanks.

Install Osclass on a CentOS 7 VPS
How to install Laravel 4 with Twitter Bootstrap on Linux VPS
How to install Rukovoditel on Ubuntu 16.04
  • Ekkachai


    Author Reply

    During my setup, I ran into ” guzzle/guzzle v3.9.3 requires ext-curl * -> the requested PHP extension curl is missing from your system.” problem.

    I have to install php5-curl module. So you might want to update “sudo apt-get install nginx php5-fpm php5-cli php5-mcrypt php5-gd” to “sudo apt-get install nginx php5-fpm php5-cli php5-mcrypt php5-gd php5-curl”

    PS. Love your site btw!

    • admin


      Author Reply

      We updated the post.

      Thank you.

  • Manxam


    Author Reply

    Thanks for the writeup. There’s a few steps missing though: such as renaming “.env.default” to “.env”, installing php5-gmp (required when running composer) and php5-mysql (or one will get PDO driver not found errors when attempting php artisan migrate), and finally editing .env with the correct database settings or “php artisan” will fail attempting to connect to the db.

    • admin


      Author Reply

      Thanks for your feedback.

  • Robert Lederer

    change :

    [email protected]:~# vim app/config/database.php


    [email protected]:~# vim config/database.php

    • admin


      Author Reply

      Thanks for pointing out. The post has been updated.

  • Lorenzo


    Author Reply

    Please add the nginx config to hide “public” from the url in case invoiceninja is used inside a directory and not as a root

    thank you

    • admin


      Author Reply

      We will make a new tutorial about how to install invoiceninja with nginx in a subdirectory on a Debian 9 VPS soon.

  • Ulf


    Author Reply

    That sounds great. Can’t wait to read and hopefully follow it :)

    Thanks for all your effort you put into the article.