You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

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_html is symlinked to /home/dtruxpgw/repositories/SoukElfalah/public
    • Or you've copied all files from /home/dtruxpgw/repositories/SoukElfalah/public into public_html, and updated the index.php in public_html to 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';
      

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:
    ls -la /home/dtruxpgw/repositories/SoukElfalah/storage/app/public/images/thumbs/
    
    Files should have at least 644 permissions, directories 755.

3. Check Laravel Environment Configuration

  • Ensure your .env file has the correct APP_URL set to your actual domain:
    APP_URL=https://your-domain.com
    
    The asset() helper uses this value to generate full URLs—if it's set to localhost or 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_log or /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.

5. Check Virtual Host Security Restrictions

Some virtual hosts have security settings that block symlinks to directories outside the document root:

  • Look for open_basedir restrictions in your PHP config (check via phpinfo()). 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 FollowSymLinks enabled for the public_html directory 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

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.05.12 04:13:06