我正在使用Docker创建一个laravel应用程序。
我的Dockerfile:
FROM alpine:3.6
ENV LANG="fr_FR.UTF-8" \
LC_ALL="fr_FR.UTF-8" \
LANGUAGE="fr_FR.UTF-8" \
TERM="xterm" \
COMPOSER_ALLOW_SUPERUSER=1
EXPOSE 80
RUN apk add --no-cache \
shadow \
nginx \
git \
curl \
wget \
bash \
supervisor \
php7 \
php7-common \
php7-fpm \
php7-dom \
php7-curl \
php7-phar \
php7-bcmath \
php7-intl \
php7-json \
php7-iconv \
php7-mcrypt \
php7-mbstring \
php7-pdo \
php7-pdo_mysql \
php7-zip \
php7-bcmath \
php7-opcache \
php7-apcu \
php7-imagick \
php7-xml \
php7-xmlwriter \
php7-ctype \
php7-tokenizer \
php7-session \
php7-simplexml \
php7-fileinfo \
php7-zlib \
openssl \
tzdata \
ca-certificates \
&& cp /usr/share/zoneinfo/Europe/Paris /etc/localtime && echo "Europe/Paris" > /etc/timezone \
&& curl -sS https://getcomposer.org/installer | php -- --install-dir=/usr/local/bin --filename=composer
WORKDIR /var/www
COPY composer.json composer.lock /var/www/
RUN composer install --prefer-dist --no-autoloader --no-interaction --no-ansi --no-dev
RUN set -x ; \
addgroup -g 82 -S www-data ; \
adduser -u 82 -D -S -G www-data www-data && exit 0 ; exit 1
COPY . /var/www/
RUN chown -R www-data:www-data storage
RUN chmod -R 775 storage
RUN chown -R www-data:www-data /var/www/storage
RUN chmod -R 775 /var/www/storage
RUN chown -R www-data:www-data docker
RUN mkdir -p var/cache && \
mkdir -p var/log && \
mkdir -p var/sessions && \
chown -R www-data:www-data var/cache && \
chmod -R 775 var/cache && \
chown -R www-data:www-data var/log && \
chmod -R 775 var/log && \
chown -R www-data:www-data var/sessions && \
chmod -R 775 var/sessions && \
mv docker/prod/php.ini /etc/php7/conf.d/50_settings.ini && \
composer dump-autoload && \
php artisan cache:clear && \
rm -rf /etc/supervisord.conf && \
mv docker/prod/supervisord.conf /etc/supervisord.conf && \
rm -rf /etc/nginx/nginx.conf && \
mv docker/prod/nginx.conf /etc/nginx/nginx.conf && \
chown -R www-data:www-data /var/www/bootstrap/cache && \
chmod -R 775 /var/www/bootstrap/cache && \
chown -R www-data:www-data storage/framework/views/ && \
chmod -R 775 storage/framework/views/ && \
chown -R www-data:www-data /var/tmp/nginx/
# Cleanup
RUN apk del git \
&& find / -type f -iname \*.apk-new -delete \
&& rm -rf /tmp/* /var/cache/apk/* /root/.composer
ADD docker/entrypoint.sh /entrypoint.sh
RUN chmod +x /entrypoint.sh
#entrypoint will take CMD as an argument
ENTRYPOINT ["/entrypoint.sh"]
CMD ["supervisord", "-c", "/etc/supervisord.conf"]
当我尝试提交表单时,出现以下错误:
The stream or file "/var/www/storage/logs/laravel.log" could not be opened: failed to open stream: Permission denied
我知道问题出在文件权限上,我检查了一下并准备存储:
drwxrwxr-x 5 www-data www-data 4096 Jul 19 12:20 storage
与其中的目录和文件相同。
我的nginx.conf:
daemon off;
user www-data;
worker_processes 5;
pid /run/nginx.pid;
error_log /dev/stdout info;
events {
worker_connections 2048;
# multi_accept on;
}
http {
access_log /dev/stdout;
##
# Basic Settings
##
sendfile on;
tcp_nopush on;
tcp_nodelay on;
keepalive_timeout 65;
types_hash_max_size 2048;
server_tokens off;
include /etc/nginx/mime.types;
default_type application/octet-stream;
client_max_body_size 10M;
client_body_buffer_size 256K;
##
# Gzip Settings
##
gzip on;
gzip_disable "msie6";
gzip_min_length 1000;
gzip_comp_level 6;
gzip_types text/plain text/css application/json application/javascript text/xml application/xml application/xml+rss text/javascript;
##
# Virtual Host Configs
##
server {
listen 80 default_server;
server_name _;
client_max_body_size 800M;
root /var/www/public;
#custom cors ici ?
add_header X-Content-Type-Options nosniff;
add_header X-XSS-Protection "1; mode=block";
add_header X-Frame-Options DENY;
#changements par oip ok ?
location / {
#root /var/www/public;
#try_files $uri $uri/ /index.html;
#index index.php;
#try_files $uri /index.php$is_args$args;
try_files $uri /index.php?$query_string;
}
#pas besoin car par d'images ?
# location ~* \.(ico|css|js|woff|jpg|jpeg|png|gif|svg)$ {
# root /oip/public/app;
# access_log off;
# log_not_found off;
# expires 365d;
# }
# pas besoin car configuré sur /
# location /rest {
# index index.php;
# try_files $uri /index.php$is_args$args;
# }
# non concerné
# location /sauth {
# index index.php;
# try_files $uri /index.php$is_args$args;
# }
location ~ \.php(/|$) {
internal;
fastcgi_pass 127.0.0.1:9000;
fastcgi_split_path_info ^(.+\.php)(/.*)$;
include fastcgi_params;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
#qu'implique APP_ENV ?
fastcgi_param APP_ENV prod;
# https off ?
fastcgi_param HTTPS off;
}
}
}
当我在存储中使用chmod 777时,它正在工作,但是我知道这样做不是很好。 我以为我的网络服务器正在使用www-data,但无法编写laravel.log 我应该怎么做才能解决这个问题?
经过一些测试,我发现我的应用程序laravel正在使用没有用户写入文件,我真的不知道为什么
答案 0 :(得分:0)
尝试:sudo chmod 775 ./storage
和sudo chmod 775 ./storage/logs
。
这赋予了应用程序将日志写入存储目录的权限。您也可以尝试使用FTP将权限更改为775。
如果这不起作用,请给文件夹777做一个成功的请求,然后将其放回775。有时也可以。 从不将其保持在777