500 server error when trying to create a PDF

Running version v5.3.48-C72 when I try to create a pdf I get a 500 server error.

I installed snappdf using composer as per instructions on the github page

In storage / logs I get

[2022-01-19 18:39:01] production.ERROR: file_get_contents(https://invoices.xxxxx.com//storage/0ZauuBKJAQdQk6nk72lRlBmFVsdfcNDKEoHofwGGGxZLhSfTb30oMepZthiMU6P3/A6dfu7ii4QRsPyZYaBBOQossXnhCn37YdrT1z07x.png): Failed to open stream: HTTP request failed! HTTP/1.1 404 Not Found {"userId":1,"exception":"[object] (ErrorException(code: 0): file_get_contents(https://invoices.xxxxx.com//storage/0ZauuBKJAQdQk6nk72lRlBmFVsdfcNDKEoHofwGGGxZLhSfTb30oMepZthiMU6P3/A6dfu7ii4QRsPyZYaBBOQossXnhCn37YdrT1z07x.png): Failed to open stream: HTTP request failed! HTTP/1.1 404 Not Found at /var/www/html/websites/xxxxxx/invoices.xxxxx.com/app/Models/Presenters/CompanyPresenter.php:69) [stacktrace]

my .env file :
`APP_NAME=“Invoice Ninja”
APP_ENV=production
APP_KEY=base64:REDACTED
APP_DEBUG=false

APP_URL=https://invoices.xxxxx.com/

DB_CONNECTION=mysql
MULTI_DB_ENABLED=false

DB_HOST=localhost
DB_DATABASE=invoice_ninja_5_jf
DB_USERNAME=ninjauser
DB_PASSWORD=thepassword
DB_PORT=3306

DEMO_MODE=false

BROADCAST_DRIVER=log
LOG_CHANNEL=stack
CACHE_DRIVER=file
QUEUE_CONNECTION=sync
SESSION_DRIVER=file
SESSION_LIFETIME=120

#REDIS_HOST=127.0.0.1
#REDIS_PASSWORD=null
#REDIS_PORT=6379

MAIL_MAILER=smtp
MAIL_HOST=smtp.gmail.com
MAIL_PORT=587
MAIL_USERNAME=user@gmail.com
MAIL_PASSWORD=redacted
MAIL_ENCRYPTION=tls
MAIL_FROM_ADDRESS=user@gmail.com
MAIL_FROM_NAME=“me”

POSTMARK_API_TOKEN=
REQUIRE_HTTPS=false

GOOGLE_MAPS_API_KEY=AIzaSyC53bRedacted
ERROR_EMAIL=
TRUSTED_PROXIES=

NINJA_ENVIRONMENT=selfhost

#options - snappdf / phantom / hosted_ninja
PDF_GENERATOR=snappdf

PHANTOMJS_KEY=‘a-demo-key-with-low-quota-per-ip-address’
PHANTOMJS_SECRET=secret

UPDATE_SECRET=secret

COMPOSER_AUTH=’{“github-oauth”: {“github.com”: “${{ secrets.GITHUB_TOKEN }}”}}’
SENTRY_LARAVEL_DSN=https://xxx
`

Would be grateful if anyone can point me in any direction. Thank You

Hi,

Please try removing the trailing slash from the APP_URL value

Hi Hillel,

Thank you very much for the prompt reply. I have noticed that, and had corrected the app url in the env, but it still shows as //storage in the error log.

 {"userId":1,"exception":"[object] (ErrorException(code: 0): file_get_contents(https://invoices.xxx.com//storage/0ZauuBKJAQdQk6nk72lRlBmFVsdfcNDKEoHofwGGGxZLhSfTb30oMepZthiMU6P3/A6dfu7ii4QRsPyZYaBBOQossXnhCn37YdrT1z07x.png): Failed to open stream: HTTP request failed! HTTP/1.1 404 Not Found
 at /var/www/html/websites/johannfenech/invoices.johannfenech.online/app/Models/Presenters/CompanyPresenter.php:69)
[stacktrace]

in the .env the app url is now

APP_URL=https://invoices.xxx.com

I re-ran php artisan optimise

but the error (above) persists.

I can confirm the snappdf doesn’t work. I’ve got a File not found at path error:

Error
[2022-01-19 21:06:39] production.ERROR: File not found at path: zcaLzxCVF4jLCYZUBhagNvPmtgDwnq3p/oPoRAYFqMIoGuP2i8pGaXTouf8WprLbYXPqNcgOR/DQtqLVAgD4uJAfN4UWvoJ1fc5wgXgw8nPU4GmLkJ/invoices/0017.pdf {"exception":"[object] (Illuminate\\Contracts\\Filesystem\\FileNotFoundException(code: 0): File not found at path: zcaLzxCVF4jLCYZUBhagNvPmtgDwnq3p/oPoRAYFqMIoGuP2i8pGaXTouf8WprLbYXPqNcgOR/DQtqLVAgD4uJAfN4UWvoJ1fc5wgXgw8nPU4GmLkJ/invoices/0017.pdf at /usr/share/nginx/invoiceninja/vendor/laravel/framework/src/Illuminate/Filesystem/FilesystemAdapter.php:167)
[stacktrace]
#0 /usr/share/nginx/invoiceninja/vendor/laravel/framework/src/Illuminate/Filesystem/FilesystemManager.php(411): Illuminate\\Filesystem\\FilesystemAdapter->get()
#1 /usr/share/nginx/invoiceninja/vendor/laravel/framework/src/Illuminate/Support/Facades/Facade.php(261): Illuminate\\Filesystem\\FilesystemManager->__call()
#2 /usr/share/nginx/invoiceninja/app/Http/Controllers/InvoiceController.php(818): Illuminate\\Support\\Facades\\Facade::__callStatic()
#3 /usr/share/nginx/invoiceninja/vendor/symfony/http-foundation/StreamedResponse.php(109): App\\Http\\Controllers\\InvoiceController->App\\Http\\Controllers\\{closure}()
#4 /usr/share/nginx/invoiceninja/vendor/symfony/http-foundation/Response.php(394): Symfony\\Component\\HttpFoundation\\StreamedResponse->sendContent()
#5 /usr/share/nginx/invoiceninja/public/index.php(61): Symfony\\Component\\HttpFoundation\\Response->send()
#6 {main}

[previous exception] [object] (League\\Flysystem\\FileNotFoundException(code: 0): File not found at path: zcaLzxCVF4jLCYZUBhagNvPmtgDwnq3p/oPoRAYFqMIoGuP2i8pGaXTouf8WprLbYXPqNcgOR/DQtqLVAgD4uJAfN4UWvoJ1fc5wgXgw8nPU4GmLkJ/invoices/0017.pdf at /usr/share/nginx/invoiceninja/vendor/league/flysystem/src/Filesystem.php:390)
[stacktrace]
#0 /usr/share/nginx/invoiceninja/vendor/league/flysystem/src/Filesystem.php(180): League\\Flysystem\\Filesystem->assertPresent()
#1 /usr/share/nginx/invoiceninja/vendor/laravel/framework/src/Illuminate/Filesystem/FilesystemAdapter.php(165): League\\Flysystem\\Filesystem->read()
#2 /usr/share/nginx/invoiceninja/vendor/laravel/framework/src/Illuminate/Filesystem/FilesystemManager.php(411): Illuminate\\Filesystem\\FilesystemAdapter->get()
#3 /usr/share/nginx/invoiceninja/vendor/laravel/framework/src/Illuminate/Support/Facades/Facade.php(261): Illuminate\\Filesystem\\FilesystemManager->__call()
#4 /usr/share/nginx/invoiceninja/app/Http/Controllers/InvoiceController.php(818): Illuminate\\Support\\Facades\\Facade::__callStatic()
#5 /usr/share/nginx/invoiceninja/vendor/symfony/http-foundation/StreamedResponse.php(109): App\\Http\\Controllers\\InvoiceController->App\\Http\\Controllers\\{closure}()
#6 /usr/share/nginx/invoiceninja/vendor/symfony/http-foundation/Response.php(394): Symfony\\Component\\HttpFoundation\\StreamedResponse->sendContent()
#7 /usr/share/nginx/invoiceninja/public/index.php(61): Symfony\\Component\\HttpFoundation\\Response->send()
#8 {main}
"} 
[2022-01-19 21:08:11] production.ERROR: File not found at path: zcaLzxCVF4jLCYZUBhagNvPmtgDwnq3p/oPoRAYFqMIoGuP2i8pGaXTouf8WprLbYXPqNcgOR/DQtqLVAgD4uJAfN4UWvoJ1fc5wgXgw8nPU4GmLkJ/invoices/0017.pdf {"exception":"[object] (Illuminate\\Contracts\\Filesystem\\FileNotFoundException(code: 0): File not found at path: zcaLzxCVF4jLCYZUBhagNvPmtgDwnq3p/oPoRAYFqMIoGuP2i8pGaXTouf8WprLbYXPqNcgOR/DQtqLVAgD4uJAfN4UWvoJ1fc5wgXgw8nPU4GmLkJ/invoices/0017.pdf at /usr/share/nginx/invoiceninja/vendor/laravel/framework/src/Illuminate/Filesystem/FilesystemAdapter.php:167)
[stacktrace]
#0 /usr/share/nginx/invoiceninja/vendor/laravel/framework/src/Illuminate/Filesystem/FilesystemManager.php(411): Illuminate\\Filesystem\\FilesystemAdapter->get()
#1 /usr/share/nginx/invoiceninja/vendor/laravel/framework/src/Illuminate/Support/Facades/Facade.php(261): Illuminate\\Filesystem\\FilesystemManager->__call()
#2 /usr/share/nginx/invoiceninja/app/Http/Controllers/InvoiceController.php(818): Illuminate\\Support\\Facades\\Facade::__callStatic()
#3 /usr/share/nginx/invoiceninja/vendor/symfony/http-foundation/StreamedResponse.php(109): App\\Http\\Controllers\\InvoiceController->App\\Http\\Controllers\\{closure}()
#4 /usr/share/nginx/invoiceninja/vendor/symfony/http-foundation/Response.php(394): Symfony\\Component\\HttpFoundation\\StreamedResponse->sendContent()
#5 /usr/share/nginx/invoiceninja/public/index.php(61): Symfony\\Component\\HttpFoundation\\Response->send()
#6 {main}

[previous exception] [object] (League\\Flysystem\\FileNotFoundException(code: 0): File not found at path: zcaLzxCVF4jLCYZUBhagNvPmtgDwnq3p/oPoRAYFqMIoGuP2i8pGaXTouf8WprLbYXPqNcgOR/DQtqLVAgD4uJAfN4UWvoJ1fc5wgXgw8nPU4GmLkJ/invoices/0017.pdf at /usr/share/nginx/invoiceninja/vendor/league/flysystem/src/Filesystem.php:390)
[stacktrace]
#0 /usr/share/nginx/invoiceninja/vendor/league/flysystem/src/Filesystem.php(180): League\\Flysystem\\Filesystem->assertPresent()
#1 /usr/share/nginx/invoiceninja/vendor/laravel/framework/src/Illuminate/Filesystem/FilesystemAdapter.php(165): League\\Flysystem\\Filesystem->read()
#2 /usr/share/nginx/invoiceninja/vendor/laravel/framework/src/Illuminate/Filesystem/FilesystemManager.php(411): Illuminate\\Filesystem\\FilesystemAdapter->get()
#3 /usr/share/nginx/invoiceninja/vendor/laravel/framework/src/Illuminate/Support/Facades/Facade.php(261): Illuminate\\Filesystem\\FilesystemManager->__call()
#4 /usr/share/nginx/invoiceninja/app/Http/Controllers/InvoiceController.php(818): Illuminate\\Support\\Facades\\Facade::__callStatic()
#5 /usr/share/nginx/invoiceninja/vendor/symfony/http-foundation/StreamedResponse.php(109): App\\Http\\Controllers\\InvoiceController->App\\Http\\Controllers\\{closure}()
#6 /usr/share/nginx/invoiceninja/vendor/symfony/http-foundation/Response.php(394): Symfony\\Component\\HttpFoundation\\StreamedResponse->sendContent()
#7 /usr/share/nginx/invoiceninja/public/index.php(61): Symfony\\Component\\HttpFoundation\\Response->send()
#8 {main}
"} 
My .env
APP_NAME="Invoice Ninja"
APP_ENV=production
APP_KEY="[REDACTED]"
APP_DEBUG="false"

APP_URL="https://pay.stefanocoding.me"

DB_CONNECTION="mysql"
MULTI_DB_ENABLED=false

DB_HOST="localhost"
DB_DATABASE="[REDACTED]"
DB_USERNAME="[REDACTED]"
DB_PASSWORD="[REDACTED]"
DB_PORT="3306"

DEMO_MODE=false

REQUIRE_HTTPS="true"
NINJA_ENVIRONMENT="selfhost"

#options - snappdf / phantom / hosted_ninja
PDF_GENERATOR=snappdf

PHANTOMJS_KEY='ak-ydtwx-3xf23-89pjk-wbzrb-9p74d'
PHANTOMJS_SECRET=secret

@david any thoughts?

@Codixer @jfenech

Can you try adding the following into your .env file

LOCAL_DOWNLOAD=true

1 Like

So I can report some progress with this suggestion. And THANK YOU SO MUCH for taking the time.

When I go to settings → Invoice design. I can see the pdf in HTML mode ON (the low quality mode preview faster but less accurate mode). The high quality mode throws this :slight_smile:


Exit Code: 127(Command not found)

Working directory: /var/www/html/websites/johannfenech/invoices.johannfenech.online/public

Output:
================


Error Output:
================
/var/www/html/websites/johannfenech/invoices.xxx.com/vendor/beganovich/snappdf/versions/961000-Linux_x64/chrome-linux/chrome: error while loading shared libraries: libnss3.so: cannot open shared object file: No such file or directory
 {"userId":1,"exception":"[object] (Symfony\\Component\\Process\\Exception\\ProcessFailedException(code: 0): The command \"'/var/www/html/websites/johannfenech/invoices.xxx.com/vendor/beganovich/snappdf/versions/961000-Linux_x64/chrome-linux/chrome' '--headless' '--disable-gpu' '--disable-translate' '--disable-extensions' '--disable-sync' '--disable-background-networking' '--disable-software-rasterizer' '--disable-default-apps' '--disable-dev-shm-usage' '--safebrowsing-disable-auto-update' '--run-all-compositor-stages-before-draw' '--no-first-run' '--no-margins' '--no-sandbox' '--print-to-pdf-no-header' '--hide-scrollbars' '--ignore-certificate-errors' '--print-to-pdf=/tmp/pdf_e38Mnu.pdf' '/tmp/html_ULx2Cv.html'\" failed.

Exit Code: 127(Command not found)

Working directory: /var/www/html/websites/johannfenech/invoices.xxx.com/public

Output:
================


Error Output:
================
/var/www/html/websites/johannfenech/invoices.xxx.com/vendor/beganovich/snappdf/versions/961000-Linux_x64/chrome-linux/chrome: error while loading shared libraries: libnss3.so: cannot open shared object file: No such file or directory
 at /var/www/html/websites/johannfenech/invoices.xxx.com/vendor/beganovich/snappdf/src/Snappdf.php:223)
[stacktrace]

@jfenech

you are missing some subsystem dependencies for headless chrome to run.

That worked thank you. So to recap, in case anyone has the same issue, my problem was twofold

  1. I was missing LOCAL_DOWNLOAD=true in my .env file (remember to run php artisan optimize after changing the .env)

  2. I was missing some dependencies for snappdf to run (case of RTFM on my end)

If it helps anyone I ran this to solve the issue of the dependencies on Ubuntu 20:

apt-get update && apt-get install ca-certificates fonts-liberation libappindicator3-1 libasound2 libatk-bridge2.0-0 libatk1.0-0 libc6 libcairo2 libcups2 libdbus-1-3 libexpat1 libfontconfig1 libgbm1 libgcc1 libglib2.0-0 libgtk-3-0 libnspr4 libnss3 libpango-1.0-0 libpangocairo-1.0-0 libstdc++6 libx11-6 libx11-xcb1 libxcb1 libxcomposite1 libxcursor1 libxdamage1 libxext6 libxfixes3 libxi6 libxrandr2 libxrender1 libxss1 libxtst6 lsb-release wget xdg-utils

Thanks everyone

1 Like

YES, thank you. This is it, this is what i needed. Invoices generated in a litteral SECOND!

1 Like

Thanks for sharing this!

cc @ben

1 Like

Perfect, this solved the same error I was having.

libasound2 for pdf generation? That sounds like a strange dependency.

It’s not the pdf generation (snappdf) depending on libasound2; it’s snappdf depending on (headless) chrome and chrome (being a web browser - not surprisingly) depending on libasound2. Even if it’s not outputting sound, the shared object needs to be there for chrome to be able to start.