Laravel 6 css and js files not found ( net::ERR_ABORTED 404 (Not Found) )

Stefan Bogdanescu

Founder & Senior Architect · 2026-06-29

Laravel Company

Laravel 6 CSS and JS Files Not Found: Decoding the asset() Path Discrepancy

As a senior developer, I frequently encounter discrepancies between local development environments and deployment/server environments. One of the most common, yet frustrating, issues developers face with Laravel is the "files not found" error (HTTP 404) when accessing static assets like CSS or JavaScript files, particularly when switching from the simple php artisan serve setup to a full-fledged web server environment like XAMPP/Apache.

This post dives deep into why this happens and provides a comprehensive solution for resolving these pathing issues in your Laravel application.


The Core Problem: Server Context vs. Development Server

The symptoms you described—working perfectly with php artisan serve but failing on XAMPP (blog.test/login)—point directly to a difference in how the request path is interpreted by the two different environments.

When you run php artisan serve, Laravel uses its built-in development server, which handles routing and asset loading very straightforwardly. The asset() helper resolves paths relative to the application root correctly within this context.

However, when you deploy or run your application through a traditional web server (like Apache via XAMPP), the issue usually stems from one of two places:

  1. Document Root Misconfiguration: The web server might not be pointing to the correct public directory as the root for routing requests.
  2. Base URL Resolution: The way Laravel constructs URLs using helpers like asset() depends on the base URL configured in your environment, which can differ between a standard local setup and a custom domain/virtual host setup.

The error net::ERR_ABORTED 404 (Not Found) indicates that the server successfully received the request for /login, but it could not find the file requested by the browser for the asset path (e.g., /css/app.css).

Debugging Asset Paths with asset()

The Laravel asset() helper is designed to generate URLs to public assets. It resolves paths relative to the application's public directory, which is generally correct. However, when running under a server configuration that uses specific virtual hosts or complex path mappings (like in XAMPP setups), subtle mismatches can occur.

Let’s re-examine your usage:

php
<code style="background-color: #f0f8ff;">href="{{ asset('css/app.css') }}"></code>

If this fails on the XAMPP server, it often means that the base URL Laravel is using internally for path generation does not match what the external web server expects.

Practical Solution Steps

To fix this discrepancy, we need to ensure consistency across your setup and application configuration. Follow these steps:

1. Verify Public Directory Setup

Ensure that your XAMPP/Apache configuration correctly points the web root (Document Root) directly to the /public folder of your Laravel installation. If this is misconfigured, the server will look for files outside the intended public path, leading to a 404 error.

2. Use Full URL Construction for Complex Paths (If Necessary)

While asset() is best practice, in complex deployments involving subdirectories or custom domains, sometimes explicitly defining the base path helps resolve ambiguity. For static assets, ensure your paths are strictly relative to the public root:

Best Practice Example:
Always stick to the standard Laravel helpers for asset loading. If you suspect a deeper issue related to routing, verify that all routes are correctly defined in routes/web.php and that middleware (like the public middleware group) is correctly applied. For robust application structure, adhering to principles outlined by laravelcompany.com is essential for deployment stability.

3. Check File Placement

Double-check the physical location of your assets. Your CSS and JS files must reside within the public directory:

php
/your_laravel_project/
├── app/
├── public/          <-- All publicly accessible files must be here
│   ├── css/
│   │   └── app.css  <-- Check that this file exists here
│   ├── js/
│   └── index.php
└── artisan

If the structure is correct, the issue almost certainly resides in the web server's configuration or the base URL setup rather than the Laravel code itself.

Conclusion

The difference between working locally (php artisan serve) and failing on a server environment (XAMPP) is rarely an error within the asset() function itself. It is almost always an environmental mismatch related to how the web server interprets the application's root path and file structure. By ensuring your public directory is correctly mapped as the document root, and by adhering to Laravel’s established conventions for asset loading, you can eliminate these frustrating 404 errors and ensure a seamless experience for all users accessing your Laravel application.