Laravel Storage 404 Not Found
When working with Laravel, you may encounter a situation where an image or a file that loads perfectly fine on your local development environment doesn’t load on your hosting server. This is a common issue, especially when dealing with storage links and filesystem permissions. If you’ve run into this problem, here’s a step-by-step guide to fix Laravel Storage 404 Not Found.
Step 1. Delete and Recreate the Symlink
One of the most common causes of this issue is a broken or misconfigured symlink between your public
directory and your storage
directory. To fix this, you can delete the existing symlink and create a new one. If you are using hosting, you can use SSH to do this. If you don’t know how to do ssh on hosting, read this article.
Remove the existing symlink
rm public/storage
Create a new symlink
php artisan storage:link
This will ensure that the symlink is correctly created and points to the right directory, allowing your images to be accessed via the URL.
Step 2. Verify the Symlink Manually
If you have SSH access to your server, you can manually inspect the symlink to ensure it’s pointing to the correct location.
Check the symlink
ls -l public/storage
This command will display the target path of the symlink. Make sure it points to ../storage/app/public
.
Step 3. Check File and Directory Permissions
File and directory permissions are another common culprit. If the web server cannot access the necessary files due to restrictive permissions, the images won’t load.
Set the correct permissions
chmod -R 775 storage
chmod -R 775 public/storage
Ensure that the web server user (often www-data
or apache
) has adequate permissions to read the files within these directories.
4. Test the URL
After recreating the symlink and checking permissions, attempt to access the image directly through the browser.
Test the URL
https://yourdomain.com/storage/your_folder/file_name.png
If the image still doesn’t load, the problem might lie in your server configuration or filesystem settings.
5. Verify .env and filesystems.php Configuration
Your .env
file and filesystems.php
configuration play a critical role in how Laravel handles URLs and file paths. Ensure that your .env
file is correctly configured with the appropriate APP_URL
:
Check your .env file
APP_URL=https://your-site.com
Next, confirm that the filesystems.php
configuration is correctly set up:
Verify filesystems.php
'public' => [
'driver' => 'local',
'root' => storage_path('app/public'),
'url' => env('APP_URL') . '/storage',
'visibility' => 'public',
],
Still Having Issues?
If after following all these steps your images are still not accessible, it may be time to contact your hosting provider. There could be server-level restrictions or configuration issues preventing the symlink from functioning properly.
Access issues like these can be frustrating, but with a systematic approach, they’re usually solvable. By ensuring your symlinks are correctly set up, permissions are appropriately configured, and your environment variables are in order, you should be able to get your images loading as expected on your hosting environment.