【问题标题】:Centos Laravel Permission denied how to change permissions?Centos Laravel Permission denied 如何更改权限?
【发布时间】:2021-08-31 09:44:35
【问题描述】:

您好,我的 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 然后在此处发布输出。

标签: nginx centos


【解决方案1】:
# 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(/.*)?'

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2018-03-26
    • 2019-10-23
    • 2018-12-13
    • 2020-07-30
    • 2011-12-04
    相关资源
    最近更新 更多