0

I have linux:

Linux version 3.10.0-693.21.1.el7.x86_64 (builder@kbuilder.dev.centos.org) (gcc version 4.8.5 20150623 (Red Hat 4.8.5-16) (GCC) ) #1 SMP Wed Mar 7 19:03:37 UTC 2018

If I set the permission to 777 on storage, laravel works, but if I set it to 755 or 775 it says:

"The stream or file "/home/admin/domains/linkshift.eu/public_html/storage/logs/laravel-2018-11-08.log" could not be opened: failed to open stream: Permission denied"

I have tried searching for an answer, but nothing else worked, I have tried doing Permissions Issue with Laravel on CentOS but it still doesn't work

Edit: I also have direct admin installed

Aivaras77
  • 11
  • 1
  • 5

2 Answers2

1

Look like the log file is generated using root user and you are running the laravel from a different user. Make sure the log file is written by same user. Or give permission to your user.

sudo chown -R laravel-user:laravel-user /path/to/your/laravel/root/directory

Run these commands after every deploy

chmod -R 775 storage/framework
chmod -R 775 storage/logs
chmod -R 775 bootstrap/cache

Still If not working, It can maybe also because of SELinux.

Check selinux status on terminal:

sestatus

If status is enabled, write command for disable SElinux (not recommended)

setenforce Permissive

or you can do like below.

yum install policycoreutils-python -y # might not be necessary, try the below first

semanage fcontext -a -t httpd_sys_rw_content_t "/path/to/your/laravel/root/directory/storage(/.*)?" # add a new httpd read write content to sellinux for the specific folder, -m for modify
semanage fcontext -a -t httpd_sys_rw_content_t "/path/to/your/laravel/root/directory/bootstrap/cache(/.*)?" # same as the above for b/cache

restorecon -Rv /var/www/html/ # this command is very important to, it's like a restart to apply the new rules

Selinux is intended to restrict access even to root users, so only the necessary stuff might be accessed, at least on a generalist overview, it's extra security, disabling it is not a good practise, there are many links to learn Selinux, but for this case it is not even required.

marc_s
  • 732,580
  • 175
  • 1,330
  • 1,459
localroot
  • 566
  • 3
  • 13
-2

Could you show the result of

ls -l /home/admin/domains/linkshift.eu/public_html/storage/logs

and have you tried

php artisan config:cache
php artisan config:clear
composer dump-autoload -o
Mou Hsiao
  • 346
  • 2
  • 7
  • total 16 -rwxrwxrwx. 1 apache apache 14827 Nov 8 03:02 laravel-2018-11-08.log – Aivaras77 Nov 08 '18 at 10:16
  • I tried everything after doing chmod -R 775 storage, but still The stream or file "/home/admin/domains/linkshift.eu/public_html/storage/logs/laravel-2018-11-08.log" could not be opened: failed to open stream: Permission denied – Aivaras77 Nov 08 '18 at 10:19
  • to confirm the name of user of your http server (which is assumed to be apache:apache here), try delete laravel-2018-11-09.log, and set the permission to 777 on storage again, then trigger a execution which writes logs to let apache create a new laravel-2018-11-09.log, and then do ls -l again to see its ownership? – Mou Hsiao Nov 08 '18 at 16:38
  • "total 0" is the output after I did what you said – Aivaras77 Nov 08 '18 at 18:43