Centos Laravel权限拒绝如何更改权限?

3

您好,我的CentOS机器在尝试操作时返回了权限错误。

"无法以追加模式打开流或文件“/usr/share/nginx/html/storage/logs/laravel.log”:打开流失败:权限被拒绝"

我尝试过:

 chown -R nginx:nginx /usr/share/nginx/html
 chown -R root:root /usr/share/nginx/html
 chown -R root:root /usr/share/nginx/html/*
 chown -R nginx:nginx /usr/share/nginx/html/*
 chown -R $USER:$USER /usr/share/nginx/html
 sudo chmod -R 777 /usr/share/nginx/html/storage
 chmod -R 775 storage/framework
chmod -R 775 storage/framework
chmod -R 775 storage/logs

但是没有任何改变。可能出了什么问题?我应该学习“应该授予哪个用户权限”吗?


请运行以下命令:ls -ld /usr/share/nginx/html/storage/logs/laravel.log,并将输出结果发布在这里。 - RavinderSingh13
1个回答

3
# if group is nginx then
# owner is root
chown -R root:nginx /usr/share/nginx/html

# any files/folder created will inherit permission of the group of the parent
chmod -R 2755 /usr/share/nginx/html

# if already there are some folder and file
# we're changing permission here

# directory permission
find /usr/share/nginx/html -type d -exec chmod 2755 {} \;

# file permission
find /usr/share/nginx/html -type f -exec chmod 0644 {} \;

# nginx group can write logs
# group nginx can read-write-execute for logs
# you can use same if you're having cache/upload directory 

setfacl -R -m g:nginx:rwx /usr/share/nginx/html/storage/logs
如果启用了SELINUX,那么
# default 
semanage fcontext -a  -t httpd_sys_content_t '/usr/share/nginx/html(/.*)?'

# Here we make persistent changes in semanage fcontext for log path
# now httpd can write log  
semanage fcontext -a  -t httpd_sys_rw_content_t '/usr/share/nginx/html/storage/logs(/.*)?'

# restore selinux context
restorecon -Rv '/usr/share/nginx/html/storage/logs(/.*)?'

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接