56

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.

Andrew Thomas
  • 2,482
  • 3
  • 25
  • 29

10 Answers10

57

For all to those having problems with this i did this tutorial:

How to install Imagemagick and Php module Imagick on ubuntu?

i did this 7 simple steps:

Update libraries, and packages

apt-get update

Remove obsolete things

apt-get autoremove

For the libraries of ImageMagick

apt-get install libmagickwand-dev

for the core class Imagick

apt-get install imagemagick

For create the binaries, and conections in beetween

pecl install imagick

Append the extension to your php.ini

echo "extension=imagick.so" >> /etc/php5/apache2/php.ini

Restart Apache

service apache2 restart

I found a problem. PHP searches for .so files in a folder called /usr/lib/php5/20100525, and the imagick.so is stored in a folder called /usr/lib/php5/20090626. So you have to copy the file to that folder.

Adam
  • 533
  • 5
  • 15
Rodrigo Carmona
  • 605
  • 1
  • 5
  • 6
  • The question as written specifies Fedora. I'd suggest adding something about whether these steps for Ubuntu are also likely to work on Fedora, or which bits might have to be modified. – Assad Ebrahim Feb 28 '13 at 20:23
  • Bit worried about step 6. Do you really want to clobber php.ini? Or should that be ">>" for appending? – Mark Setchell Feb 05 '14 at 13:01
  • 1
    I had to `apt-get install php5-dev php-pear` in order to complete the steps on Debian Wheezy – juanmf Mar 24 '15 at 22:29
  • 1
    This didn't help with command line imagemagick on Ubuntu. The Ubuntu answer below works. None of the many things listed in this answer helped, seems like it loads every library except the right one! – Henry's Cat Oct 14 '15 at 13:54
  • For me with php7.0-fpm the following command is enough to install and enable imagick: `sudo apt-get install php-imagick` – Kapitein Witbaard Feb 20 '17 at 10:53
  • Just make sure to add php version with the package otherwise it will always install the latest version of this package. For php 7.4 it should be - apt-get install php7.4-imagick – Avnish Tiwary Feb 10 '23 at 18:32
19

From: http://news.ycombinator.com/item?id=1726074

For RHEL-based i386 distributions:

yum install ImageMagick.i386
yum install ImageMagick-devel.i386
pecl install imagick
echo "extension=imagick.so" > /etc/php.d/imagick.ini
service httpd restart

This may also work on other i386 distributions using yum package manager. For x86_64, just replace .i386 with .x86_64

taco
  • 1,367
  • 17
  • 32
Andrew Thomas
  • 2,482
  • 3
  • 25
  • 29
  • This is what finally worked for me. I had performed other attemtps which included everything except for the second line. Whatever `yum install ImageMagick-devel.i386` does fixed it for me. – James Apr 14 '15 at 09:14
12

Ubuntu

sudo apt-get install php5-dev pecl imagemagick libmagickwand-dev
sudo pecl install imagick
sudo apt-get install php5-imagick
sudo service apache2 restart

Some dependencies will probably already be met but excluding the Apache service, that's everything required for PHP to use the Imagick class.

Alastair
  • 6,837
  • 4
  • 35
  • 29
10

For MAMP running on Mac OSX

Find out the what version of PHP and install the right version via brew

brew install homebrew/php/php56-imagick

Add the extension by modifying the php.ini template in MAMP

enter image description here

Verify the Imagick

enter image description here

Gajen Sunthara
  • 4,470
  • 37
  • 23
  • 1
    for **php 7.0** => `brew install php70-imagick` **php 7.1** => `brew install php71-imagick` _Restart Service_ : `sudo brew services restart php70` – Suresh Velusamy Apr 25 '17 at 13:00
6

Debian 9

I just did the following and everything else needed got automatically installed as well.

sudo apt-get -y -f install php-imagick
sudo /etc/init.d/apache2 restart
Juergen Schulze
  • 1,515
  • 21
  • 29
5

Install Imagic in PHP7:

sudo apt-get install php-imagick
Sadee
  • 3,010
  • 35
  • 36
  • In my case, I then had to run `service php7.3-fpm restart` and provide `vagrant` as the password. – Ryan Jul 12 '19 at 20:25
1

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!

Scott
  • 695
  • 1
  • 8
  • 16
1

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
Mike Doe
  • 16,349
  • 11
  • 65
  • 88
0

imagick become not supported in <= php7.0 the Ideal Solution is alternative Package Please find this here https://github.com/DantSu/php-image-editor

Mostafa Mahmoud
  • 153
  • 3
  • 7
0

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.

HoldOffHunger
  • 18,769
  • 10
  • 104
  • 133