Skip to content

Instantly share code, notes, and snippets.

@danielstgt
Last active April 14, 2025 09:55
Show Gist options
  • Save danielstgt/548fd9ce5cb0ff8bee2b7f0cdd5c8417 to your computer and use it in GitHub Desktop.
Save danielstgt/548fd9ce5cb0ff8bee2b7f0cdd5c8417 to your computer and use it in GitHub Desktop.
Upgrade ImageMagick and Imagick PHP extension

Upgrade ImageMagick Version to 7 with the Imagick PHP extension

Tested on Laravel Forge provisioned server with Ubuntu 22, PHP 8.3 and 8.4

Check the output of the current version, if it's already on v7 then you're done

php -r 'print_r(Imagick::getVersion());'
php8.3 -r 'print_r(Imagick::getVersion());'
php8.4 -r 'print_r(Imagick::getVersion());'

You can also check the installed ImageMagick version (maybe there is nothing installed)

convert --version
magick --version

Install ImageMagick 7 (skip if the previous command already said you have v7)

Remove old version

sudo apt remove "*imagemagick*" --purge -y && sudo apt autoremove --purge -y

Install new version

sudo bash -c "t=\$(mktemp) && wget 'https://dist.1-2.dev/imei.sh' -qO \"\$t\" && bash \"\$t\" && rm \"\$t\""

Check if the update was successful

magick --version

Install the Imagick extension

Check if the following shows something for your installed PHP versions

which phpize8.3
which phpize8.4
which php-config8.3
which php-config8.4

Build the extension for your installed PHP versions

git clone https://github.com/Imagick/imagick
cd imagick
phpize8.3
./configure --with-php-config=/usr/bin/php-config8.3
make
sudo make install
phpize8.4
./configure --with-php-config=/usr/bin/php-config8.4
make
sudo make install

Cleanup

make clean
make distclean
cd ..
rm -rf imagick

Check if you already have an imagick.ini, if not, create it in the right directory (which can be checked with e.g. php8.3 --ini)

cat /etc/php/8.3/mods-available/imagick.ini
ls /etc/php/8.3/mods-available/
sudo bash -c 'echo "extension=imagick.so" > /etc/php/8.3/mods-available/imagick.ini'
cat /etc/php/8.4/mods-available/imagick.ini
ls /etc/php/8.4/mods-available/
sudo bash -c 'echo "extension=imagick.so" > /etc/php/8.4/mods-available/imagick.ini'
cat /etc/php/8.3/cli/conf.d/imagick.ini
ls /etc/php/8.3/cli/conf.d/
sudo bash -c 'echo "extension=imagick.so" > /etc/php/8.3/cli/conf.d/imagick.ini'
cat /etc/php/8.3/fpm/conf.d/imagick.ini
ls /etc/php/8.3/fpm/conf.d/
sudo bash -c 'echo "extension=imagick.so" > /etc/php/8.3/fpm/conf.d/imagick.ini'
cat /etc/php/8.4/cli/conf.d/imagick.ini
ls /etc/php/8.4/cli/conf.d/
sudo bash -c 'echo "extension=imagick.so" > /etc/php/8.4/cli/conf.d/imagick.ini'
cat /etc/php/8.4/fpm/conf.d/imagick.ini
ls /etc/php/8.4/fpm/conf.d/
sudo bash -c 'echo "extension=imagick.so" > /etc/php/8.4/fpm/conf.d/imagick.ini'

Check if everything worked, maybe reload php-fpm with the correct version

php -r 'print_r(Imagick::getVersion());'
php8.3 -r 'print_r(Imagick::getVersion());'
php8.4 -r 'print_r(Imagick::getVersion());'
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment