How to Install InvoiceNinja on Debian 11 Server with Apache/Nginx

This tutorial will be showing you how to install InvoiceNinja on Debian 11 with Apache or Nginx web server. InvoiceNinja is an open source, self-hosted invoice software, a low-cost alternative to commercial online invoice platforms such as Freshbooks. InvoiceNinja provides hosted invoice service, but if you like to self host the software, you can follow the instructions below.

Install InvoiceNinja on Debian 11

InvoiceNinja Features

  • With InvoiceNinja, you can send invoices to your clients by using your own domain name and brand.
  • Manage invoicing for multiple businesses all under one account.
  • Save time by automatically billing long-term clients with recurring invoices.
  • Easily create and send beautiful proposals to your customers.
  • Attach 3rd Party Files to Invoices.
  • Create Project Tasks & Track Time.
  • Organize and plan your client’s work with a visual project management tool.
  • Allow your clients to see all their transactions with you in one glance.
  • Zapier automation allows you to transfer data between your invoicing account and popular apps including Gmail, Google Sheets, QuickBooks Online, Slack, Pipeline, MailChimp, and hundreds more.
  • Request deposits & partial payments using the same invoice again and again.
  • Use a pre-written auto-reminder email sequence to remind clients your invoice needs to be paid.
  • Receive notifications when a client views and pays your invoice.
  • And many more


To follow this tutorial, you need a Debian 11 OS running on a remote server. If you are looking for a virtual private server (VPS), I recommend Kamatera VPS, which features:

  • 30 days free trial.
  • Starts at $4/month (1GB RAM)
  • High-performance KVM-based VPS
  • 9 data centers around the world, including the United States, Canada, UK, Germany, The Netherlands, Hong Kong, and Isreal.

Follow the tutorial linked below to create your Linux VPS server at Kamatera.

You also need a domain name, so your clients can see the invoice via your domain name. I registered my domain name at NameCheap because the price is low and they give whois privacy protection free for life.

It’s very important that your server can send emails, so your clients can receive your invoice. Follow the tutorial linked below to set up SMTP relay on Ubuntu.

Now let’s install InvoiceNinja.

Step 1: Download InvoiceNinja Install Zip File on Debian 11 Server

Login to your Debian 11 server via SSH. Then run the following command to download the latest version of the InvoiceNinja zip file onto your server.


Once downloaded, extract the archive with unzip.

sudo apt install unzip

sudo mkdir -p /var/www/invoiceninja/

sudo unzip -d /var/www/invoiceninja/

The -d option specifies the target directory. InvoiceNinja web files will be extracted to /var/www/invoiceninja.

Then we need to change the owner of this directory to www-data so that the web server can write to this directory.

sudo chown www-data:www-data /var/www/invoiceninja/ -R

Step 2: Create a Database and User in MariaDB

Install MariaDB database server on Debian 11.

sudo apt install mariadb-server mariadb-client

Log into MariaDB database server with the following command.

sudo mysql

Then create a database for Invoice Ninja. This tutorial names the database invoiceninja. You can use whatever name you like.

create database invoiceninja;

Create the database user. Again, you can use your preferred name for this user. Replace your-password with your preferred password.

create user ninja@localhost identified by 'ninja_password';

Grant this user all privileges on the invoiceninja database.

grant all privileges on invoiceninja.* to ninja@localhost;

Flush privileges and exit.

flush privileges;


Step 3: Install PHP Modules

Run the following commands to install PHP modules required or recommended by InvoiceNinja.

curl -sSL | sudo bash -x

sudo apt install php-imagick php8.0 php8.0-mysql php8.0-fpm php8.0-common php8.0-bcmath php8.0-gd php8.0-curl php8.0-zip php8.0-xml php8.0-mbstring php8.0-bz2 php8.0-intl php8.0-gmp

Then restart Apache. (If you use Nginx, you don’t need to restart Nginx.)

sudo systemctl restart apache2

Step 4: Configure InvoiceNinja

Go to the InvoiceNinja web root.

cd /var/www/invoiceninja/

Copy the example .env file.

sudo cp .env.example .env

Edit this file with a command-line text editor like Nano.

sudo nano .env

Find the following line.


Change the URL to something like, so you will be able to access InvoiceNinja using this sub-domain.

Then edit the database connection details. Enter the database name, database user, and password created in step 2.


Save and close the file. Change the owner to www-data.

sudo chown www-data:www-data /var/www/invoiceninja/.env

Next, run the following command to generate a unique app key for your InvoiceNinja installation.

sudo php8.0 /var/www/invoiceninja/artisan key:generate

And initialize the database.

sudo php8.0 /var/www/invoiceninja/artisan migrate:fresh --seed

Step 5: Setting Up Web Server

We can use Apache or Nginx web server.


If you prefer Apache, run the following command to install it.

sudo apt install -y apache2 apache2-utils

Create a virtual host file for Invoice Ninja.

sudo nano /etc/apache2/sites-available/invoice-ninja.conf

Put the following text into the file. Replace the red-colored text with your actual data. Don’t forget to set A record for the domain name. (Note that the web root is set to /var/www/invoice-ninja/public/, not /var/www/invoice-ninja/)

<VirtualHost *:80>
    DocumentRoot /var/www/invoiceninja/public

    <Directory /var/www/invoiceninja/public>
       DirectoryIndex index.php
       Options +FollowSymLinks
       AllowOverride All
       Require all granted

    ErrorLog ${APACHE_LOG_DIR}/invoice-ninja.error.log
    CustomLog ${APACHE_LOG_DIR}/invoice-ninja.access.log combined


Save and close the file. Then enable this virtual host.

sudo a2ensite invoice-ninja.conf

We need to enable the rewrite module.

sudo a2enmod rewrite

Restart Apache for the changes to take effect.

sudo systemctl restart apache2

Now you can access the Invoice Ninja setup wizard page ( If you see the default Apache page instead of the setup wizard, then you need to disable the default virtual host.

sudo a2dissite 000-default.conf

And restart Apache.

Before entering any information in the setup wizard, we need to enable HTTPS.


If you prefer Nginx, run the following command to install it.

sudo apt install nginx -y

Create a invoiceninja.conf file in /etc/nginx/conf.d/ directory.

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

Put the following text into the file. Replace the red-colored text with your actual data. Don’t forget to create DNS A record for this sub-domain. (Note that the web root is set to /var/www/invoiceninja/public/, not /var/www/invoiceninja/)

server {
    listen   80;
    listen   [::]:80;

    root /var/www/invoiceninja/public/;
    index index.php index.html index.htm;
    charset utf-8;
    client_max_body_size 20M;

    location / {
        try_files $uri $uri/ /index.php?$query_string;

    if (!-e $request_filename) {
       rewrite ^(.+)$ /index.php?q= last;

    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/invoiceninja.access.log;
    error_log   /var/log/nginx/invoiceninja.error.log;

    location ~ \.php$ {
        fastcgi_split_path_info ^(.+\.php)(/.+)$;
        fastcgi_pass unix:/run/php/php8.0-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;

    sendfile off;

Save and close the file. Then test Nginx configuration.

sudo nginx -t

If the test is successful, reload Nginx for the changes to take effect.

sudo systemctl reload nginx

Now you can access the Invoice Ninja setup wizard page ( Before entering any information in the setup wizard, we need to enable HTTPS.

Step 6: Enabling HTTPS

To encrypt the HTTP traffic, we can enable HTTPS by installing a free TLS certificate issued from Let’s Encrypt. Run the following command to install Let’s Encrypt client (certbot) on Debian 11 server.

sudo apt install certbot

If you use Nginx, then you also need to install the Certbot Nginx plugin.

sudo apt install python3-certbot-nginx

Next, run the following command to obtain and install TLS certificate.

sudo certbot --nginx --agree-tos --redirect --hsts --staple-ocsp --email [email protected] -d

If you use Apache, install the Certbot Apache plugin.

sudo apt install python3-certbot-apache

And run this command to obtain and install TLS certificate.

sudo certbot --apache --agree-tos --redirect --hsts --staple-ocsp --email [email protected] -d


  • --nginx: Use the nginx plugin.
  • --apache: Use the Apache plugin.
  • --agree-tos: Agree to terms of service.
  • --redirect: Force HTTPS by 301 redirect.
  • --hsts: Add the Strict-Transport-Security header to every HTTP response. Forcing browser to always use TLS for the domain. Defends against SSL/TLS Stripping.
  • --staple-ocsp: Enables OCSP Stapling. A valid OCSP response is stapled to the certificate that the server offers during TLS.

The certificate should now be obtained and automatically installed.

invoice ninja ubuntu 18.04

Step 7: Finish Installation with the Setup Wizard

Now go to to launch the web-based setup wizard. First, you need to designate an URL for your InvoiceNinja installation (

invoiceninja web-based setup wizard


Then click the Test PDF button. If it’s successful, you will then enter the database connection credentials.

invoiceninja mariadb database connection

Click the Test connection button.

Next, Enter SMTP settings to make sure it can end invoices to your clients via email. If you use the free Sendinblue SMTP relay service, then enter your Sendinblue credentials here.

invoiceninja SMTP settings


  • Driver: SMTP
  • Host:
  • Username: your sendinblue username
  • Password: your sendinblue password
  • Port: 587
  • Encryption: STARTTLS

Click the Send test email button to check if it’s working.

Finally, create an admin account.

invoiceninja admin account

After creating the admin user, you can log into InvoiceNinja.


If you encounter the 500 server error when using InvoiceNinja, please check the logs under /var/www/invocieninja/storage/logs/ directory. Most likely it’s a permission problem, which can be fixed with:

sudo chown www-data:www-data /var/www/invoiceninja/storage/framework/cache/data/ -R

Set Up Cron Jobs

We need to set up Cron jobs to send recurring invoices and email reminders. Edit the www-data user’s crontab file.

sudo -u www-data crontab -e

Add the following lines at the end of this file.

0 8 * * * /usr/bin/php8.0 /var/www/invoiceninja/artisan ninja:send-recurring > /dev/null
0 8 * * * /usr/bin/php8.0 /var/www/invoiceninja/artisan ninja:send-reminders > /dev/null
* * * * * /usr/bin/php8.0 /var/www/invoiceninja/artisan schedule:run >> /dev/null 2>&1

Save and close the file. The two Cron jobs will run at 8 AM every day. You can also manually run a job like below.

sudo /usr/bin/php8.0 /var/www/invoiceninja/artisan ninja:send-recurring

How to Change SMTP Settings

If you need to change SMTP settings, you need to edit the .env file.

sudo nano /var/www/invoiceninja/.env

Edit the following parameters.


Save and close the file. Then clear the cache.

sudo -u www-data /usr/bin/php8.0 /var/www/invoiceninja/artisan optimize

If the cache is cleared, you will see the following messages in the command output.

Configuration cache cleared!
Configuration cached successfully!
Route cache cleared!
Routes cached successfully!
Files cached successfully!

Still Can’t Send Emails?

Are you using iRedMail? iRedMail doesn’t allow you to log in as one user and send emails as another user. If you don’t like this restriction, you can disable the sender_login_mismatch checks in Postfix.

How to Upgrade Invoice Ninja

When a new version of InvoiceNinja is out, follow these steps to upgrade.

First, back up the database.

sudo mysqldump -u root invoiceninja > invoiceninja.sql

Then back up the web files.

sudo tar -cpzvf invoiceninaja.tar.gz /var/www/invoiceninja/

Next, download the InvoiceNinja zip file from Github and replace the content in /var/www/invoice-ninja/, and install the dependencies.

cd /var/www/invoice-ninja/

sudo chown www-data:www-data /var/www/invoiceninja/ -R

sudo -u www-data composer install

Remove the .env file.

sudo rm /var/www/invoiceninja/.env

Next, go to to re-run the setup wizard. The database schema will be upgraded in the process.


I hope this tutorial helped you install Invoice Ninja on Debian 11 server. As always, if you found this post useful, then subscribe to our free newsletter to get more tips and tricks. Take care 🙂

Rate this tutorial
[Total: 5 Average: 5]

Leave a Comment

  • Comments with links are moderated by admin before published.
  • Your email address will not be published.
  • Use <pre> ... </pre> HTML tag to quote the output from your terminal/console.
  • Please use the community ( for questions unrelated to this article.
  • I don't have time to answer every question. Making a donation would incentivize me to spend more time answering questions.

The maximum upload file size: 2 MB. You can upload: image. Links to YouTube, Facebook, Twitter and other services inserted in the comment text will be automatically embedded. Drop file here