Importing gnupg key in apache

In case you need to use PGP in php you need to install gnupg extension in php. The problem comes when you want to run the routine from the webserver as the apache does not have a home and it cannot have a keyring.

For command line execution of the php script the current user key ring is used and the finger print of the key is used to identify and load the key.

In order to import key in Apache you need to set the environment variable in php script and the web server need to have access to that path. The following method is recommended.

a) Import the key in any user

b) Copy the whole .gnupg directory to apache home normally /var/www

cp -R ~/.gnupg /var/www

c) Chown to apache

chown -R apache:apache /var/www/.gnupg

This will ensure apache has a seperate set of key ring on its own.

You can also specify the home at time of import to bye pass this set

gpg –homedir /var/www –import public.asc

Now the import step is to specify in php script where to load the keys

// GnuPG code
putenv("GNUPGHOME=/var/www/.gnupg/");
Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s