Search code examples
laraveldockernginxlaradock

Laradock 404 Not Found Files with Symlink to Storage


I Created a Laravel app and I am using a windows PC in combination with Docker and Laradock. Docker runs on WSL2 but mounted to my windows drives (I know, it is very slow and I should switch to working in the Linux Filesystem).

I want to use Laravel's filesystem because I use envoyer to deploy my app. Therefor I created a symlink from public/storage to storage/app/public (default) with php artisan storage:link in the workspace container.

My IDE (PHPStorm) correctly displays the files from the link. Uploading images and thus moving them to the storage folder works as well.

The problem with Laradock (local development setup) is that if I use the URL from the asset() function (mywebsite.test/storage/file.txt for example), I get 404 Not Found. This problem does not persist on my staging linux server. Everything works fine over there.

Someone any idea what the problem could be?


Solution

  • Apparently the issue was that you should always make the symlink in the workspace container. My process was the following:

    • docker-compose down
    • docker-compose up
    • docker ps to get workspace container id
    • docker exec -it [workspace-container-id] bash
    • php artisan storage:link in project folder. If this does not work, you can create it manualy from the public folder with ln -sf ../storage/app/public storage