Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.

ennestudio's avatar

Laravel all media in public/media are in 404

Hello, I fighting with error 404. I'm working with laravel and spatie media library. On local machine all is working but on production server all media go in 404. I run php artisan storage:link BUT media inside media folder are in 404. I uploaded static media (like icons) in public/images and media inside that folder are working.

So the problem is only in public/media. Can someone help me? thanks

0 likes
3 replies
LaryAI's avatar
Level 58

It seems like the issue is with the media files inside the "public/media" folder not being accessible on the production server. Here are a few steps you can take to troubleshoot and resolve the issue:

  1. Verify the storage link:

    • Make sure that the storage link has been created correctly by running the php artisan storage:link command.
    • Check if the symbolic link has been created in the "public" directory and points to the "storage/app/public" directory.
  2. Check file permissions:

    • Ensure that the file permissions for the "public/media" folder and its contents are set correctly. The web server should have read access to these files.
    • You can try running the following command to set the correct permissions:
      chmod -R 755 public/media
      
  3. Check the file paths:

    • Verify that the file paths in your code are correct. Make sure that you are referencing the media files using the correct path, such as "/media/filename.jpg".
  4. Check the web server configuration:

    • Ensure that the web server (e.g., Apache or Nginx) is configured to allow access to the "public/media" folder.
    • For Apache, you can add the following directive to your virtual host configuration or .htaccess file:
      <Directory "/path/to/your/project/public/media">
          Options Indexes FollowSymLinks
          AllowOverride All
          Require all granted
      </Directory>
      
    • For Nginx, you can add the following location block to your server configuration:
      location /media {
          try_files $uri $uri/ /index.php?$query_string;
      }
      
  5. Clear cache and reload:

    • If you have made any changes to the configuration or code, clear the cache and reload the page to ensure that the changes take effect.

If the issue persists, it would be helpful to provide more information about your server environment and any error messages you are encountering.

Snapey's avatar

storage link only creates a symlink for public/storage

so your urls should probably be /storage/media/...,

ennestudio's avatar

thanks Snapey! I was writing that I solved with the help of A.I. It wrote some things that I missed.

very useful!

thanks Lary!

Please or to participate in this conversation.