How to Install InvoiceNinja on Ubuntu 22.04 Server with Apache/Nginx

This tutorial will be showing you how to install InvoiceNinja on Ubuntu 22.04 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 Ubuntu 22.04 Server

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, so you can get rid of third-party time trackers like
  • Organize and plan your client 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 an Ubuntu 22.04 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.

InvoiceNinja is written in PHP and relies on MySQL/MariaDB database server. So you need to set up a LAMP stack or LEMP stack before installing InvoiceNinja.

And 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 Ubuntu 22.04 Server

Login to your Ubuntu 22.04 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

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

Ubuntu 22.04 ships with PHP8.1, which is compatible with InvoiceNinja. Run the following commands to install PHP modules required or recommended by InvoiceNinja.

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

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

sudo systemctl restart apache2

If these modules are not installed, you will see the following error after login.

Whoops, looks like something went wrong.

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.1 /var/www/invoiceninja/artisan key:generate

And migrate the database.

sudo php8.1 /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, 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, 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.1-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 Ubuntu 22.04 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 are stuck in a setup loop or 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/.env
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.1 /var/www/invoiceninja/artisan ninja:send-recurring > /dev/null
0 8 * * * /usr/bin/php8.1 /var/www/invoiceninja/artisan ninja:send-reminders > /dev/null
* * * * * /usr/bin/php8.1 /var/www/invoiceninja/artisan schedule:run >> /dev/null 2>&1

Save and close the file.  Run the following command to test if the Cron jobs will execute without errors.

sudo /usr/bin/php8.1 /var/www/invoiceninja/artisan schedule:run

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, which is suitable for SMTP servers that require authentication.

MAIL_USERNAME="[email protected]"
MAIL_FROM_ADDRESS="[email protected]"

If InvoiceNinja is installed on your mail server or you have set up SMTP relay with Sendinblue, then you should use the following parameters.

MAIL_FROM_ADDRESS="[email protected]"

Save and close the file. Then clear the cache.

sudo -u www-data /usr/bin/php8.1 /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.

How to Migrate From V4 to V5

  • First, go to V4 settings -> Import & Export. Export your clients, invoices, payments, etc as individual CSV file.
  • Then install V5. Go to V5 settings -> Import & Export. Import the v4 CSV files.

Manage Invoices on Mobile Phone

InvoiceNinja has mobile apps for android and iOS, so you can manage your invoices on the go.


I hope this tutorial helped you install Invoice Ninja on Ubuntu 22.04 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: 4 Average: 4.8]

14 Responses to “How to Install InvoiceNinja on Ubuntu 22.04 Server with Apache/Nginx

  • Mysterion
    2 years ago

    Thanks for the detailed guide:)

  • Thanks for this – I got there in the end.
    Do I need to install a mail server as well or is that optional?

  • I guess this version of Invoice Ninja cannot support additional modules as it doesn’t use the contain the Composer portions, right?

  • Thank you so much!

    I rarely get Nginx working when I use these kind of directions but I got it working the first time around.

    You are the best. I’ll buy you a cup of coffee after I have closed my first sale.

    2 years ago

    Hi XIao, please update:
    Purchase a ONE YEAR white label license for $30 to remove the Invoice Ninja branding from the invoice and client portal.

    Now $30 for remove label inovice ninja branding.

    Yesterday, I have making donation for you. $10
    Thank you

    • Xiao Guoan (Admin)
      2 years ago

      Yes. The white label license is now $30 per year. And thanks for your donation.

  • hi
    I followed your instructions (including installing LAMP Stack on 22.04) and everything went well right till the end.
    I installed a self-assigned ssl certificate.
    I tested the database connection and email test. both work okay.

    • Xiao Guoan (Admin)
      2 years ago

      I would never use a self-signed certificate for an invoicing application, because Web browsers will tell visitors the web page is insecure, and do you expect visitors to pay you on an insecure web page?

      InvoicingNinja is supposed to run on a server with a real domain name and valid SSL certificate.

      • we are not using the server for external use. simply just using it for internal company invoicing and we will not be using any remote login from outside our network.

  • ¡Hi all!

    Just in case someone have had the same issue. If you did well installing your mail server with Linuxbabe tutorials, then you maybe find that using DRIVER: SMTP and ENCRYPTION:TLS , it won’t work. You just have to change DRIVER:SENDMAIL, that’s it. I didn’t probe the other options, but that worked to me.

    • Xiao Guoan (Admin)
      2 years ago

      Actually I just did a fresh install InvoiceNinja on a new server, and the SMTP driver works without any problem.

      When using your own email server, there are two drivers to choose from: SMTP and Sendmail.

      • Choose SMTP if your mail server and Invoice Ninja runs on two different hosts.
      • Choose Sendmail if your mail server and Invoice Ninja runs on the same host.

      If you choose SMTP, use settings like below.

      • host: port: 587 Encryption: STARTTLS. And enter your username and password.

      If you choose Sendmail, use settings like below.

      • host: port: 25 Encryption: none. You don’t need to enter username or password.
  • John Eggleston
    1 year ago

    May want to add that once done go to “/etc/apache2/sites-available”
    and login to all the .conf files and make sure that the “DocumentRoot” points to the “/var/www/invoiceninja/public” location so that https works for them.. or it will just show the apache load page.. after the setup of invoice Ninja..

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