- 版本
root@VM-16-8-ubuntu:/etc/php/8.1/fpm/pool.d# ls
www.conf
root@VM-16-8-ubuntu:/etc/php/8.1/fpm/pool.d# nginx -v
nginx version: nginx/1.18.0 (Ubuntu)
root@VM-16-8-ubuntu:/etc/php/8.1/fpm/pool.d# php -v
PHP 8.1.2-1ubuntu2.14 (cli) (built: Aug 18 2023 11:41:11) (NTS)
Copyright (c) The PHP Group
Zend Engine v4.1.2, Copyright (c) Zend Technologies
with Zend OPcache v8.1.2-1ubuntu2.14, Copyright (c), by Zend Technologies
root@VM-16-8-ubuntu:/etc/php/8.1/fpm/pool.d# cat /etc/os-release
PRETTY_NAME="Ubuntu 22.04 LTS"
NAME="Ubuntu"
VERSION_ID="22.04"
VERSION="22.04 (Jammy Jellyfish)"
VERSION_CODENAME=jammy
ID=ubuntu
ID_LIKE=debian
HOME_URL="https://www.ubuntu.com/"
SUPPORT_URL="https://help.ubuntu.com/"
BUG_REPORT_URL="https://bugs.launchpad.net/ubuntu/"
PRIVACY_POLICY_URL="https://www.ubuntu.com/legal/terms-and-policies/privacy-policy"
UBUNTU_CODENAME=jammy
root@VM-16-8-ubuntu:/etc/php/8.1/fpm/pool.d#
-
問題 Failed to open stream: Permission denied
The stream or file "/srv/RwShopAi/storage/logs/laravel.log" could not be opened in append mode: Failed to open stream: Permission denied The exception occurred while attempting to log: The stream or file
image.png
其實萌壳,問題已經(jīng)明確告訴我們了荷科。就是沒有權(quán)限笔链。那么添加權(quán)限就可以了舰蟆。那么要怎么添加權(quán)限呢趣惠?
1.首先,查看一下php的運行用戶是誰身害?
root@VM-16-8-ubuntu:~# ps -ef |grep php
root 1824728 1 0 17:53 ? 00:00:00 php-fpm: master process (/etc/php/8.1/fpm/php-fpm.conf)
www-data 1824730 1824728 0 17:53 ? 00:00:00 php-fpm: pool www
www-data 1824731 1824728 0 17:53 ? 00:00:00 php-fpm: pool www
root 1831098 1831014 0 18:15 pts/1 00:00:00 grep --color=auto php
root@VM-16-8-ubuntu:~#
結(jié)論:php的運行用戶是www-data 用戶味悄。
那么直接修改storage的目錄權(quán)限,應(yīng)該就可以了塌鸯。
因此侍瑟,執(zhí)行:chown -R www-data.www-data storage/
就能解決這個問題。
【不推薦】當(dāng)然,也可以把php的運行用戶涨颜,改成root來運行费韭。容易有安全風(fēng)險。
可以查看nginx 其實也是使用www-data用戶庭瑰。那就改成www-data用戶運行星持,解決更加合理。后續(xù)弹灭,可以省去很多配置督暂,同時也保證了權(quán)限的安全。
root@VM-16-8-ubuntu:~# ps -ef |grep nginx
root 1819744 1 0 17:37 ? 00:00:00 nginx: master process /usr/sbin/nginx -g daemon on; master_process on;
www-data 1819745 1819744 0 17:37 ? 00:00:00 nginx: worker process
www-data 1819746 1819744 0 17:37 ? 00:00:00 nginx: worker process
root 1831823 1831014 0 18:18 pts/1 00:00:00 grep --color=auto nginx
root@VM-16-8-ubuntu:~#
進入項目目錄:
執(zhí)行命令:chown -R www-data.www-data storage/
drwxr-xr-x 5 www-data www-data 4096 Jan 13 17:35 storage/
至此穷吮,問題即可解決逻翁。