Laravel 5.6符号链接异常:图片路径存在却返回404 Not Found
Troubleshooting Laravel Storage Image 404 on Virtual Host
Hey there, sorry you've been stuck on this for two days—let's break down the possible issues and fixes step by step:
1. Verify Laravel's Public Directory Setup (Critical!)
First, double-check if your Laravel app is deployed correctly for the virtual host:
- Laravel's public directory should be the document root of your virtual host (usually
public_html). If you've kept the Laravel core in/home/dtruxpgw/repositories/SoukElfalah, you need to ensure:- Either your
public_htmlis symlinked to/home/dtruxpgw/repositories/SoukElfalah/public - Or you've copied all files from
/home/dtruxpgw/repositories/SoukElfalah/publicintopublic_html, and updated theindex.phpinpublic_htmlto point to the correct Laravel core paths:// Update these lines in public_html/index.php require __DIR__.'/../repositories/SoukElfalah/vendor/autoload.php'; $app = require_once __DIR__.'/../repositories/SoukElfalah/bootstrap/app.php';
- Either your
If this setup is wrong, the asset() helper will generate URLs that don't map to your actual storage symlink.
2. Validate File & Directory Permissions (Beyond Just 775)
Your symlink exists, but the target files/directories might not be accessible to the web server:
- First, find out which user your web server runs as (Apache/Nginx):
# For Apache ps aux | grep httpd | head -n 1 # For Nginx ps aux | grep nginx | head -n 1 - Set the correct ownership so the web server can read the files:
# Replace "www-data" with your web server user (e.g., nobody, apache) chown -R dtruxpgw:www-data /home/dtruxpgw/repositories/SoukElfalah/storage - Also, verify the permissions on the actual image files:
Files should have at leastls -la /home/dtruxpgw/repositories/SoukElfalah/storage/app/public/images/thumbs/644permissions, directories755.
3. Check Laravel Environment Configuration
- Ensure your
.envfile has the correctAPP_URLset to your actual domain:
TheAPP_URL=https://your-domain.comasset()helper uses this value to generate full URLs—if it's set tolocalhostor an incorrect domain, the image URLs will be invalid. - Clear Laravel's config and route cache to apply changes:
php artisan config:clear php artisan cache:clear
4. Test Direct Access & Server Logs
- Try accessing an image directly via browser:
https://your-domain.com/storage/images/thumbs/default.png - If it still 404s, check your web server's error logs for specific details:
- Apache: Usually located at
/var/log/httpd/error_logor/var/log/apache2/error.log - Nginx:
/var/log/nginx/error.log
Logs will tell you if it's a permission issue, path mismatch, or symlink restriction.
- Apache: Usually located at
5. Check Virtual Host Security Restrictions
Some virtual hosts have security settings that block symlinks to directories outside the document root:
- Look for
open_basedirrestrictions in your PHP config (check viaphpinfo()). If your storage directory isn't included, you'll need to add it (contact your host if you can't edit this yourself). - Ensure your Apache/Nginx config has
Options FollowSymLinksenabled for thepublic_htmldirectory to allow following symlinks.
Quick Sanity Check
Double-check that the image files actually exist in the target directory:
ls /home/dtruxpgw/repositories/SoukElfalah/storage/app/public/images/thumbs/
Make sure default.png and your other images are present there.
内容的提问来源于stack exchange,提问作者harounbest
相关产品推荐
相关产品推荐

