Clearly root access is nothing to develop and generally work once again impossible.
Should be a difference in the environment for the developer and for production environment.
Very bad idea to code directly on the production server, and so the idea of trying to repeat the developer's production environment.
Your code should be built so that he could work from deprivileging user. The code, run it and check should be as comfortable and insulated from the demands of the environment.
Read for example about the concept of CI/CD
If you have some intermittent issues with the access rights to the files, then you don't understand what's going on. You just need a time to understand this and not to make a cult
Usually on the developer's machine, the functionality of the site runs directly under ordinary user in an environment with a simplified configuration (no extra caching layers, without optimizations, without protection from any attacks and without CDN). The project must be constructed so that it is easy to switch between the developer's environment and product, and more or less the same to work in these environments in regard to the main part of the development (features, interfaces, view...).
In addition, good practice has now become the deployment environment and the isolation of the site in Docker containers. This is a very cool and promising concept, and it has ALREADY conquered the world. There is no reason why not to use containerization in the development and production. Not so high a barrier of entry Slavoj kompensiruet the disappearance of any hemorrhoids related artifacts and side effects effects of the environment, configuration, and projects with each other.