Laravel 5.6路由失效问题求助:Homestead环境异常缓存现象
Hey there, I totally get how head-scratching this must be—especially since you’re not new to Laravel and the initial load worked fine. Let’s break down the most likely fixes for this weird "welcome page won’t go away" issue:
1. Nuke All Laravel Caches (The Big Cleanup)
First, let’s make sure none of Laravel’s cached files are holding onto old data. Run these commands from your project root (either on your host machine in the project directory, or via vagrant ssh inside the Homestead VM):
php artisan cache:clearphp artisan route:clearphp artisan config:clearphp artisan view:clear- For a one-shot full clear, use
php artisan optimize:clear—this wipes every cached file in one go.
2. Verify Homestead Shared Directory Sync
Homestead (especially with VirtualBox) can sometimes have sync delays where your host machine’s changes don’t show up in the VM immediately. Let’s confirm the changes actually made it:
- SSH into your VM:
vagrant ssh - Navigate to your project directory (usually
cd ~/code/your-project-name) - Check if
routes/web.phpis really empty:cat routes/web.php - Confirm
welcome.blade.phpis gone:ls resources/views
If the files don’t match what you see on your host, try reloading the VM withvagrant reload --provisionto force a sync.
3. Bust Browser Cache (Don’t Overlook This!)
Browsers love caching static-looking pages like the Laravel welcome screen. Try:
- A hard refresh: Ctrl+Shift+R (Windows/Linux) or Cmd+Shift+R (Mac)
- Opening the site in incognito/private browsing mode to bypass cached data
4. Restart Nginx and PHP-FPM
Sometimes the web server or PHP process holds onto cached data too. Inside the Homestead VM:
- Restart Nginx:
sudo service nginx restart - Restart PHP-FPM (match your PHP version—e.g., for PHP 8.2):
sudo service php8.2-fpm restart
5. Check for OPcache Interference
PHP’s OPcache can cache route files even after you’ve modified them. To rule this out:
- You can temporarily disable OPcache by editing your php.ini file (inside the VM, usually at
/etc/php/8.2/fpm/php.ini) and settingopcache.enable=0, then restart PHP-FPM. - Even if you don’t disable it, restarting PHP-FPM (from step 4) will clear the OPcache.
6. Double-Check Your Homestead Site Configuration
Make sure Nginx is pointing to your project’s public directory, not the root project folder. Open your Homestead.yaml file and verify the sites section looks like this:
sites: - map: your-app.test to: /home/vagrant/code/your-project/public
If you had to adjust this, run vagrant provision to apply the changes.
7. Manually Remove Cache Files (Just in Case)
If all else fails, manually delete the bootstrap cache directory inside your project:
- On host or VM:
rm -rf bootstrap/cache/*
This ensures no leftover cached routes, configs, or views are lingering.
Most of the time, this issue boils down to some layer of cache (Laravel, browser, server, or OPcache) or a sync delay between your host and Homestead VM. Since you’ve already ruled out basic route issues, these steps should get you back on track.
内容的提问来源于stack exchange,提问作者Jaguar

