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

vincent15000's avatar

Docker and logs permissions

Hello,

I have watched the entire series about docker on Laracast. A very good series, I have reproduced all the code and it works fine.

https://laracasts.com/series/the-docker-tutorial

I just have one problem when trying to load the application on the browser.

The stream or file "/var/www/html/storage/logs/laravel.log" could not be opened in append mode: Failed to open stream: Permission denied The exception occurred while attempting to log: The stream or file "/var/www/html/storage/logs/laravel.log" could not be opened in append mode: Failed to open stream: Permission denied

i'm using Ubuntu 22.04 and Laravel 11.

I specify that I have changed the permissions and the owner of the folders and files, but I have the same problem.

Can you guide me to solve this permission problem ?

Thanks a lot.

V

0 likes
1 reply
LaryAI's avatar
Level 58

Hello,

It sounds like you're encountering a common issue with Docker containers and Laravel where the web server inside the container does not have the necessary permissions to write to the storage and bootstrap/cache directories. Here's how you can resolve this issue:

  1. Ensure Permissions in Dockerfile: Make sure that your Dockerfile sets the correct permissions for the Laravel directories that need write access. You can do this by adding commands to change the ownership and permissions of the storage and bootstrap/cache directories to your Dockerfile. Here's an example snippet you might add:
# Set working directory
WORKDIR /var/www/html

# Copy existing application directory permissions
COPY --chown=www-data:www-data . /var/www/html

# Change ownership of the storage and cache
RUN chown -R www-data:www-data /var/www/html/storage /var/www/html/bootstrap/cache

# Change permissions of the storage and cache
RUN chmod -R 775 /var/www/html/storage /var/www/html/bootstrap/cache
  1. Set Permissions with Docker Compose: If you are using Docker Compose, you can set the permissions after the containers are up by using the docker-compose exec command. Here's how you can do it:
docker-compose exec app chown -R www-data:www-data /var/www/html/storage /var/www/html/bootstrap/cache
docker-compose exec app chmod -R 775 /var/www/html/storage /var/www/html/bootstrap/cache

Replace app with the name of your Laravel container service.

  1. Persistent Permissions: To ensure that permissions are correctly maintained when the Docker container is restarted, consider adding the permission commands to your container's entrypoint script or using them in the command override in your docker-compose.yml.

  2. Check User: Ensure that the user running the web server inside your Docker container (commonly www-data for Apache and PHP-FPM) matches the user you are setting permissions for.

  3. Debugging Further: If the issue persists, you can enter the container and manually check the permissions and ownership:

docker exec -it [container_id_or_name] bash
ls -la /var/www/html/storage/logs

This will show you the current permissions and owner of the logs directory, helping you to diagnose the issue.

By following these steps, you should be able to resolve the permission issues with your Laravel logs in Docker.

Please or to participate in this conversation.