504: Gateway Time-out when attempting to upgrade ⛔

Version:

Heath check:

Upgrade available:

So I first attempted to upgrade through the new UI browser interface (Aka. React) but it just times out and does not generate any error.

So I ended up with using the old UI in the Windows app instead which did generate this error:
504: Gateway Time-out

- I have checked the invoice ninja log files >>> /storage/logs
Nothing that mentions the upgrade error or give any lead there of.

- Also checked our own server which we have installed Plesk CP on it… and the logs for Invoice Ninja does generate an error in the Plesk web hotel logs (Where we installed Invoice Ninja):

Not sure why this suddenly happens. :thinking:

We had in the past updated before many times flawlessly without any issues since the new UI was released so I do not understand why this update are giving us problems.

Thoughts?

Thanks in advance
Kind regards

I’ve added to nginx:

Additional nginx directives

proxy_connect_timeout 180s;
proxy_send_timeout 180s;
proxy_read_timeout 180s;
fastcgi_send_timeout 180s;
fastcgi_read_timeout 180s;

So now the update process has 3 minutes to complete.

Ran the update again and it still fails.
But this time with:
500: Internal Server Error” on the old UI.

React UI does not display any error at all except for “Something went wrong” which is not a very useful error message.

The server logs confirms this too:

There is no other indication on what goes wrong in other log files so I’m quite clueless on how to fix this. But as I mentioned before we have updated Invoice Ninja successfully throughout many years and this also includes the new React UI. So I have hard time to imagine that the error is on our side, but I could be wrong of course.

I did turn on debug mode (=true), in the .env file but that did not generate any results.

Again thankful for any thoughts on this.

Kind regards

Hi,

As a workaround you should be able to manually copy over the latest release tar.

Hi @hillel :smiley:
I hope you’re having a lovely day and thanks for your reply.

1.) Do you have any idea what is causing this issue. Never seen this issue before and we have ran numerous automated updates in the past without any issues at all.

2.) So there is no way of forcing the update, but the manual method is the way to go?

Thanks in advance.
Kind regards

If it’s a timeout you should be able to increase the time limit to resolve the issue, here’s what ChatGPT suggests:

Thanks for the detailed info and screenshots — even though they didn’t come through visually here, your descriptions were clear enough to get a good sense of what’s going on.

TL;DR:

You’re running into a 504 Gateway Timeout error when attempting to upgrade Invoice Ninja (IN) through the new UI, and falling back to the old UI (Windows app) also fails. You’ve checked /storage/logs and Plesk logs and found a timeout error but no detailed trace from the app itself. This used to work fine before.

Let’s walk through some likely causes and ideas to try:


:bulb: Potential Issues & Fixes

1. 504 Gateway Timeout = Server not responding in time

This suggests:

  • Something in the upgrade process is taking too long (long DB migrations? large queue jobs?)
  • Or it’s hanging indefinitely
  • Or the reverse proxy (Nginx/Apache behind Plesk) is timing out too quickly

Suggestions:

  • Increase timeout settings for your web server:
    • Apache: Timeout, ProxyTimeout
    • Nginx: proxy_read_timeout, fastcgi_read_timeout
  • Check Plesk’s domain-specific settings and increase those timeout values if needed

2. Run upgrade manually via CLI

This is often the most reliable way:

php artisan migrate --force
php artisan optimize
php artisan config:clear
php artisan route:clear

Also worth trying:

php artisan ninja:post-update

This will manually apply migrations and cleanup. If there’s an error here, it’ll be clearer than in the browser.


3. Check PHP-FPM / Worker Limits

If you’re using PHP-FPM (which Plesk often does), it could be:

  • Running out of memory or workers
  • Crashing silently

Things to check:

  • PHP-FPM logs (/var/log/phpX.X-fpm.log)
  • Increase pm.max_children and memory limits
  • Make sure max_execution_time is high enough (try 300)

4. Queue Worker Stuck?

If the upgrade triggers a queue job (like database seeding or cache rebuild), and your queue driver is database or redis, it may be stuck or not running.

Try:

php artisan queue:restart
php artisan queue:work

If that solves it, you may want to make sure your queue workers are auto-starting (via Supervisor or systemd).


5. Check Disk Space & Permissions

Sometimes overlooked, but:

  • Make sure there’s enough free disk space (especially /tmp, /var, or the site’s storage/)
  • Ensure proper permissions on storage/, bootstrap/cache/
chown -R www-data:www-data /path-to-invoice-ninja
chmod -R 775 /path-to-invoice-ninja/storage

(Substitute www-data if you’re using a different user like apache, pleskuser, etc.)


6. Isolate Version Issue

If it worked before and suddenly doesn’t:

  • Did the latest IN version change anything major in the upgrade process? Check their GitHub release notes
  • Could be a breaking migration or dependency issue

:test_tube: Other Ideas

  • Turn on debug in .env during upgrade to get better error trace:

    APP_DEBUG=true
    LOG_CHANNEL=stack
    
  • Check your Laravel version compatibility – sometimes newer IN releases bump their Laravel version, which could require PHP upgrades or additional dependencies


If nothing works and you’re stuck, feel free to share:

  • Your IN version before and after
  • PHP version
  • Log lines from storage/logs/laravel.log after enabling debug
  • Your .env (scrub sensitive data)

I can help review it in more depth.

Let me know how it goes!

1 Like

Thanks Hillel!
I’ll dig into it and see if anything works of the suggested.

I have already tried the command php artisan migrate --force on Invoice Ninja. It did do nothing really.

Kind regards

I’ve had this in the past.
I think max_execution_time was the general problem. Updating the PHP settings on the server allowed the app to update, but I still occasionally get the warning as my domain runs through Cloudflare which has hard-coded timeout limits.
So cloudflare sends the gateway timeout error but the app continues updating in the background.

1 Like

Well I waited a few days nd yesterday I ran the upgrade again from the old UI (The now Windows App), and suddenly it just worked out of the blue.
I have no clue to why it suddenly worked though.

Glad to hear it, thanks for the update!

1 Like

Hi @hillel :smiley:

Hmm… :thinking:

This upgrading issue is back again with a vengeance with this newest release Version: 5.11.66
(Upgrading from Version: 5.11.61)

However I did get a more informational error this time with debug on than last time where it didn’t reveal anything:

Invoiceninja.log:

[2025-04-09 19:24:33] production.INFO: Clear cache directory  
[2025-04-09 19:24:33] production.INFO: copying release file  
[2025-04-09 19:25:33] production.INFO: Download URL  
[2025-04-09 19:30:02] production.INFO: Cleaning Stale Invoices:  
[2025-04-09 19:35:18] production.INFO: Test filesystem is writable  
[2025-04-09 19:35:19] production.INFO: Clear cache directory  
[2025-04-09 19:35:19] production.INFO: copying release file  
[2025-04-09 19:36:19] production.INFO: Download URL

laravel.log:

/var/www/vhosts/some-example.domain.com/public_html/vendor/laravel/framework/src/Illuminate/Foundation/Http/Middleware/PreventRequestsDuringMaintenance.php(110): Illuminate\\Pipeline\\Pipeline->Illuminate\\Pipeline\\{closure}()
#57 /var/www/vhosts/some-example.domain.com/public_html/vendor/laravel/framework/src/Illuminate/Pipeline/Pipeline.php(209): Illuminate\\Foundation\\Http\\Middleware\\PreventRequestsDuringMaintenance->handle()
#58 /var/www/vhosts/some-example.domain.com/public_html/vendor/sentry/sentry-laravel/src/Sentry/Laravel/Tracing/Middleware.php(79): Illuminate\\Pipeline\\Pipeline->Illuminate\\Pipeline\\{closure}()
#59 /var/www/vhosts/some-example.domain.com/public_html/vendor/laravel/framework/src/Illuminate/Pipeline/Pipeline.php(209): Sentry\\Laravel\\Tracing\\Middleware->handle()
#60 /var/www/vhosts/some-example.domain.com/public_html/vendor/laravel/framework/src/Illuminate/Pipeline/Pipeline.php(127): Illuminate\\Pipeline\\Pipeline->Illuminate\\Pipeline\\{closure}()
#61 /var/www/vhosts/some-example.domain.com/public_html/vendor/laravel/framework/src/Illuminate/Foundation/Http/Kernel.php(176): Illuminate\\Pipeline\\Pipeline->then()
#62 /var/www/vhosts/some-example.domain.com/public_html/vendor/laravel/framework/src/Illuminate/Foundation/Http/Kernel.php(145): Illuminate\\Foundation\\Http\\Kernel->sendRequestThroughRouter()
#63 /var/www/vhosts/some-example.domain.com/public_html/public/index.php(56): Illuminate\\Foundation\\Http\\Kernel->handle()
#64 {main}
"} 
[2025-04-09 19:37:19] production.ERROR: file_get_contents(https://pdf.invoicing.co/api/version): Failed to open stream: Connection timed out {"userId":1,"exception":"[object] (ErrorException(code: 0): file_get_contents(https://pdf.invoicing.co/api/version): Failed to open stream: Connection timed out at /var/www/vhosts/some-example.domain.com/public_html/app/Http/Controllers/SelfUpdateController.php:201)
[stacktrace]
#0 /var/www/vhosts/some-example.domain.com/public_html/vendor/laravel/framework/src/Illuminate/Foundation/Bootstrap/HandleExceptions.php(256): Illuminate\\Foundation\\Bootstrap\\HandleExceptions->handleError()
#1 [internal function]: Illuminate\\Foundation\\Bootstrap\\HandleExceptions->Illuminate\\Foundation\\Bootstrap\\{closure}()
#2 /var/www/vhosts/some-example.domain.com/public_html/app/Http/Controllers/SelfUpdateController.php(201): file_get_contents()
#3 /var/www/vhosts/some-example.domain.com/public_html/app/Http/Controllers/SelfUpdateController.php(207): App\\Http\\Controllers\\SelfUpdateController->checkVersion()
#4 /var/www/vhosts/some-example.domain.com/public_html/app/Http/Controllers/SelfUpdateController.php(69): App\\Http\\Controllers\\SelfUpdateController->getDownloadUrl()
#5 /var/www/vhosts/some-example.domain.com/public_html/vendor/laravel/framework/src/Illuminate/Routing/Controller.php(54): App\\Http\\Controllers\\SelfUpdateController->update()
#6 /var/www/vhosts/some-example.domain.com/public_html/vendor/laravel/framework/src/Illuminate/Routing/ControllerDispatcher.php(44): Illuminate\\Routing\\Controller->callAction()
#7 /var/www/vhosts/some-example.domain.com/public_html/vendor/sentry/sentry-laravel/src/Sentry/Laravel/Tracing/Routing/TracingControllerDispatcherTracing.php(21): Illuminate\\Routing\\ControllerDispatcher->dispatch()
#8 /var/www/vhosts/some-example.domain.com/public_html/vendor/sentry/sentry-laravel/src/Sentry/Laravel/Tracing/Routing/TracingRoutingDispatcher.php(18): Sentry\\Laravel\\Tracing\\Routing\\TracingControllerDispatcherTracing->Sentry\\Laravel\\Tracing\\Routing\\{closure}()
#9 /var/www/vhosts/some-example.domain.com/public_html/vendor/sentry/sentry-laravel/src/Sentry/Laravel/Tracing/Routing/TracingControllerDispatcherTracing.php(20): Sentry\\Laravel\\Tracing\\Routing\\TracingRoutingDispatcher->wrapRouteDispatch()
#10 /var/www/vhosts/some-example.domain.com/public_html/vendor/laravel/framework/src/Illuminate/Routing/Route.php(266): Sentry\\Laravel\\Tracing\\Routing\\TracingControllerDispatcherTracing->dispatch()
#11 /var/www/vhosts/some-example.domain.com/public_html/vendor/laravel/framework/src/Illuminate/Routing/Route.php(212): Illuminate\\Routing\\Route->runController()
#12 /var/www/vhosts/some-example.domain.com/public_html/vendor/laravel/framework/src/Illuminate/Routing/Router.php(808): Illuminate\\Routing\\Route->run()
#13 /var/www/vhosts/some-example.domain.com/public_html/vendor/laravel/framework/src/Illuminate/Pipeline/Pipeline.php(170): Illuminate\\Routing\\Router->Illuminate\\Routing\\{closure}()
#14 /var/www/vhosts/some-example.domain.com/public_html/vendor/laravel/framework/src/Illuminate/Routing/Middleware/ThrottleRequests.php(124): Illuminate\\Pipeline\\Pipeline->Illuminate\\Pipeline\\{closure}()
#15 /var/www/vhosts/some-example.domain.com/public_html/vendor/laravel/framework/src/Illuminate/Routing/Middleware/ThrottleRequests.php(89): Illuminate\\Routing\\Middleware\\ThrottleRequests->handleRequestUsingNamedLimiter()
#16 /var/www/vhosts/some-example.domain.com/public_html/vendor/laravel/framework/src/Illuminate/Pipeline/Pipeline.php(209): Illuminate\\Routing\\Middleware\\ThrottleRequests->handle()
#17 /var/www/vhosts/some-example.domain.com/public_html/app/Http/Middleware/QueryLogging.php(39): Illuminate\\Pipeline\\Pipeline->Illuminate\\Pipeline\\{closure}()
#18 /var/www/vhosts/some-example.domain.com/public_html/vendor/laravel/framework/src/Illuminate/Pipeline/Pipeline.php(209): App\\Http\\Middleware\\QueryLogging->handle()
#19 /var/www/vhosts/some-example.domain.com/public_html/vendor/laravel/framework/src/Illuminate/Routing/Middleware/SubstituteBindings.php(51): Illuminate\\Pipeline\\Pipeline->Illuminate\\Pipeline\\{closure}()
#20 /var/www/vhosts/some-example.domain.com/public_html/vendor/laravel/framework/src/Illuminate/Pipeline/Pipeline.php(209): Illuminate\\Routing\\Middleware\\SubstituteBindings->handle()
#21 /var/www/vhosts/some-example.domain.com/public_html/app/Http/Middleware/Locale.php(94): Illuminate\\Pipeline\\Pipeline->Illuminate\\Pipeline\\{closure}()
#22 /var/www/vhosts/some-example.domain.com/public_html/vendor/laravel/framework/src/Illuminate/Pipeline/Pipeline.php(209): App\\Http\\Middleware\\Locale->handle()
#23 /var/www/vhosts/some-example.domain.com/public_html/app/Http/Middleware/PasswordProtection.php(119): Illuminate\\Pipeline\\Pipeline->Illuminate\\Pipeline\\{closure}()
#24 /var/www/vhosts/some-example.domain.com/public_html/vendor/laravel/framework/src/Illuminate/Pipeline/Pipeline.php(209): App\\Http\\Middleware\\PasswordProtection->handle()
#25 /var/www/vhosts/some-example.domain.com/public_html/app/Http/Middleware/TokenAuth.php(102): Illuminate\\Pipeline\\Pipeline->Illuminate\\Pipeline\\{closure}()
#26 /var/www/vhosts/some-example.domain.com/public_html/vendor/laravel/framework/src/Illuminate/Pipeline/Pipeline.php(209): App\\Http\\Middleware\\TokenAuth->handle()
#27 /var/www/vhosts/some-example.domain.com/public_html/app/Http/Middleware/SetDb.php(40): Illuminate\\Pipeline\\Pipeline->Illuminate\\Pipeline\\{closure}()
#28 /var/www/vhosts/some-example.domain.com/public_html/vendor/laravel/framework/src/Illuminate/Pipeline/Pipeline.php(209): App\\Http\\Middleware\\SetDb->handle()
#29 /var/www/vhosts/some-example.domain.com/public_html/vendor/laravel/framework/src/Illuminate/Pipeline/Pipeline.php(127): Illuminate\\Pipeline\\Pipeline->Illuminate\\Pipeline\\{closure}()
#30 /var/www/vhosts/some-example.domain.com/public_html/vendor/laravel/framework/src/Illuminate/Routing/Router.php(807): Illuminate\\Pipeline\\Pipeline->then()
#31 /var/www/vhosts/some-example.domain.com/public_html/vendor/laravel/framework/src/Illuminate/Routing/Router.php(786): Illuminate\\Routing\\Router->runRouteWithinStack()
#32 /var/www/vhosts/some-example.domain.com/public_html/vendor/laravel/framework/src/Illuminate/Routing/Router.php(750): Illuminate\\Routing\\Router->runRoute()
#33 /var/www/vhosts/some-example.domain.com/public_html/vendor/laravel/framework/src/Illuminate/Routing/Router.php(739): Illuminate\\Routing\\Router->dispatchToRoute()
#34 /var/www/vhosts/some-example.domain.com/public_html/vendor/laravel/framework/src/Illuminate/Foundation/Http/Kernel.php(201): Illuminate\\Routing\\Router->dispatch()
#35 /var/www/vhosts/some-example.domain.com/public_html/vendor/laravel/framework/src/Illuminate/Pipeline/Pipeline.php(170): Illuminate\\Foundation\\Http\\Kernel->Illuminate\\Foundation\\Http\\{closure}()
#36 /var/www/vhosts/some-example.domain.com/public_html/vendor/sentry/sentry-laravel/src/Sentry/Laravel/Http/FlushEventsMiddleware.php(13): Illuminate\\Pipeline\\Pipeline->Illuminate\\Pipeline\\{closure}()
#37 /var/www/vhosts/some-example.domain.com/public_html/vendor/laravel/framework/src/Illuminate/Pipeline/Pipeline.php(209): Sentry\\Laravel\\Http\\FlushEventsMiddleware->handle()
#38 /var/www/vhosts/some-example.domain.com/public_html/vendor/sentry/sentry-laravel/src/Sentry/Laravel/Http/SetRequestIpMiddleware.php(45): Illuminate\\Pipeline\\Pipeline->Illuminate\\Pipeline\\{closure}()
#39 /var/www/vhosts/some-example.domain.com/public_html/vendor/laravel/framework/src/Illuminate/Pipeline/Pipeline.php(209): Sentry\\Laravel\\Http\\SetRequestIpMiddleware->handle()
#40 /var/www/vhosts/some-example.domain.com/public_html/vendor/sentry/sentry-laravel/src/Sentry/Laravel/Http/SetRequestMiddleware.php(31): Illuminate\\Pipeline\\Pipeline->Illuminate\\Pipeline\\{closure}()
#41 /var/www/vhosts/some-example.domain.com/public_html/vendor/laravel/framework/src/Illuminate/Pipeline/Pipeline.php(209): Sentry\\Laravel\\Http\\SetRequestMiddleware->handle()
#42 /var/www/vhosts/some-example.domain.com/public_html/vendor/livewire/livewire/src/Features/SupportDisablingBackButtonCache/DisableBackButtonCacheMiddleware.php(19): Illuminate\\Pipeline\\Pipeline->Illuminate\\Pipeline\\{closure}()
#43 /var/www/vhosts/some-example.domain.com/public_html/vendor/laravel/framework/src/Illuminate/Pipeline/Pipeline.php(209): Livewire\\Features\\SupportDisablingBackButtonCache\\DisableBackButtonCacheMiddleware->handle()
#44 /var/www/vhosts/some-example.domain.com/public_html/app/Http/Middleware/Cors.php(24): Illuminate\\Pipeline\\Pipeline->Illuminate\\Pipeline\\{closure}()
#45 /var/www/vhosts/some-example.domain.com/public_html/vendor/laravel/framework/src/Illuminate/Pipeline/Pipeline.php(209): App\\Http\\Middleware\\Cors->handle()
#46 /var/www/vhosts/some-example.domain.com/public_html/vendor/laravel/framework/src/Illuminate/Http/Middleware/TrustProxies.php(58): Illuminate\\Pipeline\\Pipeline->Illuminate\\Pipeline\\{closure}()
#47 /var/www/vhosts/some-example.domain.com/public_html/vendor/laravel/framework/src/Illuminate/Pipeline/Pipeline.php(209): Illuminate\\Http\\Middleware\\TrustProxies->handle()
#48 /var/www/vhosts/some-example.domain.com/public_html/vendor/laravel/framework/src/Illuminate/Foundation/Http/Middleware/TransformsRequest.php(21): Illuminate\\Pipeline\\Pipeline->Illuminate\\Pipeline\\{closure}()
#49 /var/www/vhosts/some-example.domain.com/public_html/vendor/laravel/framework/src/Illuminate/Foundation/Http/Middleware/ConvertEmptyStringsToNull.php(31): Illuminate\\Foundation\\Http\\Middleware\\TransformsRequest->handle()
#50 /var/www/vhosts/some-example.domain.com/public_html/vendor/laravel/framework/src/Illuminate/Pipeline/Pipeline.php(209): Illuminate\\Foundation\\Http\\Middleware\\ConvertEmptyStringsToNull->handle()
#51 /var/www/vhosts/some-example.domain.com/public_html/vendor/laravel/framework/src/Illuminate/Foundation/Http/Middleware/TransformsRequest.php(21): Illuminate\\Pipeline\\Pipeline->Illuminate\\Pipeline\\{closure}()
#52 /var/www/vhosts/some-example.domain.com/public_html/vendor/laravel/framework/src/Illuminate/Foundation/Http/Middleware/TrimStrings.php(51): Illuminate\\Foundation\\Http\\Middleware\\TransformsRequest->handle()
#53 /var/www/vhosts/some-example.domain.com/public_html/vendor/laravel/framework/src/Illuminate/Pipeline/Pipeline.php(209): Illuminate\\Foundation\\Http\\Middleware\\TrimStrings->handle()
#54 /var/www/vhosts/some-example.domain.com/public_html/vendor/laravel/framework/src/Illuminate/Http/Middleware/ValidatePostSize.php(27): Illuminate\\Pipeline\\Pipeline->Illuminate\\Pipeline\\{closure}()
#55 /var/www/vhosts/some-example.domain.com/public_html/vendor/laravel/framework/src/Illuminate/Pipeline/Pipeline.php(209): Illuminate\\Http\\Middleware\\ValidatePostSize->handle()
#56 /var/www/vhosts/some-example.domain.com/public_html/vendor/laravel/framework/src/Illuminate/Foundation/Http/Middleware/PreventRequestsDuringMaintenance.php(110): Illuminate\\Pipeline\\Pipeline->Illuminate\\Pipeline\\{closure}()
#57 /var/www/vhosts/some-example.domain.com/public_html/vendor/laravel/framework/src/Illuminate/Pipeline/Pipeline.php(209): Illuminate\\Foundation\\Http\\Middleware\\PreventRequestsDuringMaintenance->handle()
#58 /var/www/vhosts/some-example.domain.com/public_html/vendor/sentry/sentry-laravel/src/Sentry/Laravel/Tracing/Middleware.php(79): Illuminate\\Pipeline\\Pipeline->Illuminate\\Pipeline\\{closure}()
#59 /var/www/vhosts/some-example.domain.com/public_html/vendor/laravel/framework/src/Illuminate/Pipeline/Pipeline.php(209): Sentry\\Laravel\\Tracing\\Middleware->handle()
#60 /var/www/vhosts/some-example.domain.com/public_html/vendor/laravel/framework/src/Illuminate/Pipeline/Pipeline.php(127): Illuminate\\Pipeline\\Pipeline->Illuminate\\Pipeline\\{closure}()
#61 /var/www/vhosts/some-example.domain.com/public_html/vendor/laravel/framework/src/Illuminate/Foundation/Http/Kernel.php(176): Illuminate\\Pipeline\\Pipeline->then()
#62 /var/www/vhosts/some-example.domain.com/public_html/vendor/laravel/framework/src/Illuminate/Foundation/Http/Kernel.php(145): Illuminate\\Foundation\\Http\\Kernel->sendRequestThroughRouter()
#63 /var/www/vhosts/some-example.domain.com/public_html/public/index.php(56): Illuminate\\Foundation\\Http\\Kernel->handle()
#64 {main}
"}

I’ve increased execution time and temporarily upload_max_filesize/post_max_size to 200M (Normally 15 M)

The .env file is quite standard. I have not custom modified it.

FIY: As mentioned before this is out own self hosted server - there are no “Support at your hosting company” to contact. We have installed Plesk ourselves for easy management.

Any ideas? :light_bulb:

I think from the log timestamps it seems that 180s is way to short to let the update succeed on your server. Maybe the server or internet connection is under highload at specific times.

Update
Probably I was wrong and the issue is that downloading the update fails. Maybe a problem at the GitHub server or https://pdf.invoicing.co/api/version

1 Like

I will raise the numbers a bit and test.

I do not think you can do much about the 5xx, it is normaly related to external infrastructure. So trying again at a different time is the only thing you can do.

Well oddly enough just like last time; I waited a couple of days and then ran the update gain and “Poof”… Update done. Very odd issue. Never seen this issue before under the years we been running this web app…
.