Wow, maybe I should have read your post before posting mine. I am also having GPG woes. I do know that on my web server I can run GPG globally. Thus, on the command line, I need no directory. I just type gpg -a --recipient...
As for your .gnupg folder, if it is in your av123 folder then make sure you have the whole pathway to get to your av123 directory. For example, /home/foo/www/av123/.gnupg or whatever pathway your web server uses. Since your PHP script is probably executing as nobody, you need the entire pathway so that the server knows where to find your keyring.
I do know that you definitely have to run this script using a secure server through an SSL connection. I have to use the same web server that the shopping carts use in my case. However, after this, I am stuck. My result from my system command comes back as 2. However, I can also run the GPG command on my command line no problem. If you get this to work, let me know too. I am thinking that there is some sort of permission issue dealing with my .gnupg folder. Like, the web server is executing the script as nobody and nobody does not have access to my keyring folder.
Are you using the PHP and MySQL Web Development book?