Ubuntu Laravel storage/logs/cron.log 权限被拒绝

Ubuntu Laravel storage/logs/cron.log 权限被拒绝

我有 Ubuntu 18.04、Laravel 和 PHP7.4。当我执行例如命令时,ls我会得到文件夹列表和:

user1@bpl:/var/www/html/storage$ ls
app  framework  logs
You have new mail in /var/mail/user1

当我这样做时,cat /var/mail/user1我有文件的内容:

From user1@bpl  Tue Mar  3 14:30:01 2020
Return-Path: <user1@bpl>
X-Original-To: user1
Delivered-To: user1@bpl
Received: by bpl (Postfix, from userid 1000)
        id 3264910126D; Tue,  3 Mar 2020 14:30:01 +0000 (UTC)
From: root@bpl (Cron Daemon)
To: user1@bpl
Subject: Cron <user1@bpl> $PHP $ARTISAN transaction:verify >> $LOGS 2>&1
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
X-Cron-Env: <PHP=/usr/bin/php>
X-Cron-Env: <ARTISAN=/var/www/html/artisan>
X-Cron-Env: <LOGS=/var/www/html/storage/logs/cron.log>
X-Cron-Env: <SHELL=/bin/sh>
X-Cron-Env: <HOME=/home/user1>
X-Cron-Env: <PATH=/usr/bin:/bin>
X-Cron-Env: <LOGNAME=user1>
Message-Id: <20200303143001.3264910126D@bpl>
Date: Tue,  3 Mar 2020 14:30:01 +0000 (UTC)

/bin/sh: 1: cannot create /var/www/html/storage/logs/cron.log: Permission denied

文件夹日志的权限如下:

user1@bpl:/var/www/html/storage$ ls -al
total 20
drwxrwxr-x  5 www-data www-data 4096 Feb 24 14:36 .
drwxr-xr-x 13 www-data www-data 4096 Feb 29 02:06 ..
drwxrwxr-x  3 www-data www-data 4096 Feb 28 15:13 app
drwxrwxr-x  6 www-data www-data 4096 Feb 24 14:36 framework
drwxrwxr-x  2 www-data www-data 4096 Mar  3 14:02 logs

任务事务验证来自 cron。此任务已添加到用户 cron。如何启用将这些日志写入此文件?

答案1

由于目录权限允许所有者和组进行写入(文件创建),因此可以使用www-data以下命令将自己添加到组中:

sudo adduser $USER www-data

新的组成员身份将在下次登录时生效。

相关内容