Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Exception handling app/logs/dev.log

Tags:

symfony

The stream or file "/home/nick/projects/Symfony/app/logs/dev.log" could not  
be opened: failed to open stream: Permission denied  

I get it in symfony. I know that I can go to app/logs and delete dev.log but this is happening to often and is annoying to delete it again and againand again.

Is there any way to make it just disapear?

LE: I guess, that I got the reply. I run the comands prefixed with sudo.

Eg: sudo php app/console generate:bundle --namespace=Acme/StoreBundle will work like a charm.

nick@ptb:~/projects/Symfony$ ls -al app/logs
total 76
drwxrwxrwx+ 2 nick     nick      4096 nov 24 15:16 .
drwxr-xr-x  6 nick     nick      4096 nov 24 15:28 ..
-rw-rw-r--+ 1 www-data www-data 59583 nov 24 16:25 dev.log
-rw-rw-r--+ 1 nick     nick         0 oct  6 15:55 .gitkeep
like image 453
crixi Avatar asked Feb 11 '23 12:02

crixi


2 Answers

I think that you create directory app/logs as sudo (root), so symfony doesn't have permissions to write into the file dev.log. Manually remove directory app/logs (and all contents), create it as normal user and setup up permissions, like they are described in the official documentation http://symfony.com/doc/current/book/installation.html.

Something like:

$ sudo rm -rf app/logs
$ mkdir app/logs
$ HTTPDUSER=`ps aux | grep -E '[a]pache|[h]ttpd|[_]www|[w]ww-data|[n]ginx' | grep -v root | head -1 | cut -d\  -f1`
$ sudo setfacl -R -m u:"$HTTPDUSER":rwX -m u:`whoami`:rwX app/cache app/logs
$ sudo setfacl -dR -m u:"$HTTPDUSER":rwX -m u:`whoami`:rwX app/cache app/logs

Or use any other option which is described in official documentation.

If this not works then please paste us result of command:

$ ls -al app/logs
like image 128
repincln Avatar answered Feb 19 '23 23:02

repincln


In my case, I used CentOS 7 and I solved it by set SELINUX=disabled as follow.

 - sudo nano /etc/selinux/config
 - Edit the file by set SELINUX=disabled
 - Restart again then it worked !

I tested and tried many method included chmod, chwon, setfacl, etc but it cannot solve the problem until I tried above solution and it worked!

like image 31
Khachornchit Songsaen Avatar answered Feb 20 '23 01:02

Khachornchit Songsaen