Today I wanted to add the PHP EXIF extension to my local PHP installation. According to the PHP manual to do this you should configure PHP with –enable-exif
. However, I didn’t want to go through the tedious process of compiling PHP from scratch again. I just wanted to add the single extension.
I couldn’t find any info on how to do this, but thankfully it is actually quite simple, it’s pretty much the same as compiling any extension that doesn’t come with PHP as standard. This same process should work with any of the extensions that ship with PHP.
First you need to download the PHP source, unzip it, and navigate to the extension dir:
cd /tmp PHP='php-7.0.2' wget http://www.php.net/get/$PHP.tar.gz/from/this/mirror -O $PHP.tar.gz tar xvfz $PHP.tar.gz cd $PHP/ext/exif
Then build the extension:
/path/to/php/bin/phpize ./configure --enable-exif --with-php-config=/path/to/php/bin/php-config make sudo make install
Finally configure PHP to use the new extension. In the previous step it should have told you where it installed the extension to. Edit your php.ini and add the extension:
extension="/path/to/php/lib/php/extensions/no-debug-non-zts-20151012/exif.so"
Note that I had to use extension
rather than zend_extension
. I’m not sure what determines this? After adding the extension to your php.ini, restart PHP and if you check phpinfo()
you should see the extension is now enabled.
Not as simple as it could be, but for sure a lot easier and quicker than having to completely recompile PHP just to add a single extension.