Uninstall Imagick Version that PHP is using

Viewed 980

I installed Imagick through apt-get install. However the version it installed was old (6.9.7) and does not have all the delegates I need built in.

So I thought I uninstalled it using apt-get remove --purge imagemagick and reinstalled it from source.

Currently identify -version gives me the correct version I just installed (6.9.12) however php -r "print_r(Imagick::getVersion());" still shows v 6.9.7.

facepalm
      .-'---`-.
    ,'          `.
    |             \
    |              \
    \           _  \
    ,\  _    ,'-,/-)\
    ( * \ \,' ,' ,'-)
     `._,)     -',-')
       \/         ''/
        )        / /
       /       ,'-'

My questions are

  • Why?
  • How do I remove the old version?
  • How do I update the path for php to use the newer version?
1 Answers

ImageMagick is split up into a few packages, with both the php-imagick extension package and the front facing imagemagick package using libraries provided by the libmagick* packages.

If you've already got the compiled version of ImageMagick in place, the simplest thing will be to remove the packaged version of imagick and then compile the imagick extension as well, configuring it to use your freshly compiled version of ImageMagick.

Building on the instructions here, you can do the following:

sudo apt-get purge -y php-imagick
git clone https://github.com/Imagick/imagick.git
pushd imagick
phpize
./configure --with-imagick=${IMAGEMAGICK_PREFIX_DIR}
make
sudo cp modules/imagick.so ${PHP_EXTENSION_DIR}
echo extension=imagick.so | sudo tee ${PHP_CONFIGURATION_FILE_PATH}/conf.d/30-imagick.ini

Where:

  • IMAGEMAGICK_PREFIX_DIR is the prefix into which you've installed ImageMagick (such that MagickWand-config can be found at ${IMAGEMAGICK_PREFIX_DIR}/bin/MagickWand-config).
  • PHP_EXTENSION_DIR is the directory where PHP looks for its extensions, and can be found via php -i | grep extension_dir. This looks something like /usr/lib/php/20190902.
  • PHP_CONFIGURATION_FILE_PATH is the base directory of the particular SAPI configuration, and can be found via php -i | grep 'Configuration File (php.ini) Path' (for the cli SAPI) or the value listed under Configuration File (php.ini) Path in the phpinfo() output via the webserver. This looks something like /etc/php/7.4/${SAPI}, where SAPI is cli, or apache2, etc.
Related