GnuPG in PHP failing with error code 2

Frank Tuvell ftuvell@telocity.com
Thu Aug 8 11:47:01 2002


I've scanned the mailing list archive and Google groups and didn't 
find a solution to this problem so here goes:

I'm writing a php script to encrypt some data into a file using 
GnuPG.  The command works fine on the command line but 
returns an error 2 when executed with an exec() function call in 
PHP.  I've also had it redirect to email too and that produces the 
same result (works fine on the command line but not in PHP code).  
I've tried escaping the @ signs too.

Here's the code:

exec("echo \"This is a test\" | gpg -a -e -u blah@blah.com -r 
blah@blah.com > /var/www/blah/html/temp/encrypted", $encrypted, 
$errorCode);

"/var/www/blah/html/temp/encrypted" is the file I'd like the output to 
go to.  It currently doesn't exist so it's not an overwrite problem. 
Also, the /temp dir has chmod 777 permissions.

I've tried it without the "> /var/www/blah/html/temp/encrypted" (to 
send the output directly to the console) and I get the same result 
(works fine on the command line but not in PHP code). The 
resulting $encrypted array is empty.

The resulting $errorCode is always 2.

Any idea what I'm doing wrong here?  I'm guessing it has 
something to do with the fact that the webserver (apache) is 
running as a different user.

Any idea where I can find a list of error codes for GnuPG?

Any help with this would be greatly appreciated!  This issue is 
holding up a major project I'm working on.

Thanks in advance!

Frank