Reputation: 799
Hi there my centos machine returns permission error when try to work.
"The stream or file "/usr/share/nginx/html/storage/logs/laravel.log" could not be opened in append mode: failed to open stream: Permission denied"
I tried;
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
But nothing changed. What could be wrong? How can I learn "which user should I give permission"?
Upvotes: 3
Views: 1384
Reputation: 16997
# 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
Enabled then# 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(/.*)?'
Upvotes: 3