Install Imagemagick With PHP 8.3 In DDEV

Imagemagick is a graphics manipulation library.

Imagick is the PHP extension.

The version of Debian used in DDEV does not have php8.3 libraries available in the package manager yet.

https://packages.debian.org/stable/php/php-imagick

However, there is a way to install the latest php libraries.

https://github.com/oerdnj/deb.sury.org/wiki/Frequently-Asked-Questions#how-to-enable-the-debsuryorg-repository

Here is a script for installing php8.3 and imagick.

#!/bin/bash

if ! php -m | grep -q "^imagick$"; then
  curl -sSL https://packages.sury.org/php/README.txt | sudo bash -x
  sudo apt install php-imagick -y
fi

This checks if the imagick php module is loaded, and if not, loads the packages from the sury repository and then installs imagick.

You can put this into .ddev/commands/web/imagick.sh, and run it with ddev imagick.sh.

This sets up the script as a custom command.

You can also add it as a post-start hook (In .ddev/config.yml).

hooks:
  post-start:
    - exec: "config/imagick-ddev.sh"

This gets imagick dependencies installed in composer. There may be an extra step required to get Media PDF Thumbnails working, see the last line in the lando script:

sed -i 's#<policy domain="coder" rights="none" pattern="PDF" />#<policy domain="coder" rights="read|write" pattern="PDF" />#g' /etc/ImageMagick-6/policy.xml

Articles