1

I am working through Shawn McCool's book (great book) and each time I create a new view, and try to load it, I get a permissions error.

I am wondering why the views generated don't have read permissions. The odd thing is if I chmod to 775, I still get the error, I have to 777 then 775.

Can anyone shed some light on this and why it's happening?

Thanks!

Edit:

Error after adding new view

file_put_contents(/Users/jason/Sites/laravel1/storage/views/5c4b7b4707d658dffe52d481be6c680e): failed to open stream: Permission denied

Permissions on storage/views
drwxrwxr-x@  7 jason  jason  238 Mar  7 17:15 views

Permissions on new view -rw-r--r--

Error after chmod 775 views

 file_put_contents(/Users/jason/Sites/laravel1/storage/views/5c4b7b4707d658dffe52d481be6c680e): failed to open stream: Permission denied

Permissions after chmod 775 views

drwxrwxr-x@  7 jason  jason  238 Mar  7 17:15 views

After chmod 777 views, it works

drwxrwxrwx@  8 jason  jason  272 Mar  7 17:25 views

After chmod 777 views it still works

drwxrwxr-x@  8 jason  jason  272 Mar  7 17:25 views

But here is the twist, I did not have this issue if I didn't use viewname.blade.php. If I did viewname.php, there was no error. It seems to have something to do with Blade.

Edit 2:

Related: always make sure to .gitignore these files so that you don't end up with cached views, etc. getting pulled onto your server from your dev environment.

Jazzy
  • 6,029
  • 11
  • 50
  • 74
  • If permission is set to 775 then it is... – jtheman Mar 07 '13 at 23:44
  • @jtheman I don't follow. This is the behavior I am experiencing. I have to reset the permissions on the views dir each time. If I go straight to 775, I still get the error. – Jazzy Mar 07 '13 at 23:52
  • @shapeshifter is is in fact umask. It's set to 0022. Any idea how to overcome this without having to CHMOD each time I create a new view? And maybe answer the question since that is at least the root of my issue. – Jazzy Mar 07 '13 at 23:58
  • The problem doesn't really make sense. You are overwriting the previous 777 with 775. So the permissions are the same as just doing 775 first. See what the actual permissions on the file are, ls -la thefile between each chmod. – shapeshifter Mar 08 '13 at 00:02
  • You're right, it does not make sense. Regardless, when I add a new view, I get file_put_contents(/Users/jason/Sites/laravel1/storage/views/viewname): failed to open stream: Permission denied If I CHMOD 775 views and reload I get the same error. The CHMOD 777 and it works, then CHMOD 775 and it still works. I am about to paste the steps above in an edit. – Jazzy Mar 08 '13 at 00:22
  • 1
    Apache isn't running as the user "jason" it's running as "httpd" or "apache". `chown -R jason:apache /Users/jason/Sites` – Matthew Blancarte Mar 08 '13 at 00:30
  • Invalid argument was returned. But this points me in the right direction. – Jazzy Mar 08 '13 at 01:54
  • 1
    @Jason If you use the blade engine, your storage folder is utilised to hold a cached copy of the view, hence your permission problems. Without the blade engine, the view is just `eval`'d and then returned with no storage / cache mechanism. – David Barker Mar 08 '13 at 07:26

1 Answers1

5

Since (I think) Lion, the web server does not use mod_userdir anymore, so apache does not run as your user but as _www instead, see

user:~$ ps ax -o pid,user,rgroup,comm | grep -Ee "PID|httpd"
  PID USER             RGID COMM
10317 root                0 /usr/sbin/httpd
16516 _www               70 /usr/sbin/httpd
18497 _www               70 /usr/sbin/httpd
...

Now for your folder with permissions 775, user jason and group jason

drwxrwxr-x@ 7 jason jason 238 Mar 7 17:15 storage/views

Laravel will try to create a cache file for every blade view in that folder. If no such file exists, it will try to create that automatically. This requires write access to the folder, and since Apache runs as _www it requires write access on that directory as other.

Once the file exists however, that file is owned by _www, and so Apache does not require write access to the storage/views directory anymore. Until a new view is created...

Now what you can do is:

(keep in mind that there are other caches too in storage other than storage/views, so everything here is done on the whole storage folder)

  • either set the storage directory to 777 (for development this is "ok")

    chmod -R 777 storage
    
  • Or (better) chown the storage directory to jason:_www, this way you can keep the 775 permissions and both you and apache have sufficient access.

    sudo chown -R jason:_www storage
    
dualed
  • 10,262
  • 1
  • 26
  • 29
  • Thank you, that was the exact solution (2nd option) – Jazzy Mar 08 '13 at 17:22
  • This shouldn't have anything to do with Git, the issue was that the OSX apache does not run as your user and so can't write in the cache/storage directory. Though you are right in that cache and storage should not be in version control - in any project. – dualed Jan 31 '14 at 21:21
  • You are absolutely right, I didn't take the time to re-read my orig question and mistook it for another issue. Edited! – Jazzy Feb 01 '14 at 23:42