I changed some of the code and used php bin/console cache:clear --env=prod to clear cache in order to see my changes in production mode, but the website was giving me 500 error afterwards.
I checked apache2 error logs and saw this:
PHP Fatal error: Uncaught InvalidArgumentException: The directory "/var/www/html/var/cache/prod/annotations" is not writable.
So I checked /var/www/html/var/cache/prod and saw that prod folder and its subfolders are all owned by root and this caused by executing php bin/console cache:clear --env=prod by root user, therefore I changed owner of the folder and its subfolders using this command chown -R www-data: /var/www/html/var/cache/prod (change www-data to your own apache user if you need to) and everything went fine.
I changed some of the code and used
php bin/console cache:clear --env=prod
to clear cache in order to see my changes in production mode, but the website was giving me 500 error afterwards.I checked apache2 error logs and saw this:
PHP Fatal error: Uncaught InvalidArgumentException: The directory "/var/www/html/var/cache/prod/annotations" is not writable.
So I checked
/var/www/html/var/cache/prod
and saw that prod folder and its subfolders are all owned by root and this caused by executingphp bin/console cache:clear --env=prod
by root user, therefore I changed owner of the folder and its subfolders using this commandchown -R www-data: /var/www/html/var/cache/prod
(change www-data to your own apache user if you need to) and everything went fine.