Skip to content
Advertisement

Recurring permissions problems w/ Laravel on vagrant box

I’m getting some strange permissions problems. I’m using Laravel on a vagrant box. I regularly have to reset my app/storage permissions.

Here’s my process:

  • in terminal, run sudo chmod -R 777 app/storage. I do this both from the vagrant ssh and directly on my machine.

  • everything loads fine.

  • I run a login script that looks like this:

    public function store()
    {
    $input = Input::all();
    
    $attempt = Auth::attempt([
        'email' => $input['email']
        , 'password' => $input['password']
    ]);
    
    if($attempt){
        return Redirect::intended('/');
    }else{
        dd('errors');
    }
    }
    
  • I fill in my login with incorrect details & I get the dd() output as expected.

  • I return to my login form.

  • I enter valid user details.

  • I get the following permissions error:

    file_put_contents(/var/www/laravel/app/storage/sessions/62da397f3ec526dea6cabf36f06657234dfb9de7): failed to open stream: Permission denied
    
  • In terminal I run sudo chmod -R app/storage again.

  • I can reload the page and the permissions denied error is gone.

I’ve done this consistently every. single. time. I can’t work out what’s messing with my permissions or how to fix it.

Advertisement

Answer

I’ve just figured it out. it’s to do with the vagrantfile. I added the owner and group info to the synced files and it’s working now.

  config.vm.synced_folder ".", "/var/www", :owner => 'www-data', :group => 'www-data'
User contributions licensed under: CC BY-SA
1 People found this is helpful
Advertisement