Install Imagick PHP extension with Laravel valet

As a PHP developer, I like using Laravel valet for the amazing features it has. In one of my projects, I needed to have the Imagick extension to be installed (and enabled of course) on my machine so I can make some adjustments on pictures.

I was following the instructions mentioned on Imagick documentations which tell you to execute the following commands

brew install imagemagick
brew install pkg-config
pecl install imagick
valet restart

Everything went smoothly except the pecl command where I got this error:

Warning: mkdir(): File exists in System.php on line 294
PHP Warning:  mkdir(): File exists in /opt/homebrew/Cellar/php/8.2.1_1/share/php/pear/System.php on line 294

Warning: mkdir(): File exists in /opt/homebrew/Cellar/php/8.2.1_1/share/php/pear/System.php on line 294
ERROR: failed to mkdir /opt/homebrew/Cellar/php/8.2.1_1/pecl/20220829

This error happened because of a conflict in the pecl extensions directory. The solution is to get the correct directory by running this command

pecl config-get ext_dir | pbcopy

That command will copy the directory path to the clipboard. The next step is to create that folder with the following command

mkdir -p {the path in the clipboard}

The -p will create all the missed directories in that path.

Leave a Reply

Your email address will not be published. Required fields are marked *