PHP module “imagick” failed to install with “error: not found. Please provide a path to MagickWand-config or Wand-config program.” Solve it in 2 minutes

`imagick` installation

At around 04:30 in the early morning of Monday, January 12t, 2024, I had a spontaneous epiphany. It was clearer than ever that my iMac—already an old model bought in 2022 with only an M1 chip—needed to be wiped clean and its OS reinstalled. A total reset, barely two hours before sunrise.

tl;dr

  1. Find out your currently running PHP version with php -v
  2. cd into the binaries directory shown via which php
  3. Run ./pecl install imagick

A Fresh Start

Now, I know myself a little bit. Deleting a project (or an OS, in this case) and starting from scratch is a habit that very few people in the development world have an understanding of. Even to me, it was clear how disturbed this sounds: “You’re going to delete all of that, all the code that you’ve been working on in the last days, weeks, or even months?” Yup, I am.

This is how much I hate unorganized code. And even if it’s me who started the project, at some point, I might throw in something new, tinkered around with it, and it ended up giving me all kinds of errors. What I want need is a clean project.

My iMac is not necessarily one of these projects, but the same things apply here. Since buying it in August 2022, I’ve changed, enabled, disabled, tried, removed, and installed so many packages, modules, and apps that I couldn’t list them even if my life depended on them.

So, a fresh install does make some sense, at least. I wanted to get rid of all the digital shit that these things left behind, despite promising me of having it all properly uninstalled. If you check the path /Users/kolja/Library/Application Support, you’ll see what I mean.

IMPORTANT:
This is your reminder to create a fucking Time Machine backup. Now!

Setting up macOS—again

A’ight, so, after formatting my internal SSD and basically wiping every single file of my filesystem, I reinstalled macOS 15.2 (24C101). I’ll spare you the tedious list of tools, packages, and apps that I’ve since then reinstalled because it’s only about one of them: PHP

At this point, it might make sense to, again, point out that I’m using an iMac with a macOS file structure. The paths here won’t necessarily be the paths on non-macOS systems.

Shortly before pulling the plug, some websites made me aware of an Open Source tool named FlyEnv (not to be confused with Local by FlyWheel, which is very limited). In a few words: FlyEnv is a tool that creates a local environment for any sort of local development; PHP, Node.js, Redis—all installable through a single UI (through brew) and easily managed.

So, this is what I had, and through this, I installed my services:

  1. Apache
  2. nginx
  3. PHP
  4. MySQL
  5. MariaDB

…and anything else that makes sense for a web developer.

Installing was easy, but the first time it came with some errors. IPs already in use despite the service being off… things like this. A restart and reinstallation fixed this problem.

WordPress

To test, I installed WordPress 6.7. This isn’t a tutorial for FlyEnv, so I’m not going to show how (easy) this task is, but you guys can probably imagine.

Logged into the Dashboard, I wanted to see if the server really used the software I had selected in FlyEnv—and, yes, it did. Congratulations!

Then came the usual recommendation: No SSL active, no caching plugin, and the PHP module imagick missing. All standard stuff and easy to solve.

Installing imagick

I didn’t care about SSL and the caching plugin because I knew I could just turn them on in the FlyEnv UI, but I wanted to install imagick, mainly because I downloaded a couple of PHP versions and wanted to see how that’s being handled by FlyEnv.

Installing imagick is often just one single command through PECL. Imagine PECL as an extension manager for PHP, a little bit like pip for Python, or, even more abstractly, the AppStore for iPhones (okay, the last one was really a stretch, but you get the idea).

The Error

Naturally, I tried it the easy way: I opened my command line and wrote the following command:

pecl install imagick
Bash

And pecl began to install:

Mind you, when I entered php -v, I saw that my current systemwide PHP version was 8.4.2.

But the version in FlyEnv was different. I had set the WordPress site with PHP 8.2.27 (to reproduce a bug, if you really want to know, you nosy reader!). So, naturally, I had to cd into the directory of this version:

cd /opt/homebrew/Cellar/php@8.2/8.2.27
Bash

Inside, there is a file called pecl, as we can see when we use ls:

  8.2.27 git:(stable) ls -l
total 360
-rw-r--r--@  1 kolja  admin   9464 13 Jan 06:49 INSTALL_RECEIPT.json
-rw-r--r--@  1 kolja  admin   3204 17 Dez 18:39 LICENSE
-rw-r--r--@  1 kolja  admin  90366 17 Dez 18:39 NEWS
-rw-r--r--@  1 kolja  admin   5074 17 Dez 18:39 README.md
drwxr-xr-x@ 12 kolja  admin    384 13 Jan 06:49 bin
-rw-r--r--@  1 kolja  admin    789 13 Jan 06:49 homebrew.mxcl.php@8.2.plist
-rw-r--r--@  1 kolja  admin    285 13 Jan 06:49 homebrew.php@8.2.service
drwxr-xr-x@  3 kolja  admin     96 17 Dez 18:39 include
drwxr-xr-x@  4 kolja  admin    128 17 Dez 18:39 lib
lrwxr-xr-x@  1 kolja  admin     26 13 Jan 06:49 pecl -> /opt/homebrew/lib/php/pecl
drwxr-xr-x@  3 kolja  admin     96 13 Jan 06:49 sbin
-rw-r--r--@  1 kolja  admin  53807 13 Jan 06:49 sbom.spdx.json
drwxr-xr-x@  5 kolja  admin    160 17 Dez 18:39 share
Bash

But if you look closely enough, this “file” is no file but a link. And wherever it may lead to, it doesn’t lead to the binary of PHP 8.2.27. I tried installing it via ./pecl install imagick, and was the result:

ERROR: /private/tmp/pear/temp/imagick/configure --with-php-config=/opt/homebrew/opt/php@8.2/bin/php-config --wi
th-imagick' failed
Bash

The Solution

The solution is so easy that I’m a little embarrassed that I’ve wasted your time reading until this point (if at all).

I cd into bin and used the same command there:

cd bin && ./pecl install imagick
Bash

This time, the output looked better:

I was happy. And after restarting PHP in FlyEnv, WordPress was happy, too.