How to solve laravel permission denied errors

Last updated at January 26, 2022

💬

Laravel system can have various permission denied errors when running in production server.

Clear all cache

php artisan cache:clear

If you get error to clear cache, exeucte command using sudo.

sudo php artisan cache:clear

Check correct permission to storage & bootstrap/cache folder

sudo find . -type f -exec chmod 664 {} \;   
sudo find . -type d -exec chmod 775 {} \;
sudo chgrp -R www-data storage bootstrap/cache
sudo chmod -R ug+rwx storage bootstrap/cache

Check supervisor execution user

When you running Laravel queue by supervisor, specify www-data user.

Set user in your supervisor configuration file.

/etc/supervisor/conf.d/larvel-worker.conf
[program:laravel-worker]
process_name=%(program_name)s_%(process_num)02d
command=php /var/www/my-app/artisan queue:work --timeout=300
autostart=true
autorestart=true
stopasgroup=true
killasgroup=true
user=www-data
numprocs=1
redirect_stderr=true
stdout_logfile=/var/www/my-app/worker.log
stopwaitsecs=300

Check laravel scheduler user

Generally, laravel scheduler runs by cron job. You need to specify user which can access in your laravel application folder.

/etc/cron.d/my-app
* * * * * www-data php /var/www/my-app/artisan schedule:run >> /dev/null 2>&1

Access your web application using custom domain

You can access your web application with custom domain.