【问题标题】:Laravel No Existing Directory at "storage/logs"Laravel 在“存储/日志”中没有现有目录
【发布时间】:2019-03-28 06:14:41
【问题描述】:

我想用 Docker 运行 Laravel 5.7 应用程序。我的容器启动正常,但是当我尝试在浏览器中运行应用程序时出现错误。

在 “/Users/user/projects/laravel/application/storage/logs” 而不是 可构建:权限被拒绝

我更改了整个项目的权限...

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

然而,一切都没有改变。这个问题还能怎么解决?

这里是 docker-compose.yml 文件

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"

这是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 应用程序/存储

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

【问题讨论】:

标签: php laravel docker laravel-5.7


【解决方案1】:

试试这个命令,

php artisan optimize:clear

如果php artisan报错则执行,

composer update

【讨论】:

  • 谢谢。它对我有用。优化后,您需要再次使用 php artisan config:cache 配置缓存,然后运行 ​​php artisan storage:link
  • 我多年来一直在使用 Laravel,并且我的首选清除命令映射到:php artisan cache:clear && php artisan config:clear && php artisan route:clear && php artisan view:clear && php artisan clear-compiled 我知道优化,但它经常破坏我的应用程序(容器、权限)。优化:清除对我来说是新的。它就像一个魅力。哇。 :-)
【解决方案2】:

似乎配置中的 APP_LOG_FILE 引用了主机的日志文件路径(即/Users/user/projects/laravel/application/storage/logs)并设置为绝对路径,但在容器内部路径不同,实际上是/var/www/html/application/storage/logs。能不能在.env里改一下再试试?

【讨论】:

  • 我尝试添加APP_LOG_FILE=laravel.log,运行php artisan cache:clear && php artisan config:cache,但没有成功。我还尝试将日志目录挂载到容器中的另一个目录,但它也没有帮助。也许我做错了什么?
  • 如果你设置了APP_LOG_FILE=/var/www/html/application/storage/logs/laravel.log,你能用错误信息更新问题吗?
  • 消息没有改变。这是在指责/Users/user/projects/laravel/application/storage/logs目录
  • 好的,你能做到以下几点:用docker-compose up启动你的容器,然后到docker ps -a并复制php容器的名称。然后docker exec -it <name of php container> bash,然后一旦你进入容器的bash,显示cat .env的输出
  • 您的建议有帮助!只需在容器内运行php artisan cache:config 而不是在主机上运行)非常感谢您的帮助
【解决方案3】:

您需要在容器文件夹而不是您的操作系统文件夹中执行php artisan config:cache 命令。
在你的 php 容器中输入:
docker exec -it your-php-container /bin/bash
进入 laravel 项目文件夹并配置缓存:
php artisan config:cache

【讨论】:

    猜你喜欢
    • 2019-07-20
    • 2019-09-08
    • 1970-01-01
    • 1970-01-01
    • 2018-12-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多