I have a PHP script involving exec()
that will run fine from the command line but not in a web context. The script is simply this:
The other posters are correct to suggest the web server user doesn't have rights to write to your home directory. To see if they are right try modifying the code to write to /tmp/wee.txt. That should be world writable.
Another possibility is that php can be configured to disable calling exec(). See http://www.cyberciti.biz/faq/linux-unix-apache-lighttpd-phpini-disable-functions/