拉威尔&;Docker:无法打开流或文件";/var/www/html/storage/logs/laravel.log";:无法打开流:权限被拒绝 [英] Laravel & Docker: The stream or file "/var/www/html/storage/logs/laravel.log" could not be opened: failed to open stream: Permission denied
本文介绍了拉威尔&;Docker:无法打开流或文件";/var/www/html/storage/logs/laravel.log";:无法打开流:权限被拒绝的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
这是我的文件夹结构:
+-- root-app-dir
| +-- docker
| | +-- Dockerfile
| | +-- nginx.conf
| +-- src // this is where the Laravel app lives
| +-- 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"
这是我的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;
}
}
当我运行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
我已从我的root-app-dir
运行sudo chown lykos:lykos -R ./src
,但问题仍然存在。我如何修复此问题?
推荐答案
有几个选项,哪些选项可能出错:
storage
链接设置不正确,您可以查看here,启动app
容器后,应做php artisan storage:link
检查是否有正确链接- 您没有给定文件夹的适当权限,默认情况下,
logs
文件夹应具有www-data
可写权限,您可以通过ssh到计算机并对/var/www/html/[your laravel app]
中的文件执行ls -l
检查,如果没有,请通过chown -R www-data:www-data *
添加适当的权限
- 也与文件权限有关:您可以通过以下方式禁用SELinux(但仅限在dev服务器中,而不是在LIVE上):
sestatus
,然后通过setenforce 0
将其强制为0
(但在LIVE服务器上,最好让SElinux保持运行状态,并尝试通过chcon -R -t httpd_sys_rw_content_t [path to storage folder here]
禁用该问题
这篇关于拉威尔&;Docker:无法打开流或文件";/var/www/html/storage/logs/laravel.log";:无法打开流:权限被拒绝的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文