Download PDF on View Invoice Page - Page not found

Version ie v5.11.61-C172

Environment Shared Hosting - Cpanel

Checklist

  • Can you replicate the issue on our v5 demo site https://demo.invoiceninja.com or Invoice Ninja?
  • Have you searched existing issues? YES
  • no config.php in /bootstrap/cache/
  • Allow_url_fopen is already enabled.
  • Cleared /client/storage/framework/cache/data
  • Have you inspected the logs in storage/logs/laravel.log for any errors? Yes
  • laravel.log last modfied on 3/8/2023 with production.ERROR: file_get_contents(): https:// wrapper is disabled in the server configuration by allow_url_fopen=0 {“exception”:"[object] (ErrorException(code: 0): file_get_contents(): https:// wrapper is disabled in the server configuration by allow_url_fopen=0 at /home/host/public_html/website/client/app/Models/Presenters/CompanyPresenter.php:69)
    [stacktrace]
    invoiceninja.log appears normal is being written too.

Describe the bug

Steps To Reproduce

Open Client Portal, Click Invoice > Click View link > Website default 404 page appears
If I download from client portal by selecting the checkmark next to invoice, it downloads correctly.

Expected Behavior

Display invoice without 404



.htaccess in /website/client/

<IfModule mod_rewrite.c>
  RewriteEngine On
  RewriteRule "^.env" - [F,L]
  RewriteRule "^storage" - [F,L]
  RewriteRule ^(.well-known)($|/) - [L]
  
  RewriteRule ^(.*)$ /public/$1 [L]
</IfModule>
<IfModule mod_alias.c>
RedirectMatch 301 ^/client/$ https://website.com/client/public
</IfModule>

/website/client/public

<IfModule mod_rewrite.c>
    <IfModule mod_negotiation.c>
        Options -MultiViews -Indexes
    </IfModule>

    RewriteEngine On

    # Handle Authorization Header
    RewriteCond %{HTTP:Authorization} .
    RewriteRule .* - [E=HTTP_AUTHORIZATION:%{HTTP:Authorization}]

    # Redirect Trailing Slashes If Not A Folder...
    RewriteCond %{REQUEST_FILENAME} !-d
    RewriteCond %{REQUEST_URI} (.+)/$
    RewriteRule ^ %1 [L,R=301]


    # Handle Front Controller...
    RewriteCond %{REQUEST_FILENAME} !-d
    RewriteCond %{REQUEST_FILENAME} !-f
    RewriteRule ^ index.php [L]
</IfModule>

<IfModule mod_headers.c>
    # Blocks Search Engine Indexing
    Header set X-Robots-Tag "noindex, nofollow"
</IfModule>

.env
has at minimum
APP_DEBUG=true
EXPANDED_LOGGING=true

APP_URL=“https://website.com/client/public”

Client Portal URL in settings:
https://website.com/client/public/client/login

HI,

Can you share a screenshot of the settings on Settings > Client Portal?

I’m not sure, maybe this answer from ChatGPT will help:

Thanks for the detailed breakdown — you’re close to solving this. Based on your setup and the symptoms (404 when viewing invoice, but download works), this is most likely a misconfiguration related to APP_URL or the route handling behind the scenes, especially in a shared hosting environment with custom subdirectory deployment.

Here’s a breakdown and step-by-step guide to fix it:


:white_check_mark: Problem Summary

  • You’re on Invoice Ninja v5.11.61-C172, shared hosting (cPanel).
  • Invoices won’t display via the View Invoice link — gives a 404.
  • But downloading the invoice works — so data exists and permissions are okay.
  • The app is installed in /website/client/ and served via /website.com/client/public.

:magnifying_glass_tilted_left: Root Cause (Most Likely)

The APP_URL is misconfigured for your deployment under a subdirectory.

You currently have:

APP_URL=“https://website.com/client/public”

But Laravel and Invoice Ninja expect APP_URL to not include /public in most cases, even if that’s how it’s served. This mismatch can break internal URL generation, especially for route-based views (like invoices/abc123/view).


:white_check_mark: Fix

  1. Update .env file:
    Replace this line:

    APP_URL=“https://website.com/client/public”
    

    With:

    APP_URL=https://website.com/client
    
  2. Clear config cache:
    Run these (via SSH or through a scheduled job in cPanel if no CLI access):

    php artisan config:clear
    php artisan cache:clear
    php artisan route:clear
    php artisan view:clear
    
  3. Optional – Rewrite cleanup:
    You might also adjust .htaccess to avoid unnecessary /client/public in URLs. Since you have:

    RedirectMatch 301 ^/client/$ https://website.com/client/public
    

    You might want to make this:

    RedirectMatch 301 ^/client/$ https://website.com/client
    

:white_check_mark: Test Again

  1. Go to the Client Portal.
  2. Click Invoice > View.
  3. The invoice should now render instead of showing 404.

:white_check_mark: Bonus Tip: allow_url_fopen

Your logs also show this:

file_get_contents(): https:// wrapper is disabled in the server configuration by allow_url_fopen=0

This error doesn’t cause the 404 directly, but it’s used when generating things like the company logo for the PDF or client portal. If possible, enable this in your hosting’s php.ini:

allow_url_fopen = On

If you can’t change it globally, ask your host or try overriding with .user.ini or .htaccess (some hosts support it):

php_value allow_url_fopen On

Let me know how it goes — happy to help troubleshoot further if needed!

After trying those recommendations, I reinstalled from softaculous and now onto a subdomain. It is working now.

1 Like

Glad to hear it, thanks for the update!