I have read a similar questions ans answers such as this one. But I am still faced with one issue I haven't found a perfect solution for.
My situation is as follows: I have a symfony4 project located in var/www/project. Within this directory there are directories such as scr, config, public which are all owned by user:user (which has root access). Just one directory in this project, var (in which the cache and log are stored), is owned by www-data:www-data, so that apache can read and write to this directory.
Whenever I need to clear the cache I must run php bin/console cache:clear. I cannot do this as user, because of the permissions that are set. If I change the ownership with sudo chown user:user var, I can then do run the command. But apache won't be able to read the files any more. I could then change the ownership again with sudo chown www-data:www-data var and everything works again, but my guess is there must be an easier solution.
Addionional information: whenever the php bin/console cache:clear is executed, all files in the var directory are set with permissions 664.
I thought about changing the default user of Apache to user, but this user has root access, so this is a bad idea I think. How should I solve this?