Laravel & Docker: The stream or file "/var/www/html/storage/logs/laravel.log" could not be opened: failed to open stream: Permission denied

Stefan Izdrail

Founder & Senior Architect · 2026-06-29

Laravel Company
Title: Laravel & Docker: Fixing Permission Issues with Storage Logs Laravel and Docker are powerful tools that can help streamline your development workflow by providing a consistent environment across different environments. However, when using these technologies together, you may encounter permission related issues, such as the one mentioned in your scenario. In this comprehensive blog post, we will discuss the potential causes of the error `The stream or file "/var/www/html/storage/logs/laravel.log" could not be opened: failed to open stream: Permission denied` and provide a step-by-step guide on how to resolve it for your Laravel application running in Docker containers. 1. Ensure the correct user and group ownership: To ensure that Laravel can properly access and write to its logs directory, you must first check that the owner of your Laravel app (in this case, 'lykos') has the necessary permissions on both the source code folder (src) as well as the storage/logs directory. You can run `ls -l` to view the current file and directory ownership information: ```bash ls -l -R | grep src # Check the user and group for the 'src' folder ls -l -R | grep storage/logs # Check the user and group for the 'storage/logs' folder ``` 2. If your current ownership is not correct, you can change it by running the following command from your root-app-dir: ```bash sudo chown -R lykos:lykos ./src # Change the user and group of 'src' to 'lykos' and its associated group sudo chown -R lykos:lykos ./storage/logs # Change the user and group of 'storage/logs' to 'lykos' and its associated group ``` 3. Make sure your docker-compose.yml file is properly configured for Laravel access: In your Dockerfile, you have mounted the source code folder as follows: `volumes: - ./src/:/var/www/html/`. However, this volume mapping is not set up correctly in your docker-compose.yml file: ```diff - wrong code ... volumes: # Change to proper configuration - ./src/:/var/www/html/storage ... - correct code ... volumes: - ./src/:/var/www/html/ # No need for storage folder mapping, as Laravel will create it automatically ... ``` 4. After making the changes, you must rebuild your images and restart your containers to reflect the new configuration. Run `docker-compose up -d` again: ```bash docker-compose up -d # Rebuilds images and restarts all containers using the updated configuration ``` 5. Verify the permission issue is fixed: Check your Laravel app's logs by visiting `http://localhost:8000/storage/logs` or accessing the log files directly through a browser or file explorer. If you can now view and create new log files, the issue should be resolved. In conclusion, this issue was likely caused by incorrect ownership of your Laravel app's files and folders within your Docker containers. By following these steps and ensuring proper configuration throughout your project, you can effectively eliminate this error in your development workflow. Remember to keep your codebase structured well and always use the latest software versions for better security practices.