Most Laravel developers hit a Laravel 404 Error After Deployment at least once in their career, and the fix is rarely obvious the first time. A perfectly working app on your local machine can suddenly show "Not Found" on a production server because of misrouted requests, missing rewrite rules, or broken file ownership. This guide walks you through the real causes, the precise commands to fix them, and the tradeoffs nobody warns you about, so you can stop guessing and ship clean.
Overview & Quick Fix Summary
What triggers a 404 after deployment?
Three things break Laravel routes on a fresh server: the web server never hands the request to public/index.php, Laravel cannot read its own files, or the routing cache points at a path that no longer exists. The browser sees a 404 either way, but the root cause is almost always one of the three.
Immediate steps to verify routes
- Open a static file in the same domain (for example,
robots.txt). If that also 404s, the issue is DNS, the document root, or file permissions, not Laravel. - Run
php artisan route:liston the server to confirm your routes are actually registered. - Check that
APP_URLin.envmatches the live domain exactly, including protocol and trailing slash behavior.
If the static file loads but Laravel routes do not, your web server rewrite is the prime suspect, and the Apache or Nginx sections below will resolve it within minutes.
Why 404 Errors Matter in 2026 Laravel Deployments
Impact on SEO and user trust
A 404 is not just a broken link. It wastes Google's crawl budget, kills internal link equity, and erodes user trust the moment someone hits your homepage and sees "Not Found." In competitive niches, a deployment-time 404 left uncorrected for hours can quietly bleed rankings that took months to earn.
Evolving PHP runtime and Laravel versions
Laravel 11.x on PHP 8.2+ is the mainstream stack in 2026, and it ships tighter defaults around cache signing, route discovery, and asset versioning. The framework assumes your server is configured to forward every non-file request to index.php. Older Apache configs and many shared hosting panels still expect you to wire that up manually, which is exactly where the 404 appears. Staying current means catching up on the rewrite rules your host may not enable by default, not the other way around.
Definition: A 404 error is an HTTP status code indicating the requested resource was not found. In Laravel, it usually means the request never reached the framework because the web server could not map the URL to a real file or directory.
Prerequisites & Environment Checklist
Server stack (Apache/Nginx, PHP 8.2, MariaDB)
Before you start debugging, make sure the basics are installed. On Ubuntu, a production-ready Laravel stack includes Apache or Nginx, PHP 8.2 with required extensions, and MariaDB. A minimal PHP install command for Laravel looks like this:
sudo apt install php libapache2-mod-php php-mbstring php-xmlrpc php-soap php-gd php-xml php-cli php-zip php-bcmath php-tokenizer php-json php-pear
sudo apt install mariadb-server
sudo apt install apache2
sudo ufw allow "Apache Full"
Verify Apache is running with sudo systemctl status apache2, and confirm PHP is wired in by creating a quick test file with sudo nano /var/www/html/test.php that contains <?php phpinfo(); ?>. If phpinfo() renders, your PHP and module chain is healthy.
Laravel 11.x compatibility
Laravel 11 requires PHP 8.2 or higher and Composer 2.x. If you are still on PHP 8.0 or 8.1, route caching and the new php artisan key:rotate command will silently misbehave. Upgrade PHP first, then run composer install --no-dev --optimize-autoloader against the production server.
Vite and laravel-vite-plugin setup
Laravel 11 uses Vite as the default asset bundler through the laravel-vite-plugin. A missing manifest will not directly cause route 404s, but it will break your CSS and JS, which often gets mistaken for a routing issue. Confirm package.json includes vite and laravel-vite-plugin, and that resources/js/app.js and resources/css/app.css exist as the documented entry points.
Common Causes of Laravel 404 After Deployment
URL Rewrites & .htaccess misconfig
The default Laravel .htaccess file is required inside the public/ directory. If your hosting panel points the document root at the project root instead of public/, or if the file is missing, Apache will return 404 instead of routing through index.php. As noted in a thread on the Laravel.io deployment forum, missing symlinks and a misplaced document root account for the majority of post-deployment 404 reports.
File Permissions & Ownership errors
If storage/ and bootstrap/cache/ are not writable by the web server user, Laravel throws a 500 in some cases and a 404 in others when it cannot read cached route files. The fix is well documented in the Deploynix deployment errors guide: assign the right owner and group, then grant 775.
Storage link and public folder missing
Laravel exposes user uploads through a symlink from public/storage to storage/app/public. If that symlink was never created, every uploaded file URL returns 404. Running php artisan storage:link on the server is mandatory after every first deploy, and the command is idempotent, so it is safe to add to your deployment script.
Vite asset compilation issues
A 404 on /build/assets/app-xxxx.js means Vite never built the assets, or the manifest path is wrong. As explained in the Laravel News Vite error roundup, the production build is npm run build, not npm run dev. A dev build points to a local server, which is unreachable from production, and every referenced asset silently 404s.
Step-by-Step Fix for Apache (mod_rewrite)
Verify .htaccess exists and correct
Confirm the file is present at public/.htaccess and that the document root in your Apache config points to the public/ directory, not the project root. The standard Laravel .htaccess contains a rewrite rule that forwards every non-file request to index.php.
Enable mod_rewrite module
mod_rewrite is not always enabled on fresh Apache installs. Enable it, then restart Apache:
sudo a2enmod rewrite
sudo systemctl restart apache2
If your host uses cPanel or a panel like Hostinger's Laravel tutorial, mod_rewrite is usually already enabled but your AllowOverride directive may block .htaccess from taking effect. Switch AllowOverride None to AllowOverride All inside the <Directory> block.
Set proper APP_URL in .env
Open .env and confirm APP_URL matches the live URL exactly. Mixed protocols (http vs https) or mismatched subdomains can produce 404s on signed routes and asset links. Save and clear config.
Clear route cache
After every deploy, refresh the cached route file so stale route definitions do not haunt you:
php artisan route:clear
php artisan config:clear
php artisan cache:clear
Step-by-Step Fix for Nginx
Configure server block for Laravel
Nginx does not read .htaccess. You must hardcode the rewrite logic into your server block. A minimal Laravel-ready server block looks like this:
server {
listen 80;
server_name example.com www.example.com;
root /var/www/example.com/public;
index index.php;
location / {
try_files $uri $uri/ /index.php?$query_string;
}
location ~ \.php$ {
include snippets/fastcgi-php.conf;
fastcgi_pass unix:/var/run/php/php8.2-fpm.sock;
}
}
Use try_files directive
The try_files line is the heart of the fix. It tells Nginx: try the literal file, then the directory, then hand the request to index.php. Without it, Nginx returns 404 the moment a URL does not match a real file.
Set proper root and index
Make sure root points at the public/ directory of your Laravel project, not the project root. A common mistake is to point it at /var/www/example.com instead of /var/www/example.com/public.
Reload Nginx
After any config change, validate syntax and reload:
sudo nginx -t
sudo systemctl reload nginx
Fixing File Ownership & Permissions
Using chown/chmod commands
Set ownership of the writable directories to your deploy user and the web server group, then grant 775 permissions so the group can write:
chown -R deploynix:www-data storage bootstrap/cache
chmod -R 775 storage bootstrap/cache
This pattern is recommended in the Deploynix deployment errors guide for a reason: it lets the web server write cached files without exposing the application to the world. Avoid running deployment commands as root. Root-owned files break the web server's ability to read your views, which is yet another source of 404s on fresh deploys.
Hostinger Fix File Ownership tool
If you deploy through Hostinger's hPanel and the 404 persists, use the Fix File Ownership tool described in their 404 troubleshooting tutorial. It resets ownership to the panel's default user and resolves most permission-driven 404s in seconds.
Ensuring web server user access
After applying permissions, test with phpinfo() and confirm the script owner matches the FPM or Apache user. If the user mismatch persists, Laravel will load but quietly fail to compile cached views, surfacing as 404 on routes that depend on those views.
Testing permissions with phpinfo
Drop a temporary phpinfo() file, load it in the browser, and check the user and group under the Environment section. Then run ls -la storage on the server and confirm the owner matches.
Real-World Tradeoffs & Performance Impact
Cache vs. Freshness tradeoffs
Running php artisan route:cache and php artisan config:cache on every deploy dramatically improves response time, but it also means a stale cache can mask a working config. If you fix a 404 by editing .env but forget to clear config cache, the old APP_URL keeps winning. The tradeoff: speed for a brief, predictable cache-clearing step after each deploy.
Vite hot reload vs. production build
npm run dev is incredible locally because it gives instant HMR, but it relies on a Vite dev server that does not exist in production. Running it on a deployed server exposes a port, leaks source maps, and 404s every bundled asset when the dev server is killed. Use npm run build in any deployment pipeline and serve the resulting public/build/ files as static assets.
Impact on deployment time and server load
Adding npm run build, asset versioning, and php artisan optimize can add 30 to 90 seconds to a deployment. For a CI/CD pipeline on Jenkins or GitHub Actions, that is fine. For a shared host where you upload via FTP, it can be painful. If you ship multiple times a day, automate the build step in CI and upload only the artifacts. If you ship weekly, run npm run build locally and rsync the public/build/ folder along with your code.
Best Practices & Checklist
Secure .env and secret keys
Never commit .env. On the server, run php artisan key:generate once and store the value safely. In Laravel 11, php artisan key:rotate lets you rotate the key without breaking encrypted data, which is useful after a suspected leak.
Run php artisan route:cache
On production, after clearing and warming caches, run php artisan route:cache and php artisan view:cache to compile the framework for maximum throughput. Always clear the cache first to avoid shipping a stale file from a previous deploy.
Use asset versioning with Vite
Vite's manifest.json includes content hashes by default, so you can safely enable far-future cache headers on public/build/. This keeps users from re-downloading assets after every deploy and removes a class of 404s caused by outdated asset references.
Regularly update PHP and Laravel
Laravel 11.x on PHP 8.2+ is the supported combination in 2026. Running anything older is asking for deprecation warnings, dropped security patches, and obscure 404s from unsupported route definitions. Update quarterly and test in a staging environment first.
Common Mistakes & Troubleshooting
Forgot to run php artisan migrate
If a route depends on a column or table that does not exist, Laravel will throw a 500, not a 404, but a misconfigured healthcheck or fallback route can convert that into a 404. Always run php artisan migrate --force as part of the deploy script.
Missing storage link
If profile pictures, PDFs, and other uploaded files return 404, the storage symlink is the most likely cause. Run php artisan storage:link and confirm public/storage exists and points at storage/app/public.
Incorrect APP_URL
Mismatched APP_URL breaks signed URLs, password reset links, and asset URLs. If those features 404, the URL is wrong, not the route. Set APP_URL=https://example.com (no trailing slash) and clear config cache.
Missing .htaccess in public folder
Without public/.htaccess, Apache does not forward requests to index.php. If you copied only app/, config/, and routes/ into your deploy, you forgot the most important folder. The public/ directory must contain index.php, .htaccess, and your built assets.
Who Should Use Which Fix? (Approach Table)
Use the table below to jump straight to the workflow that matches your setup. Each row is a tested path that maps a real persona to the recommended fix and the exact benefit you get.
| Target Persona | Recommended Option | Key Reason & Real-World Benefit |
|---|---|---|
| Developer on shared Hostinger hosting | Use hPanel document root + Fix File Ownership tool | Points the document root to public/ automatically and resets ownership in one click, eliminating the two most common 404 causes for shared hosting. |
| DevOps engineer on Ubuntu with Jenkins | Hardcoded Nginx server block + automated cache rebuild | Reproducible across every pipeline run, no .htaccess surprises, and zero manual intervention when you scale beyond a single server. |
| Team using Docker & Vite | Multi-stage Dockerfile with npm run build baked in |
Builds assets once inside the image, eliminates "works on my machine" 404s, and gives you a single artifact to ship. |
| Enterprise on Apache & PHP 8.2 | Centralized .htaccess with AllowOverride + route caching |
Leverages existing Apache infra while gaining Laravel's performance benefits through compiled routes and views. |