Laravel 和 Docker:无法打开流或文件“/var/www/html/storage/logs/laravel.log”:无法打开流:权限被拒绝
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/50552970/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Laravel & Docker: The stream or file "/var/www/html/storage/logs/laravel.log" could not be opened: failed to open stream: Permission denied
提问by ltdev
This is my folder structure:
这是我的文件夹结构:
+-- root-app-dir
| +-- docker
| | +-- Dockerfile
| | +-- nginx.conf
| +-- src // this is where the Laravel app lives
| +-- docker-compose.yml
This is my docker-compose.yml
这是我的 docker-compose.yml
version: '2'
services:
app:
build:
context: ./docker
dockerfile: Dockerfile
image: lykos/laravel
volumes:
- ./src/:/var/www/html/
networks:
- app-network
nginx:
image: nginx:latest
volumes:
- ./src/:/var/www/html/
- ./docker/nginx.conf:/etc/nginx/conf.d/default.conf
ports:
- 8000:80
networks:
- app-network
mysql:
image: mysql:5.7
ports:
- "4306:3306"
environment:
MYSQL_DATABASE: homestead
MYSQL_USER: homestead
MYSQL_PASSWORD: secret
MYSQL_ROOT_PASSWORD: secret
volumes:
- mysqldata:/var/lib/mysql
networks:
- app-network
phpmyadmin:
image: phpmyadmin/phpmyadmin
ports:
- 8080:80
links:
- mysql
environment:
PMA_HOST: mysql
volumes:
mysqldata:
driver: "local"
networks:
app-network:
driver: "bridge"
This is my nginx.conf
这是我的 nginx.conf
server {
root /var/www/html/public;
index index.html index.htm index.php;
server_name _;
charset utf-8;
location = /favicon.ico { log_not_found off; access_log off; }
location = /robots.txt { log_not_found off; access_log off; }
location / {
try_files $uri $uri/ /index.php$is_args$args;
}
location ~ \.php$ {
# include snippets/fastcgi-php.conf;
include fastcgi_params;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
fastcgi_param PATH_INFO $fastcgi_path_info;
fastcgi_pass app:9000;
fastcgi_index index.php;
}
error_page 404 /index.php;
location ~ /\.ht {
deny all;
}
}
When I run docker-compose up -d
and try to access the Laravel app through the htts://localhost:8000
I get this error on my screen
当我运行docker-compose up -d
并尝试通过htts://localhost:8000
我的屏幕上出现此错误来访问 Laravel 应用程序时
UnexpectedValueException
The stream or file "/var/www/html/storage/logs/laravel.log" could not be opened: failed to open stream: Permission denied
I have run sudo chown lykos:lykos -R ./src
from my root-app-dir
but the issue is still there. How can I fix this?
我已经逃离sudo chown lykos:lykos -R ./src
了我的,root-app-dir
但问题仍然存在。我怎样才能解决这个问题?
回答by Tooschee
There are several options, what could be wrong:
有几种选择,可能是什么问题:
- The
storage
link isn't properly set, you can read about it here, after launchingapp
container, you should dophp artisan storage:link
to check whether proper link is there - You don't have the proper right for the given folder, from default,
logs
folder should havewww-data
writable rights, you can check that by ssh to machine and the dols -l
on files in/var/www/html/[your laravel app]
, if not, add the proper rights by:chown -R www-data:www-data *
- Also related to file permissions: you can disable SELinux (but only in dev server, never do it on live) by cehcking the status:
sestatus
and then enforcing it to0
bysetenforce 0
(however on live server, it's better to leave SElinux running and try to disable the problem bychcon -R -t httpd_sys_rw_content_t [path to storage folder here]
- 该
storage
链接设置不正确,你可以看到它在这里,发射后app
的容器,你应该做的php artisan storage:link
检查适当的链接是否存在 - 您没有给定文件夹的正确权限,默认情况下,
logs
文件夹应该具有www-data
可写权限,您可以通过 ssh 来检查机器和ls -l
对文件的操作/var/www/html/[your laravel app]
,如果没有,请通过以下方式添加正确的权限:chown -R www-data:www-data *
- 也涉及到文件权限:您可以通过cehcking状态禁用SELinux(但只能在开发服务器,从来没有做到这一点活)
sestatus
,然后执行,以0
通过setenforce 0
(不论活的服务器上,这是更好地让SELinux的运行,并尝试禁用问题由chcon -R -t httpd_sys_rw_content_t [path to storage folder here]
回答by popoyvargas
from Tooschee's answer,chcon -R -t httpd_sys_rw_content_t [path to storage folder here]
worked for me.
来自 Tooschee 的回答,chcon -R -t httpd_sys_rw_content_t [path to storage folder here]
对我来说有效。