Homebrew: install new formula php72-imagick
Asked Answered
U

3

11

I need install imagick module on my php 7.2

I see

brew search php72
==> Searching local taps...
==> Searching taps on GitHub...
==> Searching blacklisted, migrated and deleted formulae...
No formula found for "php72".
Closed pull requests:
...
php72-imagick 3.4.3 (new formula) (https://github.com/Homebrew/homebrew-php/pull/4267)

How can I do it?

Also I need support for argon

Undesigning answered 27/4, 2018 at 10:4 Comment(0)
M
50

It all changed back in April 2018 I think. Homebrew no longer acts as the package manager for PHP, so all the php-imagick and php-redis and php-other-extension stuff has gone and you are now supposed to manage PHP packages using pecl like everyone else does.

So, how to get Imagick under PHP? Note that Imagick and ImageMagick are two different things:

  • ImageMagick is the entire ImageMagick suite
  • Imagick is just the PHP binding

Here are the steps - if anyone knows better or any improvements, let me know via comment and I will update.


Step 1 - Delete anything likely to conflict

Before starting, it is best to clean up all the stuff that is broken or unneeded. Do as many of these as you are comfortable with:

brew rm php [email protected] [email protected] [email protected]
brew rm imagemagick

Step 2 - Update Xcode command line tools and get build packages

Make sure you have installed Xcode command-line tools with:

xcode-select --install

Go to AppStore and click on Updates and update any Xcode related packages - especially if you have recently upgraded macOS.

Install homebrew building tools:

brew install pkg-config

Step 3 - Install ImageMagick

Check what ImageMagick options you want with:

brew options imagemagick

I like to use:

brew install imagemagick --with-x11 --with-librsvg --with-openexr --with-pango
hash -r

but you may like vanilla install:

brew install imagemagick
hash -r

Step 4 - Install homebrew PHP

Next, install the homebrew version of PHP with:

brew install php
hash -r                    # Update bash's internal paths

Now, critically ensure you are running the correct homebrew PHP:

type php

If that tells you:

/usr/local/...anything.../php

you are running homebrew PHP and you can go to the next step.

If it tells you:

/usr/bin/php

you are running the Apple-supplied PHP. If that is what you want to run, ignore my entire answer which is predicated on you wanting to use homebrew PHP. If you get this answer but want to run homebrew PHP, your PATH is set incorrectly. You need to put /usr/local/bin before /usr/bin to pick up all homebrew packages ahead of Apple programs, i.e.

export PATH=/usr/local/bin:$PATH

This step gives you pecl - the PHP Package Manager - as well, since it is part of homebrew PHP.


Step 5 - Install Imagick

Now you can install Imagick with pecl:

pecl install imagick

If anything goes wrong, here are some related questions and answers...

Q1. How can I find where my php.ini file is?

Try any of these commands:

pecl config-get php_ini                  # I get "/usr/local/etc/php/7.2/php.ini"
brew info php
php -i | grep "Loaded Configuration"     # I get "Loaded Configuration File => /usr/local/etc/php/7.2/php.ini"

Q2. How can I find where pecl installs modules?

pecl config-get ext_dir                 # I get "/usr/local/lib/php/pecl/20170718"

Q3. How can I tell what PHP modules are loaded?

php -m

Q4. Why can't PHP find my module?

First locate your modules directory using Q2. I like to put that in the clipboard with:

pecl config-get ext_dir | pbcopy

Then edit the php.ini file from Q1. I use vi, so I would do:

vi "$(pecl config-get php_ini)"

Then find the line in that file that looks like this:

; Directory in which the loadable extensions (modules) reside.
; http://php.net/extension-dir

and, then (using the contents of your paste buffer) make the following line look like this (no semi-colon at the start):

extension_dir = "/usr/local/lib/php/pecl/XXXXXX"

on my machine XXXXXX is 20170718. If you get this right, any and all modules you install via pecl will be visible to your homebrew PHP.

Q5. How can I see all my PHP settings?

Check PHP configuration, versions and settings with:

php -i
Manion answered 25/5, 2018 at 12:57 Comment(7)
Thank you, it helped me a lot! I was having issues due missing imagemagick library.Underwaist
'brew rm php [email protected] [email protected] [email protected]' gave me an error message that those casks did not exist, all worked apart from thatPyrrha
Bless you! But 1. I had to add the mkdir /usr/local/lib/php/pecl dir before pecl install imagick and 2. clean the /usr/local/etc/php/7.2/conf.d dir to get rid of PHP warningsCrawfish
@Mark Setchell - I can't thank you enough for this detailed explanation and overview! I've been struggling to get Imagemagick installed, and you sir have saved me! Thank you so, so much!Dipeptide
Thanks for this. God look at all those steps just to get imagick up and running.Baseborn
@Mark Setchell pecl install imagick -> No releases available for package "pecl.php.net/imagick on High SierraRidings
@Mirko same message happened to me, anyone knows why?Monogamist
E
1

In my case (PHP 7.2.10 with Homebrew) works:

pecl install imagick

Open the file php.ini and remove extension line with imagick extension.

Check *.ini files with

php --ini

You can see paths to extension files. Create or edit imagick ini file.

subl /usr/local/etc/php/7.2/conf.d/ext-imagick.ini

The content of file may be (check the path to imagick.so)

[imagick]
extension="/usr/local/opt/php/pecl/20170718/imagick.so"

And restart php with

brew services restart php

Try, if the error message dissapear:

php -v

And check imagick extension with:

php -i | grep imagick

If you see line with imagick module => enabled you have solved a problem.

Electrokinetics answered 3/10, 2018 at 8:48 Comment(0)
D
-1

You want php72-gmagick, GraphicsMagick is a fork from ImageMagick 5.5.2.

Or, you can pecl install imagick still.

Diastema answered 25/5, 2018 at 9:28 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.