Articles
Wednesday, 2 December 2020
Proper file permissions for Laravel
Step by step guide
ssh
into your server.cd
into your project directory.
cd /var/www/<project-folder>
- Assuming your web server is
www-data
, assign you Laravel project to that group:
sudo chown -R <my-username>:www-data .
- Add your user to the
www-data
group (so you should also have permission to read/write):
sudo usermod -a -G www-data <my-username>
Good practice is to set all your directories to 755
, and all files to 644
.
- Set folder permissions using the following command:
sudo find . -type d -exec chmod 755 {} \;
- Set file permissions using the following command:
sudo find . -type f -exec chmod 644 {} \;
- Give the webserver permission to upload & write files to the
storage
&cache
folders:
sudo chmod -R ug+rwx storage bootstrap/cache
Done 🥳 .
Queue worker
If you have a queue worker running, like supervisor, you should configure the user to be www-data
, not your user:
[program:laravel-worker]process_name=%(program_name)s_%(process_num)02dcommand=php /var/www/PROJECT_NAME/artisan queue:work database --sleep=3 --tries=3autostart=trueautorestart=trueuser=www-datanumprocs=6redirect_stderr=truestdout_logfile=/var/www/PROJECT_NAME/worker.logstopwaitsecs=3600