Welcome to Abdul Malik Ikhsan's Blog

Install Imagick extension for PHP 8 in macOS Big Sur

Posted in Teknologi, Tutorial PHP by samsonasik on January 4, 2021

I am really grateful I’ve had a chance to have the Mac mini M1 on a new year 2021. It’s really fast, even I only use 8 gigs ram version! Also, the software that in my old mac no longer can use its latest update – like php with homebrew – is back! In this post, I will show you how to install imagick for PHP 8 in macOS Big Sur for it.

First, I assume that you already have Homebrew installed. Next is install PHP 8, we can use shivammathur/php for it, the installation steps are in its readme.

When PHP 8 installed, we can ensure that imagemagick already installed, if not, if we can install via Homebrew as well:

$ brew install imagemagick

Now, time to install imagick. There is no imagick release yet for php 8, but we can install the dev-master already following this issue :

$ git clone https://github.com/Imagick/imagick
$ cd imagick
$ phpize && ./configure
$ make
$ sudo make install

When you run make, if you got the following error:

/opt/homebrew/Cellar/php/8.0.0_1/include/php/ext/pcre/php_pcre.h:23:10: fatal error: 'pcre2.h' file not found

You can copy installed pcre2.h from Homebrew:

cp /opt/homebrew/Cellar/pcre2/10.36/include/pcre2.h .

Next, you can re-run :

$ make
$ sudo make install

After it installed, you can register imagick.so to /opt/homebrew/etc/php/8.0/php.ini:

extension="imagick.so"

Now, let’s check if it is installed:

➜  ~ php -a
Interactive shell

php > echo phpversion('imagick');
@PACKAGE_VERSION@

Yes, above @PACKAGE_VERSION@ should be just fine. That’s it!

5 Responses

Subscribe to comments with RSS.

  1. Lambert Torres said, on June 26, 2021 at 12:40 am

    I’m seeing a different error when trying to install the extension. I’m trying to install imagemagick for use with php7.3. I can get it to configure and build. but installing has the following error

    mkdir: /usr/local/Cellar/php@7.3/7.3.28_1/pecl: File exists
    mkdir: /usr/local/Cellar/php@7.3/7.3.28_1/pecl: No such file or directory
    make: *** [install-modules] Error 1

    cd into the folder above I can see pecl is a symlink to

    admin 23 Jun 24 20:20 pecl -> /usr/local/lib/php/pecl

    Any suggestion or recommendation?

    • samsonasik said, on June 26, 2021 at 4:43 pm

      I am not sure, it shows `/opt/homebrew/bin/pecl` in my local dev:

      ➜  ~ ls -al /opt/homebrew/bin/pecl
      lrwxr-xr-x  1 samsonasik  staff  28 Jun  9 14:03 /opt/homebrew/bin/pecl -> ../Cellar/php/8.0.7/bin/pecl
      
      • Lambert Torres said, on July 1, 2021 at 12:11 am

        okay your symlink is different than mine. mine is pointing to:

        /usr/local/Cellar/php@7.3/7.3.28_1/pecl -> /usr/local/lib/php/pecl

        I wonder if I move pecl to another folder things will be different.

  2. Lambert Torres said, on July 1, 2021 at 12:43 am

    Hi following this up. following this thread here. https://github.com/Homebrew/homebrew-core/issues/41081. I was able to create the folder then after rerunning the sudo make install command able to install the extension. Thanks for this guide.


Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s

%d bloggers like this: