Laravel No Existing Directory at "storage/logs"
Asked Answered
M

3

11

I want to run a Laravel 5.7 application with Docker. My containers start OK but when I try to run the app in the browser I get an error.

There is no existing directory at "/Users/user/projects/laravel/application/storage/logs" and its not buildable: Permission denied

I changed permissions for the whole project with...

sudo chmod -R 777 /Users/user/projects/laravel/application

However, nothing changed. How else can this issue be solved?

Here is the docker-compose.yml file

version: '3'
services:
  web:
    image: nginx
    volumes:
    - "./vhosts.conf:/etc/nginx/conf.d/vhosts.conf"
    - "./application/public:/var/www/html/application/public"
    - "./:/var/www/html"
    - "./logs/nginx/error.log:/var/log/nginx/error.log"
    - "./logs/nginx/access.log:/var/log/nginx/access.log"
    ports:
    - "8000:80"
    environment:
    - NGINX_HOST=ld2.web
    restart: always
    depends_on:
    - php
  php:
    image: php:7.2-fpm
    restart: always
    volumes:
    - "./application/storage/php/php.ini:/usr/local/etc/php/conf.d/php.ini"
    - "./application/public:/var/www/html/application/public"
    - "./:/var/www/html"

Here is an output of ls -ls application

drwxrwxrwx  26 user  staff     832 Oct 24 14:50 .
drwxrwxrwx   8 user  staff     256 Oct 24 01:06 ..
-rwxrwxrwx   1 user  staff     213 Sep  4 16:12 .editorconfig
-rwxrwxrwx   1 user  staff     704 Oct 24 00:38 .env
-rwxrwxrwx   1 user  staff     655 Sep  4 16:12 .env.example
-rwxrwxrwx   1 user  staff     111 Sep  4 16:12 .gitattributes
-rwxrwxrwx   1 user  staff     177 Sep  4 16:12 .gitignore
drwxrwxrwx   7 user  staff     224 Sep  4 16:12 app
-rw-r--r--   1 user  staff       0 Oct 24 14:56 application.txt
-rwxrwxrwx   1 user  staff    1686 Sep  4 16:12 artisan
drwxrwxrwx   4 user  staff     128 Sep  4 16:12 bootstrap
-rwxrwxrwx   1 user  staff    1527 Sep  4 16:12 composer.json
-rwxrwxrwx   1 user  staff  148959 Oct 24 00:35 composer.lock
drwxrwxrwx  15 user  staff     480 Sep  4 16:12 config
drwxrwxrwx   6 user  staff     192 Sep  4 16:12 database
-rwxrwxrwx   1 user  staff    1022 Sep  4 16:12 package.json
-rwxrwxrwx   1 user  staff    1134 Sep  4 16:12 phpunit.xml
drwxrwxrwx  10 user  staff     320 Sep  4 16:12 public
-rwxrwxrwx   1 user  staff    3924 Sep  4 16:12 readme.md
drwxrwxrwx   6 user  staff     192 Sep  4 16:12 resources
drwxrwxrwx   6 user  staff     192 Sep  4 16:12 routes
-rwxrwxrwx   1 user  staff     563 Sep  4 16:12 server.php
drwxrwxrwx   6 user  staff     192 Oct 24 01:20 storage
drwxrwxrwx   6 user  staff     192 Sep  4 16:12 tests
drwxrwxrwx  40 user  staff    1280 Oct 24 00:41 vendor
-rwxrwxrwx   1 user  staff     537 Sep  4 16:12 webpack.mix.js

ls -la application/storage

drwxrwxrwx   6 user  staff  192 Oct 24 01:20 .
drwxrwxrwx  27 user  staff  864 Oct 24 15:44 ..
drwxrwxrwx   4 user  staff  128 Sep  4 16:12 app
drwxrwxrwx   7 user  staff  224 Sep  4 16:12 framework
drwxrwxrwx   2 user  staff   64 Oct 24 01:20 logs
drwxrwxrwx   3 user  staff   96 Oct 24 00:43 php
Morbific answered 23/10, 2018 at 22:30 Comment(13)
/users ? are you sure that folder even exists?Cisalpine
Well, have you tried creating the directory?Rotter
Has this code been tested/developed on a windows host perhaps?Cisalpine
are you mapping a local folder to your docker container? if so, you need to use the mapped location.Adey
@YouriKoeman , yes, I am sure that directory exists. The code was developed on MacMorbific
@Rotter , I've created the directory and everything was OK. I also tried to run with created directory and withoutMorbific
@MrE, Yes, I mapped folder and mapping was successfulMorbific
do you have docker configured in nu s uid mode?Cisalpine
@Morbific , can you show your Dockerfile contents or docker-compose.yml in case you're using compose? The question MrE asked was: 1. if you really pass your directory into the container as a volume when launching it; 2. you used COPY command in your Dockerfile only when building the image and there was no logs at the time of the image buildArsenite
you can just update your question with contents formatted :) You can also update your question with the output of the following commands: ls -la ./application, ls -la ./application/storage and I think you can just remove extra volume mount from your docker-compose.yml "./application/public:/var/www/html/application/public" since you already mount the whole "./:/var/www/html" in both nginx and php containersArsenite
@Arsenite I've updated the question, thanks)Morbific
This is the solution to this question #51041696Carnay
Possible duplicate of There is no existing directory at /storage/logs and its not buildable: Permission deniedCarnay
A
8

Seems that your APP_LOG_FILE in the config references the logfile path for your host machine (i.e. /Users/user/projects/laravel/application/storage/logs) and set as absolute path, but inside your containter the path is different and in fact is /var/www/html/application/storage/logs. Can you change it in the .env and try again?

Arsenite answered 24/10, 2018 at 16:59 Comment(6)
I've tried to add APP_LOG_FILE=laravel.log, ran php artisan cache:clear && php artisan config:cache but it didn't work. I also tried to mount log directory to another one in container but it didn't help as well. Maybe I was doing something wrong?Morbific
can you update the question with the error message if you set your APP_LOG_FILE=/var/www/html/application/storage/logs/laravel.log ?Arsenite
message did not change. It was blaming /Users/user/projects/laravel/application/storage/logs directoryMorbific
ok, can you do the following: launch your containers with docker-compose up, then to docker ps -a and copy the name of php container. Then docker exec -it <name of php container> bash and then once you're in the container's bash, show the output of cat .envArsenite
I checked .env file inside container, line APP_LOG_FILE=/var/www/html/application/storage/logs/laravel.log is there but I still get the same problemMorbific
your advice helped! It was just necessary to run php artisan cache:config inside container but not on host machine) Thanks a lot for helpMorbific
J
18

Try this command,

php artisan optimize:clear

If php artisan gives error then execute,

composer update
Jac answered 21/6, 2019 at 20:4 Comment(2)
thanks. It worked for me. Once optimised, you need to configure cache again with php artisan config:cache and then run php artisan storage:linkStoughton
I've been using Laravel for years and had my go-to clear command mapped to: php artisan cache:clear && php artisan config:clear && php artisan route:clear && php artisan view:clear && php artisan clear-compiled I knew of optimize but it broke my app more often than not (containers, permissions). optimize:clear is new to me. And it works like a charm. Wow. :-)Indigestible
A
8

Seems that your APP_LOG_FILE in the config references the logfile path for your host machine (i.e. /Users/user/projects/laravel/application/storage/logs) and set as absolute path, but inside your containter the path is different and in fact is /var/www/html/application/storage/logs. Can you change it in the .env and try again?

Arsenite answered 24/10, 2018 at 16:59 Comment(6)
I've tried to add APP_LOG_FILE=laravel.log, ran php artisan cache:clear && php artisan config:cache but it didn't work. I also tried to mount log directory to another one in container but it didn't help as well. Maybe I was doing something wrong?Morbific
can you update the question with the error message if you set your APP_LOG_FILE=/var/www/html/application/storage/logs/laravel.log ?Arsenite
message did not change. It was blaming /Users/user/projects/laravel/application/storage/logs directoryMorbific
ok, can you do the following: launch your containers with docker-compose up, then to docker ps -a and copy the name of php container. Then docker exec -it <name of php container> bash and then once you're in the container's bash, show the output of cat .envArsenite
I checked .env file inside container, line APP_LOG_FILE=/var/www/html/application/storage/logs/laravel.log is there but I still get the same problemMorbific
your advice helped! It was just necessary to run php artisan cache:config inside container but not on host machine) Thanks a lot for helpMorbific
P
1

You need execute php artisan config:cache command in container folder instead of your OS folder.
Enter in your php container:
docker exec -it your-php-container /bin/bash
go to laravel project folder and configure cache:
php artisan config:cache

Pommel answered 5/8, 2019 at 16:44 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.