Laravel: Images Work Locally But Show 404 on Live Server Website?

After pushing your code to your live server, the website doesn't show the public images you uploaded? This is a typical problem often asked on forums. These are the potential reasons/fixes.

Of course, it depends on how you load the image. The typical code is this:

<img src="{{ asset('images/logo.png') }}" />

Or, if you use a Spatie Media Library package:

<img src="{{ $user->getFirstMediaUrl('avatars') }}" />

First, what you need to do is to right-click that failed image and see its full URL. From that, you may realize your problem. Does that image contain an incorrect domain? Some subfolders missing in the path?

Then, check these three things:

  1. Check your .env file and APP_URL value: it should be https://[yourwebsite.com] - some people forget to change it from the default localhost or provide incorrect URL with an extra folder/subdomain
  2. If you store images in storage/app/public, check if you have run php artisan storage:link successfully (so, no errors happened) to create the symlink.
  3. Check if your web-server root folder is successfully pointed to the /public folder of the Laravel project.

In my experience, these cover all potential cases of this problem.

avatar

I ran into this problem on Laravel Cloud. However the instructions from this article don't really seem to apply in this case. What would be the corresponding steps when using Laravel Cloud?

avatar

Sorry, we have not had enough experience with Cloud to help you here...

But from overall experience - I think you should use s3 to store the images and return it from there. Cloud (serverless) storage is often not persistent and you dont have much space there

Like our articles?

Become a Premium Member for $129/year or $29/month
What else you will get:
  • 83 courses
  • 96 long-form tutorials
  • access to project repositories
  • access to private Discord

Recent New Courses