Can't run GPG through php on linux (works fine through telnet)

Andy Freeman
Tue May 21 18:38:23 2002

Thanks for your help ..

one of our web designers found the answer !

he just followed the process on web monkey
( )

Another useful link is

This script assumes that :

1) Your php web user is called "nobody"
2) nobody has a home directory of "/home/customers/nobody/"
3) this path contains a folder ".gnupg", which in turn contains the
4) the path to the gpg exe is /usr/local/bin/gpg

You also need to
chmod +s /user/local/bin/gpg

I believe that this is all you need to know,
but since i don't fully understand the process,
i'm not entirely sure ...


// usage $crypted_data = gnupg_crypt($data_to_encrypt);
function gnupg_crypt($msg) {

//set the environment variable for GPGPATH

//generate token for unique filenames
$tmpToken = md5(uniqid(rand()));

//create vars to hold paths and filenames
$plainTxt = "/home/customers/nobody/" . "$tmpToken" . "data";
$crypted = "/home/customers/nobody/" . "$tmpToken" . "pgpdata";

//open file and dump in plaintext contents
$fp = fopen($plainTxt, "w+");
fputs($fp, $msg);

//invoke GPG to encrypt file contents
system("/usr/local/bin/gpg --encrypt -ao $crypted -r 'Key_Name (Key_Comment)
<Key_main_addr>' $plainTxt");

//open file and read encrypted contents into var
$fd = fopen($crypted, "r");
$output = fread($fd, filesize($crypted));

//delete files!

return $output;



Long live GNU

Andy Freeman