php error: Class 'Imagick' not found

Viewed 124218

I am getting the error "Class 'Imagick' not found". Somehow I need to make this library accessible to php. I am using Php 5.2.6 on Fedora 8. my php_info has no mention of ImageMagick.

I have tried: yum install ImageMagick and restarted apache, which didn't work.

I also added extension=imagick.ext to my php.ini file and restarted apache, which didn't work.

10 Answers

Install Imagic in PHP7:

sudo apt-get install php-imagick

On an EC2 at AWS, I did this:

 yum list | grep imagick

Then found a list of ones I could install...

 php -v

told me which version of php I had and thus which version of imagick

yum install php56-pecl-imagick.x86_64

Did the trick. Enjoy!

Docker container installation for php:XXX Debian based images:

RUN apt-get update && apt-get install -y --no-install-recommends libmagickwand-dev
RUN pecl install imagick && docker-php-ext-enable imagick
RUN apt-get clean && rm -rf /var/lib/apt/lists/* /tmp/* /var/tmp/* || true

Install Base Imagick Repos

Many of these answers are great, if you are using PHP5, but PHP8 offers too many features to just pass up, and imagick is a bit different here.

Install the base imagick repos:

sudo apt-get install php8.0-imagick php8.1-imagick imagemagick php-imagick php-pear php-dev

Install Imagick's Extension into PHP

You may want to omit php8.1-imagick if you are not up to version 8.1 yet. php-pear is where the pecl command lives, so, if that doesn't install correctly, you'll get an error when you need to do the next command...

sudo pecl install imagick

Update PHP.ini

Find your php.ini file with...

php -i | grep  -i php.ini

You may get output like...

Configuration File (php.ini) Path => /etc/php/8.1/cli
Loaded Configuration File => /etc/php/8.1/cli/php.ini

Open this file and add to the end of the file this text: extension=imagick.so.

Restart PHP

Then restart your server. Any of these will do:

systemctl restart apache2
/etc/init.d/apache2 restart
sudo service apache2 graceful

Check if the Install Worked

  • See the results of phpinfo() on a web page, which should mention imagick.
  • See the results of simulated phpinfo() info calls from the command line with php -r "echo phpinfo();" | grep 'imagick';.
  • See the internal storage of phpinfo() from the command line with php -i | grep 'imagick'.
  • See the installed packages containing imagick in the name with dpkg --list | grep 'imagick'.

Note: These are all important, because while I was debugging, I was able to see Imagick installed at lower layers (i.e. with dpkg), but was not seeing it in the higher layers (i.e. with phpinfo(); through webhost). Cheers.

Related