Laravel 5.2: Class Imagick not found

こ雲淡風輕ζ 提交于 2019-12-05 03:54:42
Sishir Pokhrel

Can you try editing php.ini located in
cd /etc/php5/apache2/php.ini

if your linux is ubuntu ?

cat php.ini | grep extension=imagick.so

if there is the results of search, then you might get this
;extension=imagick.so
You remove this semicolon ; and if not any results,

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

And finally

sudo /etc/init.d/apahce2 restart

It works with this code

<?php

namespace App\Http\Controllers;
use Illuminate\Routing\Controller as BaseController;
use Imagick;

class GuestController extends BaseController {

    public $imagic;

    public function __construct(){
        $this->imagic = new Imagick();
    }

    public function test(){
        return get_class_methods($this->imagic);
    }
}

This is what worked for me for Laravel 5.7 on Homestead:

sudo apt-get update && sudo apt-get install -y imagemagick php-imagick && sudo service php7.2-fpm restart && sudo service nginx restart

If you're using a version of PHP other than 7.2 or aren't using Nginx, you'll need to adjust.

Try this:

  1. Dowload the extension here (the tarball): http://pecl.php.net/package/imagick

(Lets suppose you use the version: 3.4.3)

  1. Go to the extension directory with the terminal Example

    cd /Downloads/
    
  2. Extract the tarball

    tar xf imagick-3.4.3.tgz
    
  3. Go to the new extracted directory

    cd imagick-3.4.3.tgz
    
  4. Phpize the library (is base written in C)

    phpize
    
  5. Run

    ./configure
    
  6. Run

    make && make test && make install
    
  7. Go to your php.ini (ussualy in Ubuntu located at /etc/php/7.x/cli/php.ini) and add this line:

    extension=imagick.so 
    

That's it. Update php

    service php7.2-fpm restart

and the server (apache, nginx or other).

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!