Hi Patrik,
How can I get apache's environmental variable if I do not run the script as the uid of apache?
If you use suExec, this quote from http://httpd.apache.org/docs/suexec.html could help:
19. Can we successfully clean the process environment to ensure safe operations? suEXEC cleans the process' environment by establishing a safe execution PATH (defined during configuration), as well as only passing through those variables whose names are listed in the safe environment list (also created during configuration). HTH, Vinai