php error: Class 'Imagick' not found

php exception
php error as exception
php exception class
php error vs exception
php fatal error
php 7 catch type error
php return error
php catch fatal error

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.

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.

Php 5/7 error class handling, The short is you shouldn't do that, because it's a backwards incompatible change. The long answer is yes, it's possible, but you still shouldn't do that, because it  Well organized and easy to understand Web building tutorials with lots of examples of how to use HTML, CSS, JavaScript, SQL, PHP, Python, Bootstrap, Java and XML.

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

PHP Exception Handling, Lets create an exception class: <?php class customException extends Exception { public function errorMessage() { //error message $errorMsg = 'Error on line '. To catch both exceptions and errors in PHP 5.x and 7, add a catch block for Exception AFTER catching Throwable first. Once PHP 5.x support is no longer needed, the block catching Exception can be removed.

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.

A Crash Course of Changes to Exception Handling in PHP 7 , The Error class in PHP 7 is a new type of class that handles the different errors – they are either fatal errors or type errors, and this class is only for internal PHP errors. Error is divided into four subclasses: ArithmeticError. There is another problem that may occur and it is worth for anyone to know it. If you use __autoload() and in the file that holds the class being autoloaded you write your PHP tags incorrectly, it will return a class not found error: File App.php.

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

Verify the Imagick

PHP 7 Throwable Errors Exceptions, Error is the base class of all the internal PHP errors. The most commons are the following: ParseError , which is thrown when we require or eval a  It can enable PHP execution error logging setting the file that logs error messages. The class provides an error handler function that outputs a stack back-trace with the functions, arguments, file and lines of where an error occurs, as well the values of super-global variables $_GET, $_POST and $_FILES, and also the IP address of the current user accessing the site. The class may also enable of disable the output of error messages to Web pages and change the error reporting level.

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

The PHP Exception Class Hierarchy, When a fatal error occurs, PHP will now throw an Error class instance. An Exception instance, on the other hand, is thrown for more traditional,  Gets the name of the class of the given object . This parameter may be omitted when inside a class. Note: Explicitly passing NULL as the object is no longer allowed as of PHP 7.2.0. The parameter is still optional and calling get_class () without a parameter from inside a class will work, but passing NULL now emits an E_WARNING notice.

Modern Error handling in PHP, The new interface. While PHP 7 provides both Error and Exception classes, let's check the Throwable interface first. Both Error and Exception  Define a Class. A class is defined by using the class keyword, followed by the name of the class and a pair of curly braces ({}). All its properties and methods goes inside the braces:

JetPack update error, Error message : Uncaught Error: Class 'Automattic\Jetpack\Roles' not found in /​vhosts/dwnmedia.ch/httpdocs/wordpress/wp-includes/class-wp-hook.php(288):  Autoloading Classes. Many developers writing object-oriented applications create one PHP source file per class definition. One of the biggest annoyances is having to write a long list of needed includes at the beginning of each script (one for each class). In PHP 5, this is no longer necessary.

Good Practices: handling error and exceptions in PHP, The only classes that can throw error are the ones that implement the Throwable class. Let's play a game, look at the code and answer the  The class name can be any valid label, provided it is not a PHP reserved word. A valid class name starts with a letter or underscore, followed by any number of letters, numbers, or underscores. A valid class name starts with a letter or underscore, followed by any number of letters, numbers, or underscores.

Comments
  • Did you search for a image magick php extension ? I imagine that you need something between the C library & your PHP class.
  • All my extensions are *.so not *.ext ?
  • "didn't work" very good very useful
  • 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.
  • Bit worried about step 6. Do you really want to clobber php.ini? Or should that be ">>" for appending?
  • I had to apt-get install php5-dev php-pear in order to complete the steps on Debian Wheezy
  • 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!
  • For me with php7.0-fpm the following command is enough to install and enable imagick: sudo apt-get install php-imagick
  • 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.
  • for php 7.0 => brew install php70-imagick php 7.1 => brew install php71-imagick Restart Service : sudo brew services restart php70
  • With PHP7 : sudo apt-get install php7.0-imagick -y service apache2 restart
  • In my case, I then had to run service php7.3-fpm restart and provide vagrant as the password.