10

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
Satendra Rawat
  • 1,264
  • 11
  • 23
Anastasia
  • 315
  • 1
  • 3
  • 13
  • /users ? are you sure that folder even exists? – YouriKoeman Oct 23 '18 at 22:42
  • Well, have you tried creating the directory? – miken32 Oct 23 '18 at 22:43
  • 1
    Has this code been tested/developed on a windows host perhaps? – YouriKoeman Oct 23 '18 at 22:44
  • 1
    are you mapping a local folder to your docker container? if so, you need to use the mapped location. – MrE Oct 24 '18 at 00:30
  • @YouriKoeman , yes, I am sure that directory exists. The code was developed on Mac – Anastasia Oct 24 '18 at 06:29
  • @miken32 , I've created the directory and everything was OK. I also tried to run with created directory and without – Anastasia Oct 24 '18 at 06:30
  • @MrE, Yes, I mapped folder and mapping was successful – Anastasia Oct 24 '18 at 06:31
  • do you have docker configured in nu s uid mode? – YouriKoeman Oct 24 '18 at 06:34
  • @Anastasia , 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 build – Alexey Oct 24 '18 at 06:57
  • 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 containers – Alexey Oct 24 '18 at 10:50
  • @Alexey I've updated the question, thanks) – Anastasia Oct 24 '18 at 12:57
  • This is the solution to this question https://stackoverflow.com/questions/51041196/there-is-no-existing-directory-at-storage-logs-and-its-not-buildable-permissio/55474102#55474102 – Vikas Rinvi Jun 21 '19 at 19:05
  • 1
    Possible duplicate of [There is no existing directory at /storage/logs and its not buildable: Permission denied](https://stackoverflow.com/questions/51041196/there-is-no-existing-directory-at-storage-logs-and-its-not-buildable-permissio) – Vikas Rinvi Jun 21 '19 at 19:09

3 Answers3

15

Try this command,

php artisan optimize:clear

If php artisan gives error then execute,

composer update
TAbdiukov
  • 1,185
  • 3
  • 12
  • 25
Satendra Rawat
  • 1,264
  • 11
  • 23
  • 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:link – Invincible Jun 14 '20 at 10:55
  • 1
    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. :-) – Jakub Nov 03 '20 at 07:15
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?

Alexey
  • 3,414
  • 7
  • 26
  • 44
  • 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? – Anastasia Oct 24 '18 at 19:43
  • can you update the question with the error message if you set your `APP_LOG_FILE=/var/www/html/application/storage/logs/laravel.log` ? – Alexey Oct 25 '18 at 06:07
  • message did not change. It was blaming `/Users/user/projects/laravel/application/storage/logs` directory – Anastasia Oct 25 '18 at 07:24
  • 1
    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 bash` and then once you're in the container's bash, show the output of `cat .env` – Alexey Oct 25 '18 at 09:01
  • 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 problem – Anastasia Oct 25 '18 at 15:12
  • 2
    your advice helped! It was just necessary to run `php artisan cache:config` inside container but not on host machine) Thanks a lot for help – Anastasia Oct 25 '18 at 15:15
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