Unable to create PDFs

I did a fresh install of Invoice Ninja v5 on a brand new installation of ISPConfig (running Ubuntu 20.04 with PHP 7.4, Apache, and Let’s Encrypt SSL Cert for the sub-domain I’m running it on). No errors on the initial installation checks.

I’ve created one company, and one product, and when I go to create an invoice, hitting save generates the following error:

500: file_get_contents(https://xxxxx.xxxxx.ca/storage/Fu8xVAoZPOmV5NrSmjtZDM13NoWsNWWU6qy3uqNlXsIQCWndSrMS9M4sPmNZqdiO/HL6Ow2r30vdCtrwxGMGl3Dpi6GDXo9wcDcGKM1ir.png): failed to open stream: Connection timed out

I’ve checked the ownership on the Storage folder, and they are correct for the ISPConfig environment. I’ve tried changing folder permissions from 755 to 777 and back to 755. I’ve cleared the cache as well as run php artisan optimize.

Can anyone point me in the right direction?

@david do you have any suggestions?

@christopher.phillips

This error indicates that the app cannot resolve (for what ever reason) the full URL to the logo file.

if you attempt to go to the URL in your browser, does it resolve?

Am I correct to assume that I should also see this logo file in the Storage directory? (If I should see it there, I most decidedly do not.)

I’ll give the URL in my browser a try.

So yes, I can open the full URL for the logo file. I am also now seeing this error in the logs:

*[2021-08-02 21:15:53] production.INFO: https://xxxxxx.xxxxxx.ca/phantom/invoice/yXligGHXS5EbWjKR4pNjIqFUrEmMS1LD7wgm0q89ulkJLH8nBlWIYiuvF5IRhuSV?phantomjs_secret=secret *
[2021-08-02 21:16:33] production.ERROR: There was an error generating the PDF with Phantom JS {“exception”:"[object] (App\Exceptions\PhantomPDFFailure(code: 0): There was an error generating the PDF with Phantom JS at /var/www/clients/clientX/webX/finance/app/Utils/PhantomJS/Phantom.php:135)

Is it possible you’ve reached your max limit of generated PDFs?

It’s entirely possible. I’ve registered for a PhantomJS key, as well as purchased the White Label option. I will be doing some additional testing with the White Label first.

I will add in my white label key, and then these two lines into my .env file

NINJA_HOSTED_PDF=true
PHANTOMJS_PDF_GENERATION=false

In the existing .ENV file, I also have the following line. Does it need to be changed to “hosted_ninja” in addition to the above two lines?

PDF_GENERATOR=phantom

Thank you for your help.
Chris

@christopher.phillips,

I can’t tell for sure if this would work on your server, but here are my self hosted PDF settings in my .env file, which work fine on my end on a shared server, if that helps:

PDF_GENERATOR=hosted_ninja
NINJA_HOSTED_PDF=true
PHANTOMJS_PDF_GENERATION=false

Thanks Charles. I updated my .Env file, did an optimize, cleared the cache and tried to save an invoice again. Receiving this error again in the logs:

[2021-08-03 15:25:40] production.ERROR: file_get_contents(https://xxxxxx.xxxxxx.ca/storage/w8lvnvT1RoKS7tCVUAFPHKZKDD5ant01byN8n9JF4EIsr0AEnNzB47PWDyEfzyOj/bDUlBTqsuBjwj0PSYAQ2MYHmMCmcUDh6KaWTWwUT.png): failed to open stream: Connection timed out {“exception”:"[object] (ErrorException(code: 0): file_get_contents(https://xxxxxx.xxxxxx.ca/storage/w8lvnvT1RoKS7tCVUAFPHKZKDD5ant01byN8n9JF4EIsr0AEnNzB47PWDyEfzyOj/bDUlBTqsuBjwj0PSYAQ2MYHmMCmcUDh6KaWTWwUT.png): failed to open stream: Connection timed out at /var/www/clients/clientX/webX/finance/app/Models/Presenters/CompanyPresenter.php:68)

The URL is viewable from a browser as it was before.

Some additional testing:

Creating a new invoice and saving it (without trying to view) is currently giving me:

TimeoutException after 0:00:30.000000: Future not completed - I believe this is due to email settings which I believe are ok, but can’t test at the moment.

  • I do not see any additional entries in the error log after doing this.
  • When I click on the Invoice section again, I’m prompted to either continue editing or discard changes.
  • Discarding changes and refreshing my browser results in a new invoice showing up, but the number is showing “Pending”
  • Opening that pending invoice and trying to save again results in a 500: Server Error.
  • Clicking the Invoice section again does not result in the same prompt to discard my changes as above.
  • The invoice is still showing “Pending” for the number. Error log still showing no additional entries.
  • Opening this invoice again and trying to view the PDF results in another 500: Server Error. Still number pending, and no error logs.
  • Logged completely out, and back into InvoiceNinja.
  • Opened Invoice and hit Save. 500: Server Error. Still shows as number pending.
  • Logged out, ran PHP ARTISAN OPTIMIZE, logged back in, edited invoice and saved. 500: Server Error. Nothing in log.
  • Tried viewing PDF without navigating elsewhere first. Same 500 Server Error.

I deleted my logo file that I uploaded, then logged out, ran PHP ARTISAN KEY:GENERATE and OPTIMIZE, then logged back in. The invoice had been populated with a number, and I’m seeing below in the log file. The new_logo.png file is viewable from a web browser.

[2021-08-03 18:12:55] production.ERROR: file_get_contents(https://xxxxxx.xxxxxx.ca/images/new_logo.png): failed to open stream: Connection timed out {“userId”:1,“exception”:"[object] (ErrorException(code: 0): file_get_contents(https://xxxxxx.xxxxxx.ca/images/new_logo.png): failed to open stream: Connection timed out at /var/www/clients/clientX/webX/finance/app/Models/Presenters/CompanyPresenter.php:72)

I checked my firewall and tested turning off all Advanced Threat Protection and Intrusion Prevention on the firewall rules. Additional testing did not reveal any positive results, and I’m really at a lack of what to try next.

Well…I managed to figure it out. An errant firewall rule was not allowing the ISPConfig server to essentially talk to itself. The URLs above worked great from my PC, but I tried using WGET to the URL from the server itself and it timed out. Went searching through my firewall rules and found the issue.

UGH! Glad to have it fixed, but oh man is that frustrating.

Thank you to everyone who chimed in with suggestions. :slight_smile:

Glad to hear you were able to track it down, thanks for sharing the solution!

1 Like