← Other topics

Laravel permissions for storage and bootstrap/cache (Apache or Nginx)

Video Notes

There are two directories within a Laravel application that need to be writable by the server: storage and bootstrap/cache. Within these directories, the server will write application-specific files such as cache info, session data, error logs, etc.

To allow this to happen, you need to update the permissions of storage and bootstrap/cache so they are owned by the system user your web server is running as.

To identify this system user, run the following command to output processes on your system related to your web server (either Apache or Nginx):

> ps aux | egrep '(apache|httpd|nginx)'

From this output, identify the user from the leftmost column. Ignore any processes owned by root.

On Nginx, you’re looking for the nginx: worker process process, so from the following example output we see the user is www-data:

root        2724  0.0  0.2  81896  2108 ?        Ss   Jun23   0:00 nginx: master process /usr/sbin/nginx -g daemon on; master_process on;
www-data    2726  0.0  0.4  82640  4504 ?        S    Jun23   0:00 nginx: worker process
root       60668  0.0  0.2   7008  2136 pts/0    S+   14:50   0:00 grep -E --color=auto (apache|httpd|nginx)

Here’s an example from an Apache server where we also see the user www-data:

root       11929  0.0  1.2 238908 12180 ?        Ss   Jun24   0:10 /usr/sbin/apache2 -k start
www-data   71685  0.0  0.9 239664  9304 ?        S    00:00   0:00 /usr/sbin/apache2 -k start
www-data   71686  0.0  0.9 239664  9292 ?        S    00:00   0:00 /usr/sbin/apache2 -k start
root       78734  0.0  0.2   8160  2376 pts/0    S+   14:50   0:00 grep -E --color=auto (apache|httpd|nginx)

Knowing this, I will update storage and bootstrap/cache to be owned by www-data with the following two chown (change owner) commands:

> chown -R www-data storage
> chown -R www-data bootstrap/cache

You should now be able to load your application without any permission errors. If your application isn’t working, check out my guide Common Laravel Installation Issues.

If this info helped you out you can say thanks and support future content by clicking my Amazon affiliate link: https://amzn.to/3UtgnYk. If you make a purchase on Amazon within 24 hours of clicking the link I may receive a micro-commission and it costs you nothing extra. Any income from these sales goes directly to supporting me in making new videos and guides. Thank you for your support!

← Other topics