Saving files locally with Laravel
Stefan Bogdanescu
Founder & Senior Architect · 2026-06-29
# Saving Files Locally in Laravel: Solving the 404 URL Mystery
As a senior developer working with Laravel, managing file storage—especially when dealing with public assets that need to be accessible via a web URL—is a common sticking point. You've correctly set up the foundation using `storage:link`, but suddenly, accessing those files results in a frustrating 404 error. This often happens not because of an error in your code logic, but due to a misunderstanding of how Laravel’s storage mechanism interacts with the underlying web server configuration.
This post will diagnose why you are encountering 404 errors when trying to access files saved via the `storage` disk and provide the definitive solution to ensure your public assets are served correctly.
## Understanding the Laravel Storage Link
You have already taken the crucial first step: running `php artisan storage:link`. This command creates a symbolic link from the publicly accessible directory (`public/storage`) to the private application storage directory (`storage/app/public`).
When you use the `Storage` facade in your application (e.g., `$disk->put(...)`), Laravel saves the file physically into the `storage/app/public` folder. The symlink then tells the web server: "If a request comes for `/storage/filename`, look here (`storage/app/public/filename`)."
Your workflow looks sound:
1. File is saved to `storage/app/public/`.
2. A link exists from `public/storage` pointing to that location.
3. You retrieve the filename from the database.
4. You attempt to generate the URL using `asset($filename)`.
The failure occurs at step 4 because while the *application* knows how to map the path internally, the *web server* (Apache or Nginx) needs explicit configuration to serve files from that symlinked location correctly, especially in local development environments.
## The Root Cause: Web Server Configuration Mismatch
The 404 error almost always points to a mismatch between the file system permissions and how your web server is configured to handle static assets.
In many local development setups (like those using PHP's built-in server or Dockerized environments), while the symlink works perfectly for Artisan commands, the actual HTTP request path might not be correctly mapped by default, leading to a 404 response instead of serving the file content.
To fix this, we need to ensure that the web server explicitly recognizes and serves files from the `public/storage` directory. This is an infrastructure configuration issue rather than a Laravel code error.
## The Solution: Ensuring Public Directory Access
The solution involves two parts: verifying permissions and ensuring your web server setup correctly points to the public assets. While this fix is environment-dependent (e.g., how you run PHP), understanding the principle is key for robust