It’s quite tricky to build gnupg php extension on OSX. I’m using homebrew, so I installed necessary dependencies first:
brew install gpgme
This goes well as most things with brew.
Then I’m trying to install GNUPG PHP PECL extension as the instructions tell me to do:
sudo pecl install gnupg
Bang!!!
I get weird errors like these:
duplicate symbol _gnupg_keylistiterator_class_entry in: .libs/gnupg.o .libs/gnupg_keylistiterator.o duplicate symbol _gnupg_class_entry in: .libs/gnupg.o .libs/gnupg_keylistiterator.o ld: 2 duplicate symbols for architecture x86_64 clang: error: linker command failed with exit code 1 (use -v to see invocation) make: *** [gnupg.la] Error 1 ERROR: `make' failed
“Tough luck”, I think. But wait… After some googling around PHP bugs I got some hints.
So here’s what you got to do:
- download pecl extension source code
- fix 2 lines in .h and .c files
- phpize, configure and make
- configure PHP extension
- == Profit
pecl download gnupg
In my case it downloads files to /Users/sven/soft/php-5.5.4/ext/gnupg-1.3.3/gnupg-1.3.3.tgz
Unpack the archive:
tar xzf gnupg-1.3.3/gnupg-1.3.3.tgz cd gnupg-1.3.3
Open file php_gnupg.h and add comments and explanation around line 50:
/* moved next line to gnupg.c zend_class_entry *gnupg_class_entry; */
Copy the line zend_class_entry *gnupg_class_entry; to buffer. Save and exit.
Open file gnupg.c:
Find lines (around 177) and paste copied buffer so it looks like this:
zend_class_entry *gnupg_class_entry;
/* {{{ objects_new */ zend_object_value gnupg_obj_new(zend_class_entry *class_type TSRMLS_DC){
Do similar things with files gnupg_keylistiterator.c and php_gnupg_keylistiterator.h.
Open file php_gnupg_keylistiterator.h around line 69:
/* moved next line to gnupg_keylistiterator.c zend_class_entry *gnupg_keylistiterator_class_entry; */
Copy line zend_class_entry *gnupg_keylistiterator_class_entry; to buffer. Save and exit.
Open file gnupg_keylistiterator.c around line 72 and make it look like this by pasting buffer:
zend_class_entry *gnupg_keylistiterator_class_entry;
/* {{{ keylistiterator_objects_new */ zend_object_value gnupg_keylistiterator_objects_new(zend_class_entry *class_type TSRMLS_DC){
Save and exit.
Configure, build and install: ./configure make clean && make make install
Now you should have php extension gnupg.so somewhere. I have it in my Cellar:
/usr/local/Cellar/php55/5.5.4/lib/php/extensions/no-debug-non-zts-20121212/gnupg.so
Wherever it is, copy the path to buffer.
Open a new file (your php-s conf.d may be somewhere else!)
vim /usr/local/etc/php/5.5/conf.d/ext-gnupg.ini
And add following lines there:
[gnupg] extension="/usr/local/Cellar/php55/5.5.4/lib/php/extensions/no-debug-non-zts-20121212/gnupg.so"
Save and exit. Be sure to replace path if your gnupg.so is somewhere else.
Test your php:
php --ri gnupg
It should display something like this:
gnupg gnupg support => enabled GPGme Version => 1.4.3 Extension Version => 1.3.3-dev
Thanks!