I created a temporary file using fopen in php and get the file owner/user id and username. My question is
Is it always httpd a username for php generated file? Is it always for apache? Can we change the username for apache?
You can view/change the user that Apache runs as with the User
directive. (Directives are found in the httpd.conf
file, usually in /etc/apache2, on a Mac.) If you want PHP and Apache to run as different users, then you can use the Suexec module to switch to a different user when running PHP scripts.
See this question for a discussion of the pros and cons of Suexec vs MPM-ITK.