ImageMagick Brew installation with PHP Module in Mac OS X
Your ImageMagick installation is not enough. You also need the Imagick package (possibly called php72-imagick
or similar for home brew).
Imagick doesn't do the work itself, it is a native PHP extension for creating and modifying images using the ImageMagick API.
Try to search for the exact name of the package via brew search imagick
.
How do I install imagemagick with homebrew?
The quickest fix for me was doing the following:
cd /usr/local
git reset --hard FETCH_HEAD
Then I retried brew install imagemagick
and it correctly pulled the package from the new mirror, instead of adamv.If that does not work, ensure that /Library/Caches/Homebrew
does not contain any imagemagick files or folders. Delete them if it does.
Homebrew: install new formula php72-imagick
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
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 php@5.6 php@7.0 php@7.1
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
How to set up phpimagik in Mac OS X?
Yes, use homebrew
. Go to the homebrew website and install it with the one line script there. - I don't want to paste it here because you need the latest and greatest line at the time of following these instructions.
Then, when you have homebrew
installed, do these steps to get ImageMagick installed and running under PHP and also with Apache.
# Check all of homebrew is working - fix any errors before proceeding
brew doctor
# Get latest versions of everything if you already had "homebrew" installed
# Probably not necessary if you just installed "homebrew" in previous step
brew update && brew upgrade
# Find latest PHP version - using "brew search"
newestPHP=$(brew search php | grep -E "php[0-9]+$" | sort | tail -1)
echo $newestPHP
e.g. php56
# Install latest PHP and corresponding ImageMagick
brew install ${newestPHP} ${newestPHP}-imagick
e.g. brew install php56 php56-imagick
# Check that the installation worked - you MUST use "/usr/local/bin/php"
/usr/local/bin/php -i | grep -i imag
OutputAdditional .ini files parsed => /usr/local/etc/php/5.6/conf.d/ext-imagick.ini
PHP Warning: Unknown: It is not safe to rely on the system's timezone settings. You are *required* to use the date.timezone setting or the date_default_timezone_set() function. In case you used any of those methods and you are still getting this warning, you most likely misspelled the timezone identifier. We selected the timezone 'UTC' for now, but please set date.timezone to select your timezone. in Unknown on line 0
imagick
imagick module => enabled
imagick module version => 3.1.2
imagick classes => Imagick, ImagickDraw, ImagickPixel, ImagickPixelIterator
ImageMagick version => ImageMagick 6.9.1-1 Q16 x86_64 2015-04-15 http://www.imagemagick.org
ImageMagick copyright => Copyright (C) 1999-2015 ImageMagick Studio LLC
ImageMagick release date => 2015-04-15
ImageMagick number of supported formats: => 204
ImageMagick supported formats => 3FR, AAI, AI, ART, ARW, AVI, AVS, BGR, BGRA, BGRO, BMP, BMP2, BMP3, BRF, CAL, CALS, CANVAS, CAPTION, CIN, CIP, CLIP, CMYK, CMYKA, CR2, CRW, CUR, CUT, DCM, DCR, DCX, DDS, DFONT, DNG, DOT, DPX, DXT1, DXT5, EPDF, EPI, EPS, EPS2, EPS3, EPSF, EPSI, ERF, FAX, FITS, FRACTAL, FTS, G3, GIF, GIF87, GRADIENT, GRAY, GV, HALD, HDR, HISTOGRAM, HRZ, HTM, HTML, ICB, ICO, ICON, IIQ, INFO, INLINE, IPL, ISOBRL, JNG, JNX, JPE, JPEG, JPG, JPS, JSON, K25, KDC, LABEL, M2V, M4V, MAC, MAP, MASK, MAT, MATTE, MEF, MIFF, MKV, MNG, MONO, MOV, MP4, MPC, MPEG, MPG, MRW, MSL, MSVG, MTV, MVG, NEF, NRW, NULL, ORF, OTB, OTF, PAL, PALM, PAM, PANGO, PATTERN, PBM, PCD, PCDS, PCL, PCT, PCX, PDB, PDF, PDFA, PEF, PES, PFA, PFB, PFM, PGM, PICON, PICT, PIX, PJPEG, PLASMA, PNG, PNG00, PNG24, PNG32, PNG48, PNG64, PNG8, PNM, PPM, PREVIEW, PS, PS2, PS3, PSB, PSD, PWP, RADIAL-GRADIENT, RAF, RAS, RAW, RGB, RGBA, RGBO, RGF, RLA, RLE, RMF, RW2, SCR, SCT, SFW, SGI, SHTML, SIX, SIXEL, SPARSE-COLOR, SR2, SRF, STEGANO, SUN, SVG, SVGZ, TEXT, TGA, THUMBNAIL, TILE, TIM, TTC, TTF, TXT, UBRL, UIL, UYVY, VDA, VICAR, VID, VIFF, VIPS, VST, WBMP, WMV, WPG, X3F, XBM, XC, XCF, XPM, XPS, XV, YCbCr, YCbCrA, YUV
imagick.locale_fix => 0 => 0
imagick.progress_monitor => 0 => 0
That completes the installation if you only want to run ImageMagick under PHP outside your website.The remaining steps are only necessary if you want to run PHP and ImageMagick under Apache inside your website.
# Check if PHP module loaded in Apache config file - /etc/apache2/httpd.conf
grep "^LoadModule.*php5_module.*libphp.*" /etc/apache2/httpd.conf
Check it matches, or if not present add a line like this
LoadModule php5_module /usr/local/Cellar/php56/5.6.6/libexec/apache2/libphp5.so
# Restart Apache
sudo apachectl restart
PHP Imagemagick installation - XAMPP and macosx
If you don't have Brew yet then get it from here https://github.com/mxcl/homebrew
Once setup you can use brew search magick
to see the available packages.
Related Topics
Disable Doctrine 2 Lazy Loading When Using Jms Serializer
Zend Framework 2 - Global Check for Authentication with Zfcuser
How to Split a String into an Array of Unicode Characters in PHP
How to Watch a File Write in PHP
Image Upload from iPhone Strips Exif Data
Adding an Admin Page on Opencart Version 2
Creating and Invoking an Anonymous Function in a Single Statement
How to Upload Files in Web Workers Without Using Formdata
Merging Overlapping Ranges in PHP Arrays
PHP MySQL - Insert into Without Using Column Names But with Autoincrement Field
Call to Undefined Function Curl_Init() - with Wamp
Converting Nsarray -> JSON -> Nsdata -> PHP Server ->JSON Representation
PHP Splitting an Array into Two Arrays - Keys Array and Values Array
MySQL Fulltext Search Multiple Words
Posting to a Facebook Page as the Page (Not a Person)
Print Directly to Network Printer Using PHP
Pdo Prepared Statements for Insert and on Duplicate Key Update with Named Placeholders