How to Update InvoiceNinja v.5 on VM/bare metal

Hello.

I’ve been successfully using a self-hosted version of InvoiceNinja for my own business for about one year now and it’s been brilliant. The one caveat to that has been updates. Until now, every time I attempted to update either via web UI or on the command line, the process would fail horribly with 500 errors or 503 errors and several other web errors. After extensive searching and experimenting, I finally have the process set and it has successfully worked multiple times now.

Similarly to how I found this guide helpful, I thought I might share this and hopefully help a few others as well. This process only takes a few minutes (depending on the size of installation).

Base assumptions. All steps below assume you have sudo access via SSH. My installation is in production and is directly installed inside a VM (i.e. NO DOCKER) with nothing else installed, using Ubuntu 22.04, nginx, and mariadb; using the invoiceninja.zip file method of installation. These directions should work for CentOS, Fedora (I previously had it installed in Fedora), etc.; just use your relevant commands to do so. I have my installation located in /var/www/invoiceninja; however, you should use the path to wherever you have your instance installed, as locations may vary depending on which directions you followed and if you are using Apache2 or Nginx and other factors.

InvoiceNinja VM Update

Backup Database

  • sudo mysqldump -u root ninjadb > ninjadb.(date).sql
    • replace (date) with the current date. Ex: ninjadb.19.02.2024.sql
    • make sure you use the correct name for your active database, mine is ninjadb, yours may be different. The backup will fail without the correct db name.
    • Over time, you may wish to delete or move older versions of the back up and only keep the most recent one or two, as they can be large and take up lots of valuable space on the server.

Backup Web Files

  • sudo tar -cpzvf invoiceninja.(date).tar.gz /path/to/invoiceninja/
    • replace (date) with the current date. Ex: invoiceninja.19.02.2024.tar.gz
    • Similarly to above, over time, you may wish to delete or move older versions of the back up and only keep the most recent one or two, as they can be large and take up lots of valuable space on the server.

Download & Install Update

  • cd /path/to/invoiceninja
  • sudo wget https://github.com/invoiceninja/invoiceninja/releases/download/v5.9.6/invoiceninja.tar
    • (select and copy the link for the tarball of the latest release from Github - that is the latest as of writing this guide. You could also download the react only version instead of the full version with Flutter.)
  • sudo tar -xf invoiceninja.tar
  • delete zip file: sudo rm /path/to/invoiceninja/invoiceninja.tar

Update ownership

  • sudo chown www-data:www-data /path/to/invoiceninja -R

Install Update

  • sudo -u www-data composer install

Migrate

  • sudo -u www-data php artisan migrate
    • Application in production. Are you sure you want to run this command?
      • Yes

Optimize

  • sudo -u www-data php artisan optimize

FINISHED! Login to your updated system.

I hope this helps someone as I had not previously found any clear documentation on how to manually update my installation.

Edits: Various clarifications on assumptions.

Edit 2: Updated to reflect that as of 5.9.2, the ZIP file is no longer available and only tarballs are used.

4 Likes

This is great, thanks for sharing!

1 Like

I’ve updated the instructions due to the change from zip files to tarballs.

2 Likes

I us the backup sql using a daily cron job and the date +%A as well but I use:

FILELOCATION="/opt/sql-backups"
mkdir $FILELOCATION

#keep a weeks worth of invoice backups 
/usr/bin/mysqldump --add-drop-table --user=root --password=password ninjadb  >  $FILELOCATION/ninja-$(date +%A).sql

This gives you a weeks worth of backup and it automatically overwrites the older backups like this:

-rw-r--r-- 1 root   root      242225 Jun 28 23:15 ninja-Friday.sql
-rw-r--r-- 1 root   root      242225 Jul  1 05:15 ninja-Monday.sql
-rw-r--r-- 1 root   root      242225 Jun 29 23:15 ninja-Saturday.sql
-rw-r--r-- 1 root   root      242225 Jun 30 23:15 ninja-Sunday.sql
-rw-r--r-- 1 root   root      242225 Jun 27 23:15 ninja-Thursday.sql
-rw-r--r-- 1 root   root      242225 Jun 25 23:15 ninja-Tuesday.sql
-rw-r--r-- 1 root   root      242225 Jun 26 23:15 ninja-Wednesday.sql

1 Like

Nice. Thanks for sharing. Great idea.

I’ve got a script for you. It takes all the bells and whistles from you and helps you to focus on other things. It’s written from scratch and isn’t just a one-liner.

GitHub
Backup & Update - Invoice Ninja

Official Thread
https://forum.invoiceninja.com/t/invoice-ninja-management-script/16570

:green_heart:

1 Like

Thanks for sharing. I saw this when you posted a new topic several days ago.

1 Like

Thanks for the guide much appreciated.

When I am trying to update mine to 5.10.41, I am getting the following error after running the php artisan migration command, however my installation got updated and I can use it after that, but wondering how can I fix that so it doesn’t show up again ?

You’ll need to update the failed migration file to comment out the parts that have already run.

Thanks Hillel,

what is the migration file name so I can look at it and try to see if I can comment these lines ? After that shall I do the php artisan migrate command again?

My Inoivce Ninja now shows the update version although I had the error in the screenshot above.

It’s shown at the top of the screenshot above next to ‘FAIL’

Yes, you would then run migrate again

I tried to comment this file 2024_07_10_043241_2024_07_10_invoice_id_index_on_projects_table.php

When I commented out the invoices table section, it give error on the quotas table, I commented that well as well and it went ok with no problem after that. So I guess both tables didn’t need migration or had been migrated before some how.

Glad to hear it completed, thanks for the update!