Skip to main content
Tutorial Free

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

July 24, 2023
2 min read

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.

Enjoyed This Tutorial?

Get access to all premium tutorials, video and text courses, and exclusive Laravel resources. Join our community of 10,000+ developers.

Comments & Discussion

MM
m. maier ✓ Link copied!

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?

M
Modestas ✓ Link copied!

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

We'd Love Your Feedback

Tell us what you like or what we can improve

Feel free to share anything you like or dislike about this page or the platform in general.