Changing the storage path in Laravel Lumen

Let me first explain why I needed this. I was using Otto, which is basically a fancy way of setting up a development environment. If you want to read upon Otto, be my guest: It is using Vagrant underneath to set up it’s environment. I decided to make a simple Laravel Lumen API, which would be running on that virtual machine created by Otto.

So my situation was as follows:

I had a local development folder (repo) which was mounted on the development machine as a shared folder. Now here comes the problem: the folder was made by setting the folder owner and group to the vagrant. Once I ssh’ed into the machine, I couldn’t change the owner storage folder used by Laravel. When I ran the command:

sudo chown -R www-data:www-data storage/

The user and group of the folder just simply wouldn’t change. So I decided I needed another storage location where folder owner and group can be set using chown. Therefore I made a folder inside /var/www.

sudo mkdir /var/www/

Then I copied the storage folder in the Laravel Lumen project to this directory. In here I could set the owner to www-data. Only one problem was left. Lumen didn’t know where to look for the updated storage folder. You need to tell this to the framework.

So I was looking in the source code of Lumen and then I found this function: useStoragePath(). So what I did next is opening up – in your Lumen project – bootstrap/app.php and nearly at the end if the file I added:


This was all you need to do in order to update your Lumen storage location.

Geef een reactie

Scroll naar boven