新建了一个 Laravel 的计划任务,配置好 crontab

* * * * * php /www/sunzhongwei/artisan schedule:run >> /dev/null 2>&1

同时,将当前登录用户,添加到了 www-data 的用户组,以防止无法访问 storage/logs 下的日志文件。

但是,执行了一段时间,导致 web 请求报错

file_put_contents(/www/sunzhongwei/storage/framework/cache/data/f1/6c/f16xxxx56b65501434d05bf1fc20c9fc8f9): failed to open stream: No such file or directo
ry

通过 ls -la 查看,可以发现该文件属于当前登录用户,而不是 www-data,用户组也不是 www-data 所属的用户组。

那就说明解决方法只有一个,就是以 www-data 的身份执行 laravel crontab 的计划任务。

对应的命令是

sudo crontab -u www-data -e

然后把上面的计划任务配置剪切过来就可以了。

测试环境

Ubuntu 16.04 Server

参考

https://askubuntu.com/questions/189189/how-to-run-crontab-as-userwww-data

相关文章:

  • 2021-07-10
  • 2021-08-14
  • 2022-12-23
  • 2022-12-23
猜你喜欢
  • 2022-12-23
  • 2021-11-18
  • 2021-09-04
  • 2022-01-19
  • 2021-12-01
  • 2021-12-01
相关资源
相似解决方案