10

I've followed these steps to install imagemagick and php extension imagick in my computer with Mac OS Catalina and I can't seem to find a way.

I always get the following error when trying to install imagick with $ sudo pecl install imagick:

php_imagick.h:42:10: fatal error: 'php.h' file not found
#include "php.h"
         ^~~~~~~
1 error generated.
make: *** [imagick_file.lo] Error 1
ERROR: `make' failed

I'm using php.7.3.11.

Apparently Mac OS X Catalina decided to move the headers to another folder and now it doesn't seem to find them.

I've been reading this answer but seems like the solution is too long to be true. Isn't there any other more simple and straight forward method?

It seems others manage to fix it for other extensions with much less trouble. However, I'm not quite sure the steps for Imagick are exactly the same...

Alvaro
  • 40,778
  • 30
  • 164
  • 336
  • I didn't have any issue installing `imagick` on `macOS 10.15.4` using these instructions and `sudo pecl install imagick`. *`install ok: channel://pecl.php.net/imagick-3.4.4`* ; and I can see it if I run `php -m | grep -i magic`. Is this problem related just to `PHP 7.3`? I just `brew install php` and it got `PHP 7.4.4`. – Christos Lytras Apr 09 '20 at 00:41

2 Answers2

10

I had this same issue with my new MacBook Air and Catalina. It was a because I did not have PHP installed with brew. I looked at the page you linked to, and I am assuming you have already completed the brew install pkg-config imagemagick. This is what I would do to get clean it up and get it working, see below.

Remove your existing imagemagick and pkg-config that were just installed (and PHP if it shows up in the versions list)

First, we get the php @ver name if necessary. If you don't see PHP in the list then we don't need to remove it, just remove the other two.


    brew list --versions
    ...
    imagemagick 7.0.10-0
    ...
    pcre 8.44
    php@7.3 7.3.16
    pkg-config 0.29.2_2
    ...

Stop the php service if it is running, in my case it is @7.3

brew services stop php@7.3

Next we remove the items having issue

brew remove php@7.3 pkg-config imagemagick

or simply

brew remove pkg-config imagemagick if PHP not installed with brew

Restart your computer (optional, but I like to do it)

Now we install the items again, include PHP this time if it was not installed with brew last time

brew install php@7.3 pkg-config imagemagick

Add PHP to your path for cmd line if not already there (optional)

echo 'export PATH="/usr/local/opt/php@7.3/bin:$PATH"' >> ~/.bash_profile

echo 'export PATH="/usr/local/opt/php@7.3/sbin:$PATH"' >> ~/.bash_profile

To have launchd start php@7.3 now and restart at login:

brew services start php@7.3

Or, if you don't want/need a background service you can just run:

php-fpm

Confirm PHP and imagemagick and perl/pecl are the expected versions

php -v

PHP 7.3.16 (cli) (built: Mar 19 2020 11:19:09) ( NTS )
Copyright (c) 1997-2018 The PHP Group
Zend Engine v3.3.16, Copyright (c) 1998-2018 Zend Technologies
    with Zend OPcache v7.3.16, Copyright (c) 1999-2018, by Zend Technologies

convert --version

Version: ImageMagick 7.0.10-0 Q16 x86_64 2020-04-04 https://imagemagick.org
Copyright: © 1999-2020 ImageMagick Studio LLC
License: https://imagemagick.org/script/license.php
Features: Cipher DPC HDRI Modules OpenMP(3.1) 
Delegates (built-in): bzlib freetype gslib heic jng jp2 jpeg lcms ltdl lzma openexr png ps tiff webp xml zlib

pecl version

PEAR Version: 1.10.10
PHP Version: 7.3.16
Zend Engine Version: 3.3.16
Running on: Darwin mbookair.local 19.4.0 Darwin Kernel Version 19.4.0: Wed Mar  4 22:28:40 PST 2020; root:xnu-6153.101.6~15/RELEASE_X86_64 x86_64

Now install iMagick using pecl

pecl install imagick

hit ENTER when you see the path question for 'autodetect'

When it's complete you can confirm the module is loaded php -m | grep imagick

if it's loaded it will return one line with the word imagick

Test from command line imagick installed correctly cd to your user home dir cd ~

Run PHP as interactive shell from cmd line

php -a

Code to test at cmd line:

$im = new Imagick ();
$im->newImage (300, 225, "blue");
$im->writeImage ("test_imagick.jpg");

Exit php interactive mode by typing exit, then check if the bright blue test_imagick.jpg was created in your user dir

Troubleshooting Notes

If you are getting a warning about:

"PHP Warning:  Module 'imagick' already loaded in Unknown on line 0

Warning: Module 'imagick' already loaded in Unknown on line 0"

This may be left over from the previous pecl install that did not complete. Check your php.ini file and remove duplicate extension="imagick.so" entry

Community
  • 1
  • 1
mstephenson
  • 309
  • 2
  • 9
  • 1
    I can't believe it is soooo complicated to install... isn't there any other more human way? I feel like there's something very wrong with PHP if we have to do all this to install a simple extension. – Alvaro Apr 10 '20 at 17:14
  • 2
    My answer was longer because I was trying to provide instructions on how to unwind anything you may have done and then do a somewhat of a fresh install with a way to test from PHP at the cmd line to ensure imagick was installed and working. The short answer is: **1)** `brew install php@7.3`, **2)** `brew reinstall pkg-config imagemagick`, **3)** `pecl install imagick`. Does that work? – mstephenson Apr 11 '20 at 02:32
  • the same error will be shown when issuing `pecl install imagick` – Raptor Sep 09 '20 at 02:57
  • Great answer, thank you! Worked for me. I've finally bit the bullet and moved Mac OS over to homebrew for php, much easier now! – Luc Sep 15 '20 at 22:40
  • for me just adding the two bash_profile lines worked with source .bask_profile – TeT Psy Jan 14 '21 at 06:01
0

There is a bug in home brew, here is the link https://github.com/Homebrew/homebrew-core/issues/41081

When you get tired of home brew, switch to Ubuntu, install imagick no fuss package installation.

Joseph Olstad
  • 93
  • 1
  • 5