Exactly how to do it! Thanks Michael.
In fact, this is the best practice, Ehsan: you do not want to give your web server user rights to write files, due to security. So, install things as root or some other privileged user, then change the ownership and permissions back to the web server user so it can read them.