Running a shell script in apache

I have a shell script, that works when ran in the shell. When placed in the cgi-bin directory, it doesn't work as expected.

Looking at the logs, it seems that some environmental variables are not being passed.

My apache user is www.

For simplicity, here is a sample script I want to run

#!/usr/bin/bash

echo "$HOME"

When logged in as user "www" from a shell it will return

/home/www

When running the script from a hyperlink I get no output. How can I resolve this?

Thanks

The script has to source the environment variables/settings all by itself -
source /home/phpuser/.profile
source /etc/profile

emulate what occurs during login. Whatever that is. test you efforts first with the "set" command - it shows everything.
It should match what you get when you run it interactively.

I added a .profile to /home/www

However, I still don't get the output of echo "$HOME"

---------- Post updated at 11:28 AM ---------- Previous update was at 10:41 AM ----------

You can disregard my last post, I figured it out.

Thanks for the help!