- 版本
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
其实,问题已经明确告诉我们了。就是没有权限。那么添加权限就可以了。那么要怎么添加权限呢?
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:~#
结论:php的运行用户是www-data 用户。
那么直接修改storage的目录权限,应该就可以了。
因此,执行:chown -R www-data.www-data storage/
就能解决这个问题。
【不推荐】当然,也可以把php的运行用户,改成root来运行。容易有安全风险。
可以查看nginx 其实也是使用www-data用户。那就改成www-data用户运行,解决更加合理。后续,可以省去很多配置,同时也保证了权限的安全。
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:~#
进入项目目录:
执行命令:chown -R www-data.www-data storage/
drwxr-xr-x 5 www-data www-data 4096 Jan 13 17:35 storage/
至此,问题即可解决。