Why you should run artisan as www-data in Laravel production
Running php artisan as root on a server is a very common mistake. The command works, but it leaves a problem behind.
What happens
Artisan creates log, cache and compiled view files. Run as root, these files are owned by root. The web server runs as www-data, so it cannot write to them. The result is Permission denied and a 500 error.
The right way
With Docker Compose, run the command as the web user:
docker compose exec -T -u www-data -e HOME=/tmp app php artisan migrate --force-e HOME=/tmp stops some tools from failing because they cannot find a writable home directory.
If you already ran it as root
chown -R www-data:www-data storage bootstrap/cacheOne more rule
Run the tests before every deploy. If they fail, do not go live. Even a small Blade mistake can take the site down.