The stream or file var www storage logs laravel log could not be opened failed to open stream Permission denied

0 votes

I have two docker containers: Nginx and App.
The app container extends PHP-fpm and also has my Laravel Code.

In my docker-compose.yml I'm doing:

version: '2'
services:
    nginx:
        build:
            context: ./nginx
            dockerfile: ./Dockerfile
        ports:
            - "80:80"
        links:
            - app
    app:
        build:
            context: ./app
            dockerfile: ./Dockerfile

In my Nginx Dockerfile i'm doing:

FROM nginx:latest
WORKDIR /var/www
ADD ./nginx.conf /etc/nginx/conf.d/default.conf
ADD . /var/www
EXPOSE 80

In my App Dockerfile I'm doing:

FROM php:7-fpm
WORKDIR /var/www
RUN apt-get update && apt-get install -y libmcrypt-dev mysql-client && docker-php-ext-install mcrypt pdo_mysql
ADD . /var/www

After successfully running docker-compose up, I have the following error when I try localhost

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

From my understanding, the storage folder needs to writable by the webserver.
What should I be doing to resolve this?

Sep 30, 2020 in Laravel by kartik
• 37,520 points
21,534 views

1 answer to this question.

0 votes

Hello @kartik,

Make your Dockerfile something as below -

FROM php:7-fpm
WORKDIR /var/www
RUN apt-get update && apt-get install -y libmcrypt-dev mysql-client && docker-php-ext-install mcrypt pdo_mysql
ADD . /var/www
RUN chown -R www-data:www-data /var/www

This makes directory /var/www owned by www-data which is the default user for php-fpm.

Since it is compiled with user www-data.

Hope it helps!!

Thank You!!

answered Sep 30, 2020 by Niroj
• 82,840 points

Related Questions In Laravel

0 votes
1 answer

Error:Laravel 5 show ErrorException file_put_contents failed to open stream: No such file or directory

Hello @kartik, The best way to solve this ...READ MORE

answered Aug 10, 2020 in Laravel by Niroj
• 82,840 points
6,530 views
+2 votes
1 answer

Error: laravel.log could not be opened?

Hello, Never use 777 for directories on your ...READ MORE

answered Apr 2, 2020 in Laravel by Niroj
• 82,840 points
12,439 views
+1 vote
1 answer

Error:file_put_contents(meta/services.json): failed to open stream: Permission denied?

Hello @kartik, Below steps helped me fix the ...READ MORE

answered Apr 3, 2020 in Laravel by Niroj
• 82,840 points
8,717 views
+1 vote
1 answer

How to make anchor tag with routing using Laravel?

Hey @kartik, First you have to go to ...READ MORE

answered Mar 18, 2020 in Laravel by Niroj
• 82,840 points
23,087 views
0 votes
1 answer

What is redirection in Laravel?

Named route is used to give specific ...READ MORE

answered Mar 18, 2020 in Laravel by Niroj
• 82,840 points
3,017 views
0 votes
1 answer

How to install Laravel via composer?

Hello, This is simple you just need to ...READ MORE

answered Mar 23, 2020 in Laravel by Niroj
• 82,840 points
2,951 views
+1 vote
1 answer

What are named routes in Laravel and How can specify route names for controller actions?

Hey @kartik, Named routing is another amazing feature of ...READ MORE

answered Mar 23, 2020 in Laravel by Niroj
• 82,840 points
44,894 views
+1 vote
3 answers

Error: Exception file_put_contents failed to open stream: No such file or directory in Laravel?

Hello, You should typically run the php artisan config:cache command ...READ MORE

answered Mar 31, 2020 in Laravel by Niroj
• 82,840 points
48,894 views
0 votes
2 answers

Error:Failed to open stream: Permission denied in Laravel?

I had this problem lately with my ...READ MORE

answered Nov 4, 2020 in Laravel by anonymous
• 140 points
16,936 views
webinar REGISTER FOR FREE WEBINAR X
REGISTER NOW
webinar_success Thank you for registering Join Edureka Meetup community for 100+ Free Webinars each month JOIN MEETUP GROUP