这是我的文件夹结构:
+-- 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
我已从sudo chown lykos:lykos -R ./src
运行root-app-dir
,但问题仍然存在。我该如何解决这个问题?
答案 0 :(得分:6)
如果您使用的是 laravel 帆,请将以下内容添加到您的 .env 文件中
WWWGROUP=1000
WWWUSER=1000
答案 1 :(得分:5)
如果将上述内容添加到您的 .env 文件中时上述内容不起作用,则以下内容将:
sudo chmod o+w ./storage/ -R
这将在不更改用户和组权限的情况下授予其他人权限。
答案 2 :(得分:2)
有几种选择,可能出错:
storage
链接未正确设置,您可以阅读here,在启动app
容器后,您应该php artisan storage:link
检查是否正确链接在那里logs
文件夹应具有www-data
可写权限,您可以通过ssh检查到机器和do {{ 1}} ls -l
中的文件,如果没有,请按以下方式添加适当的权限:/var/www/html/[your laravel app]
chown -R www-data:wwww-data *
然后通过{{1强制执行sestatus
来禁用SELinux(但仅限在开发服务器中,永远不会在实时中执行) (但是在实时服务器上,最好让SElinux运行并尝试通过0
答案 3 :(得分:1)
答案 4 :(得分:0)
forEach