Adding Imagick extension in Laragon, XAMPP, WAMPP to be used in Laravel 11 with PHP 8.2?

85 Views Asked by At

The Imagick extension functions perfectly with PHP 8.1 and Laravel 10, but not with PHP 8.2. The new Laravel 11 is compatible with PHP 8.2, which implies that the Imagick library must also be installed to operate correctly. However, I have been unable to find instructions on how to install Imagick on PHP 8.2. I understand that Imagick is pre-installed in PHP 8.2.17, but the .dll file is not present in the ext folder. So, how can I set up my environment to work with Laravel 11, PHP 8.2, Intervention Image, and Imagick locally using Laragon, XAMPP, or WAMPP? And how can I do the same in a production environment using Ubuntu 22?

I am trying to use Laravel 11 with PHP 8.2 and Intervention to process images.

2

There are 2 best solutions below

0
Stefano Martini On
sudo apt-get install php8.2-imagick -y

Then restart the server

2
Leonard Cătălin Bîra On

EDIT: the following guide works if a DLL for the PHP version exists, and while official Imagick Build does exist for PHP 8.1.27 on Windows for PHP 8.2 it doesn't at the moment. I would suggest trying to use Docker with Alpine, PHP 8.2 and Imagick, there is on StackOverflow a thread that might help you: Imagick Docker Alpine Linux php8.2 or if you can take the risk, download non-official Imagick DLL for php 8.2 from https://github.com/Imagick/imagick/issues/573#issuecomment-1431773928

That being said the steps are:

To know if php is Thread Safe or not, and what architecture is it (x86, x64), to discover this in PowerShell:

php -i | Select-String "Thread Safety"
php -i | Select-String "Architecture"

Then go to http://pecl.php.net/package/imagick and download the package, for example for php 8.1.27 I currently have: 8.1 Thread Safe (TS) x64 imagick 3.7.0

Unzip the content of the package in a folder that can be definitive.

Copy the one dll (php_imagick.dll in my case) to your php ext directory and make sure you right click on the file, properties and unblock it.

Now to make it work you need to:

1. Edit php.ini

In php.ini, find where extensions are defined searching for extension= and add the line:

extension:imagick

2. Edit PATH sys env variable to add Imagick folder

Search PATH on startbar, open "Edit the system environment variables", click on Environment Variables, select PATH, edit and add the path to the Imagick definitive folder.

Done.

Now you should be able to see imagick extension in a new opened console when you digit "php -m"

Beware: if you do not add Imagick folder PATH to your system env path php will like throw an error of extension not found even if the dll is there.