500 server error on payments

Hello,

we have error 500, when we try to delete invoice, add/change payment. Some of payments are partly paid and cannot be deleted/unpaid.

SETUP: self hosted from zip
php8.2
nginx
invoice ninja v5.7.5-C123
/var/www/ owner is user named nginx

STEPS:

  1. on older version we changed cron settings (looked like it did not helped) - empty logs, used /update secret
  2. but triangle is not in admin portal
  3. updated to v5.7.5-C123
  4. first had 500 error on login (probably fixed with /update secret)
  5. cron recurring invoices do not worked, but other things about payments worked
  6. after few hours cron fired - recurring invoices went from pending to active
  7. error 500 occured after creating new invoice and payment
  8. in storage laravel.log we see ERROR: Unable to create lockable file:
  • but it is 2 hours old, recent 500 errors do not show as entries in log

As we do not have www-data user, from other posts we found commands listed below.
So, these commands should fix the problem (replacing www-data with nginx)?

sudo chown -R www-data:www-data /var/www/html/ninja
sudo chown -R www-data:www-data storage
sudo find ./ -type d -exec chmod 755 {} \;

Thank you (i am not super experienced with linux)

Hi,

Do you see new error messages in storage/logs when trying again?

In storage/logs/laravel.log i only see these ERRORS

production.ERROR: Unable to create lockable file: /var/www /invoiceninja/storage/framework/cache/data/7b/ea/7beacf091eb507c1c109d103b4461c0 c0e439c63. Please ensure you have permission to create files in this location. { “userId”:1,“exception”:"[object] (Exception(code: 0): Unable to create lockable file: /var/www/invoiceninja/storage/framework/cache/data/7b/ea/7beacf091eb507c1c 109d103b4461c0c0e439c63. Please ensure you have permission to create files in th is location. at /var/www/invoiceninja/vendor/laravel/framework/src/Illuminate/Fi lesystem/LockableFile.php:73)

I managed to succesfuly create more invoices and payments. Later i got again this error (only different time).
Between those errors there are informative numbered lines

So, after searching here, found this post: After Update from 5.3.10 to 5.3.15 I get 500:Server error on login

USED STEPS:
cd /var/www/invoiceninja
php artisan migrate
php artisan optimize
and /update?secret=

There was nothing to migrate. Still got error when editing partialy paid payments or wanted to delete invoice.

Later i used commands from first post (also was in /var/www/invoiceninja directory)

sudo chown -R nginx:nginx /var/www/invoiceninja
sudo chown -R nginx:nginx storage
sudo find ./ -type d -exec chmod 755 {} \;

Looks like it works for now, I will report any problems. Now i can edit and or delete invoices which i could not before

Thank you

1 Like

Glad to hear it, thanks for sharing the solution!

For today it is working. Created multiple invoices and payments. Only issue was that deleting payments it showed negative account of client. It was first invoice so completely removing and creating client, helped to clear account balance to 0.

Will see how cron jobs will work

Thank you
Have a nice day

Hello, from yesterday we added 7 invoices with payments, and it happened again.
Invoice is marked as PAID, but in payments i have 2 uncompleted payments, showing 2x ammount of invoice as paid. Cannot edit or delete, get error 500. Only cron created reccuring invoices, and nobody logged in.

Log only shows 2 hours old error of lockable file

here is log

[2023-09-02 13:39:50] production.ERROR: Unable to create lockable file: /var/www/invoiceninja/storage/framework/cache/data/92/d2/92d2472ee20183b29c4d25dcd4104ee87d85a54a. Please ensure you have permission to create files in this location. {“userId”:1,“exception”:"[object] (Exception(code: 0): Unable to create lockable file: /var/www/invoiceninja/storage/framework/cache/data/92/d2/92d2472ee20183b29c4d25dcd4104ee87d85a54a. Please ensure you have permission to create files in this location. at /var/www/invoiceninja/vendor/laravel/framework/src/Illuminate/Filesystem/LockableFile.php:73)
[stacktrace]
#0 /var/www/invoiceninja/vendor/laravel/framework/src/Illuminate/Filesystem/LockableFile.php(43): Illuminate\Filesystem\LockableFile->createResource()
#1 /var/www/invoiceninja/vendor/laravel/framework/src/Illuminate/Cache/FileStore.php(108): Illuminate\Filesystem\LockableFile->__construct()
#2 /var/www/invoiceninja/vendor/laravel/framework/src/Illuminate/Cache/FileLock.php(14): Illuminate\Cache\FileStore->add()
#3 /var/www/invoiceninja/vendor/laravel/framework/src/Illuminate/Cache/Lock.php(91): Illuminate\Cache\FileLock->acquire()
#4 /var/www/invoiceninja/vendor/laravel/framework/src/Illuminate/Queue/Middleware/WithoutOverlapping.php(76): Illuminate\Cache\Lock->get()
#5 /var/www/invoiceninja/vendor/laravel/framework/src/Illuminate/Pipeline/Pipeline.php(180): Illuminate\Queue\Middleware\WithoutOverlapping->handle()
#6 /var/www/invoiceninja/vendor/laravel/framework/src/Illuminate/Pipeline/Pipeline.php(116): Illuminate\Pipeline\Pipeline->Illuminate\Pipeline\{closure}()
#7 /var/www/invoiceninja/vendor/laravel/framework/src/Illuminate/Queue/CallQueuedHandler.php(122): Illuminate\Pipeline\Pipeline->then()
#8 /var/www/invoiceninja/vendor/laravel/framework/src/Illuminate/Queue/CallQueuedHandler.php(70): Illuminate\Queue\CallQueuedHandler->dispatchThroughMiddleware()
#9 /var/www/invoiceninja/vendor/laravel/framework/src/Illuminate/Queue/Jobs/Job.php(98): Illuminate\Queue\CallQueuedHandler->call()
#10 /var/www/invoiceninja/vendor/laravel/framework/src/Illuminate/Queue/SyncQueue.php(43): Illuminate\Queue\Jobs\Job->fire()
#11 /var/www/invoiceninja/vendor/laravel/framework/src/Illuminate/Queue/SyncQueue.php(147): Illuminate\Queue\SyncQueue->push()
#12 /var/www/invoiceninja/vendor/laravel/framework/src/Illuminate/Bus/Dispatcher.php(250): Illuminate\Queue\SyncQueue->later()
#13 /var/www/invoiceninja/vendor/laravel/framework/src/Illuminate/Bus/Dispatcher.php(229): Illuminate\Bus\Dispatcher->pushCommandToQueue()
#14 /var/www/invoiceninja/vendor/laravel/framework/src/Illuminate/Bus/Dispatcher.php(77): Illuminate\Bus\Dispatcher->dispatchToQueue()
#15 /var/www/invoiceninja/vendor/laravel/framework/src/Illuminate/Foundation/Bus/PendingDispatch.php(193): Illuminate\Bus\Dispatcher->dispatch()
#16 /var/www/invoiceninja/app/Services/Ledger/LedgerService.php(38): Illuminate\Foundation\Bus\PendingDispatch->__destruct()
#17 /var/www/invoiceninja/app/Services/Payment/DeletePayment.php(100): App\Services\Ledger\LedgerService->updateInvoiceBalance()
#18 /var/www/invoiceninja/vendor/laravel/framework/src/Illuminate/Database/Eloquent/Relations/BelongsToMany.php(1028): App\Services\Payment\DeletePayment->App\Services\Payment\{closure}()
#19 /var/www/invoiceninja/vendor/laravel/framework/src/Illuminate/Database/Eloquent/Relations/BelongsToMany.php(987): Illuminate\Database\Eloquent\Relations\BelongsToMany->Illuminate\Database\Eloquent\Relations\{closure}()
#20 /var/www/invoiceninja/vendor/laravel/framework/src/Illuminate/Database/Concerns/BuildsQueries.php(53): Illuminate\Database\Eloquent\Relations\BelongsToMany->Illuminate\Database\Eloquent\Relations\{closure}()
#21 /var/www/invoiceninja/vendor/laravel/framework/src/Illuminate/Database/Eloquent/Relations/BelongsToMany.php(984): Illuminate\Database\Eloquent\Builder->chunk()
#22 /var/www/invoiceninja/vendor/laravel/framework/src/Illuminate/Database/Eloquent/Relations/BelongsToMany.php(1026): Illuminate\Database\Eloquent\Relations\BelongsToMany->chunk()
#23 /var/www/invoiceninja/app/Services/Payment/DeletePayment.php(83): Illuminate\Database\Eloquent\Relations\BelongsToMany->each()
#24 /var/www/invoiceninja/app/Services/Payment/DeletePayment.php(44): App\Services\Payment\DeletePayment->adjustInvoices()
#25 /var/www/invoiceninja/vendor/laravel/framework/src/Illuminate/Database/Concerns/ManagesTransactions.php(30): App\Services\Payment\DeletePayment->App\Services\Payment\{closure}()
#26 /var/www/invoiceninja/app/Services/Payment/DeletePayment.php(38): Illuminate\Database\Connection->transaction()
#27 /var/www/invoiceninja/app/Services/Payment/PaymentService.php(92): App\Services\Payment\DeletePayment->run()
#28 /var/www/invoiceninja/app/Repositories/PaymentRepository.php(253): App\Services\Payment\PaymentService->deletePayment()
#29 /var/www/invoiceninja/app/Http/Controllers/PaymentController.php(614): App\Repositories\PaymentRepository->delete()
#30 /var/www/invoiceninja/app/Http/Controllers/PaymentController.php(518): App\Http\Controllers\PaymentController->performAction()
#31 /var/www/invoiceninja/vendor/laravel/framework/src/Illuminate/Collections/Traits/EnumeratesValues.php(236): App\Http\Controllers\PaymentController->App\Http\Controllers\{closure}()
#32 /var/www/invoiceninja/app/Http/Controllers/PaymentController.php(516): Illuminate\Support\Collection->each()
#33 /var/www/invoiceninja/vendor/laravel/framework/src/Illuminate/Routing/Controller.php(54): App\Http\Controllers\PaymentController->bulk()
#34 /var/www/invoiceninja/vendor/laravel/framework/src/Illuminate/Routing/ControllerDispatcher.php(43): Illuminate\Routing\Controller->callAction()
#35 /var/www/invoiceninja/vendor/sentry/sentry-laravel/src/Sentry/Laravel/Tracing/Routing/TracingControllerDispatcherTracing.php(21): Illuminate\Routing\ControllerDispatcher->dispatch()
#36 /var/www/invoiceninja/vendor/sentry/sentry-laravel/src/Sentry/Laravel/Tracing/Routing/TracingRoutingDispatcher.php(19): Sentry\Laravel\Tracing\Routing\TracingControllerDispatcherTracing->Sentry\Laravel\Tracing\Routing\{closure}()
#37 /var/www/invoiceninja/vendor/sentry/sentry-laravel/src/Sentry/Laravel/Tracing/Routing/TracingControllerDispatcherTracing.php(20): Sentry\Laravel\Tracing\Routing\TracingRoutingDispatcher->wrapRouteDispatch()
#38 /var/www/invoiceninja/vendor/laravel/framework/src/Illuminate/Routing/Route.php(259): Sentry\Laravel\Tracing\Routing\TracingControllerDispatcherTracing->dispatch()
#39 /var/www/invoiceninja/vendor/laravel/framework/src/Illuminate/Routing/Route.php(205): Illuminate\Routing\Route->runController()
#40 /var/www/invoiceninja/vendor/laravel/framework/src/Illuminate/Routing/Router.php(799): Illuminate\Routing\Route->run()
#41 /var/www/invoiceninja/vendor/laravel/framework/src/Illuminate/Pipeline/Pipeline.php(141): Illuminate\Routing\Router->Illuminate\Routing\{closure}
()
#42 /var/www/invoiceninja/vendor/laravel/framework/src/Illuminate/Routing/Middleware/ThrottleRequests.php(122): Illuminate\Pipeline\Pipeline->Illuminate\Pipeline\{closure}()
#43 /var/www/invoiceninja/vendor/laravel/framework/src/Illuminate/Routing/Middleware/ThrottleRequests.php(87): Illuminate\Routing\Middleware\ThrottleRequests->handleRequestUsingNamedLimiter()
#44 /var/www/invoiceninja/vendor/laravel/framework/src/Illuminate/Pipeline/Pipeline.php(180): Illuminate\Routing\Middleware\ThrottleRequests->handle()
#45 /var/www/invoiceninja/app/Http/Middleware/QueryLogging.php(40): Illuminate\Pipeline\Pipeline->Illuminate\Pipeline\{closure}()
#46 /var/www/invoiceninja/vendor/laravel/framework/src/Illuminate/Pipeline/Pipeline.php(180): App\Http\Middleware\QueryLogging->handle()
#47 /var/www/invoiceninja/vendor/laravel/framework/src/Illuminate/Routing/Middleware/SubstituteBindings.php(50): Illuminate\Pipeline\Pipeline->Illuminate\Pipeline\{closure}()
#48 /var/www/invoiceninja/vendor/laravel/framework/src/Illuminate/Pipeline/Pipeline.php(180): Illuminate\Routing\Middleware\SubstituteBindings->handle()
#49 /var/www/invoiceninja/app/Http/Middleware/Locale.php(44): Illuminate\Pipeline\Pipeline->Illuminate\Pipeline\{closure}()
#50 /var/www/invoiceninja/vendor/laravel/framework/src/Illuminate/Pipeline/Pipeline.php(180): App\Http\Middleware\Locale->handle()
#51 /var/www/invoiceninja/app/Http/Middleware/TokenAuth.php(101): Illuminate\Pipeline\Pipeline->Illuminate\Pipeline\{closure}()
#52 /var/www/invoiceninja/vendor/laravel/framework/src/Illuminate/Pipeline/Pipeline.php(180): App\Http\Middleware\TokenAuth->handle()
#53 /var/www/invoiceninja/app/Http/Middleware/SetDb.php(40): Illuminate\Pipeline\Pipeline->Illuminate\Pipeline\{closure}()
#54 /var/www/invoiceninja/vendor/laravel/framework/src/Illuminate/Pipeline/Pipeline.php(180): App\Http\Middleware\SetDb->handle()
#55 /var/www/invoiceninja/vendor/laravel/framework/src/Illuminate/Pipeline/Pipeline.php(116): Illuminate\Pipeline\Pipeline->Illuminate\Pipeline\{closure}()
#56 /var/www/invoiceninja/vendor/laravel/framework/src/Illuminate/Routing/Router.php(798): Illuminate\Pipeline\Pipeline->then()
#57 /var/www/invoiceninja/vendor/laravel/framework/src/Illuminate/Routing/Router.php(777): Illuminate\Routing\Router->runRouteWithinStack()
#58 /var/www/invoiceninja/vendor/laravel/framework/src/Illuminate/Routing/Router.php(741): Illuminate\Routing\Router->runRoute()
#59 /var/www/invoiceninja/vendor/laravel/framework/src/Illuminate/Routing/Router.php(730): Illuminate\Routing\Router->dispatchToRoute()
#60 /var/www/invoiceninja/vendor/laravel/framework/src/Illuminate/Foundation/Http/Kernel.php(200): Illuminate\Routing\Router->dispatch()
#61 /var/www/invoiceninja/vendor/laravel/framework/src/Illuminate/Pipeline/Pipeline.php(141): Illuminate\Foundation\Http\Kernel->Illuminate\Foundation\Http\{closure}()
#62 /var/www/invoiceninja/vendor/sentry/sentry-laravel/src/Sentry/Laravel/Http/SetRequestIpMiddleware.php(45): Illuminate\Pipeline\Pipeline->Illuminate\Pipeline\{closure}()
#63 /var/www/invoiceninja/vendor/laravel/framework/src/Illuminate/Pipeline/Pipeline.php(180): Sentry\Laravel\Http\SetRequestIpMiddleware->handle()
#64 /var/www/invoiceninja/vendor/sentry/sentry-laravel/src/Sentry/Laravel/Http/SetRequestMiddleware.php(31): Illuminate\Pipeline\Pipeline->Illuminate\Pipeline\{closure}()
#65 /var/www/invoiceninja/vendor/laravel/framework/src/Illuminate/Pipeline/Pipeline.php(180): Sentry\Laravel\Http\SetRequestMiddleware->handle()
#66 /var/www/invoiceninja/vendor/livewire/livewire/src/DisableBrowserCache.php(19): Illuminate\Pipeline\Pipeline->Illuminate\Pipeline\{closure}()
#67 /var/www/invoiceninja/vendor/laravel/framework/src/Illuminate/Pipeline/Pipeline.php(180): Livewire\DisableBrowserCache->handle()
#68 /var/www/invoiceninja/app/Http/Middleware/Cors.php(24): Illuminate\Pipeline\Pipeline->Illuminate\Pipeline\{closure}()
#69 /var/www/invoiceninja/vendor/laravel/framework/src/Illuminate/Pipeline/Pipeline.php(180): App\Http\Middleware\Cors->handle()
#70 /var/www/invoiceninja/vendor/laravel/framework/src/Illuminate/Http/Middleware/TrustProxies.php(39): Illuminate\Pipeline\Pipeline->Illuminate\Pipeline\{closure}()
#71 /var/www/invoiceninja/vendor/laravel/framework/src/Illuminate/Pipeline/Pipeline.php(180): Illuminate\Http\Middleware\TrustProxies->handle()
#72 /var/www/invoiceninja/vendor/laravel/framework/src/Illuminate/Foundation/Http/Middleware/TransformsRequest.php(21): Illuminate\Pipeline\Pipeline->Illuminate\Pipeline\{closure}()
#73 /var/www/invoiceninja/vendor/laravel/framework/src/Illuminate/Foundation/Http/Middleware/ConvertEmptyStringsToNull.php(31): Illuminate\Foundation\Http\Middleware\TransformsRequest->handle()
#74 /var/www/invoiceninja/vendor/laravel/framework/src/Illuminate/Pipeline/Pipeline.php(180): Illuminate\Foundation\Http\Middleware\ConvertEmptyStringsToNull->handle()
#75 /var/www/invoiceninja/vendor/laravel/framework/src/Illuminate/Foundation/Http/Middleware/TransformsRequest.php(21): Illuminate\Pipeline\Pipeline->Illuminate\Pipeline\{closure}()
#76 /var/www/invoiceninja/vendor/laravel/framework/src/Illuminate/Foundation/Http/Middleware/TrimStrings.php(40): Illuminate\Foundation\Http\Middleware\TransformsRequest->handle()
#77 /var/www/invoiceninja/vendor/laravel/framework/src/Illuminate/Pipeline/Pipeline.php(180): Illuminate\Foundation\Http\Middleware\TrimStrings->handle()
#78 /var/www/invoiceninja/vendor/laravel/framework/src/Illuminate/Foundation/Http/Middleware/ValidatePostSize.php(27): Illuminate\Pipeline\Pipeline->Illuminate\Pipeline\{closure}()
#79 /var/www/invoiceninja/vendor/laravel/framework/src/Illuminate/Pipeline/Pipeline.php(180): Illuminate\Foundation\Http\Middleware\ValidatePostSize->handle()
#80 /var/www/invoiceninja/vendor/laravel/framework/src/Illuminate/Foundation/Http/Middleware/PreventRequestsDuringMaintenance.php(86): Illuminate\Pipeline\Pipeline->Illuminate\Pipeline\{closure}()
#81 /var/www/invoiceninja/vendor/laravel/framework/src/Illuminate/Pipeline/Pipeline.php(180): Illuminate\Foundation\Http\Middleware\PreventRequestsDuringMaintenance->handle()
#82 /var/www/invoiceninja/vendor/sentry/sentry-laravel/src/Sentry/Laravel/Tracing/Middleware.php(87): Illuminate\Pipeline\Pipeline->Illuminate\Pipeline\{closure}()
#83 /var/www/invoiceninja/vendor/laravel/framework/src/Illuminate/Pipeline/Pipeline.php(180): Sentry\Laravel\Tracing\Middleware->handle()
#84 /var/www/invoiceninja/vendor/laravel/framework/src/Illuminate/Pipeline/Pipeline.php(116): Illuminate\Pipeline\Pipeline->Illuminate\Pipeline\{closure}()
#85 /var/www/invoiceninja/vendor/laravel/framework/src/Illuminate/Foundation/Http/Kernel.php(175): Illuminate\Pipeline\Pipeline->then()
#86 /var/www/invoiceninja/vendor/laravel/framework/src/Illuminate/Foundation/Http/Kernel.php(144): Illuminate\Foundation\Http
\Kernel->sendRequestThroughRouter()
#87 /var/www/invoiceninja/public/index.php(56): Illuminate\Foundation\Http\Kernel->handle()

It seems likely it’s a permissions error. You may want to switch to using Docker instead, it shouldn’t have these issues.

So we found that cron was scheduled under root user, instead of nginx (i as a technician inherited this server after another technician…)

We cleared the cache,

php artisan cache:clear 

created new cron command under nginx user
and /update secret

Now we will see what will happen.
Looks like it is caused by cron. Because we set reccuring invoices few days ago around 15:30 of our local time. This error happens since then after 15:30

Glad to hear it, thanks again for sharing your solution! Here’s hoping the problem is now resolved.

Hello, so 500 error disapeared. Sometimes we see the whole website fo freeze. Browser will show pop up about leaving website. Then it will reload and everything works.

For now we have not tested cron and reccuring invoices.
We will test it during weekend

Also i forgot. There is weird bug with translations. When user or admin account want to add a payment of invoice, the labels are in english e.g. Bank transfer, cash…

After 1 hour or 1 and half hour translations automatically get in language which was set during installation. Other labels, or words are 100% of time in language set during installation.

This behavior will show again, if user log out and log in (again he/she will have english translations of payment type for 1 hour)

Are you using the Flutter or React app?

You may want to try the desktop app:

Right now we use Flutte version. In React version we could not figure out how to get custom columns in lists like clients or invoices to show in e.g. list of clients