Adding IMAP to PHP 7.2 on OSX

21,376

Solution 1

Kevin Abel is providing some of the PHP extensions removed from Homebrew/core. You can install the IMAP extension with:

brew tap kabel/php-ext
brew install php-imap

To install a specific version, such as 7.2 use:

brew install [email protected]

Solution 2

Here is how I solved this problem under Mojave:

First, I installed IMAP module for PHP 7.2

brew install kabel/php-ext/[email protected]

Secondly I copied the imap.so from installed folder to the 'extension_dir' used by php.ini

sudo cp /usr/local/lib/php/20170718/imap.so to /usr/local/lib/php/pecl/20170718

Solution 3

There is a much better way to recompile php with IMAP extension directly using Homebrew.

  1. Run brew edit [email protected]

  2. Add depends_on "imap-uw" at the end of the depends_on section

  3. Check which version of openssl is in the depends_on section

  4. Add --with-imap=#{Formula["imap-uw"].opt_prefix} at the end of the --with section

  5. Add --with-imap-ssl=#{Formula["[email protected]"].opt_prefix} after --with-imap. Check sure it is the same version as in the depends_on section

  6. Run brew reinstall --build-from-source [email protected]

  7. It is not necessary to enable the php_imap.so extension in php.ini, because it is already compiled into PHP. You can check phpinfo();

In case of a formula update in the feature, just edit the formula again and reinstall with --build-from-source.

Solution 4

This answer for those who prefer installing imap ext using native commands without adding other taps or smth else.

In short we need to compile extension from sources. Ok, here is the process.

$ # Download sources from php.net of already installed php version. 
$ cd ~/Downloads
$ wget https://www.php.net/distributions/php-7.3.5.tar.gz
$ gunzip php-7.3.5.tar.gz
$ tar xvf php-7.3.5.tar
$ # Go to ext dir 
$ cd php-7.3.5/ext/imap
$ # prepare extension using phpize command, you should 
$ # ensure that you use phpize of proper version from 
$ # already installed php version as checking the API version for example
$ phpize
$ # prepare dependencies
$ # install openssl and imap
$ brew install openssl
$ brew install imap-uw
$ # after all installation check the installed paths of the exts
$ ./configure --with-kerberos --with-imap-ssl=/usr/local/Cellar/openssl/1.0.2r/ --with-imap=/usr/local/Cellar/imap-uw/2007f/
$ make
$ # get extension dir 
$ php -i | grep extension_dir
extension_dir => /usr/local/lib/php/pecl/20180731 => /usr/local/lib/php/pecl/20180731
$ cp modules/imap.so /usr/local/lib/php/pecl/20180731/
$ # add extension to your php.ini
# [imap]
# extension="imap.so"

That's it. Be lucky!

Solution 5

After expired kabel/php-ext/[email protected], I used another tap:

brew tap shivammathur/php

brew tap shivammathur/extensions

brew install [email protected]
Share:
21,376
Laef
Author by

Laef

Updated on February 05, 2021

Comments

  • Laef
    Laef about 3 years

    I'm using PHP 7.2 on OS X El Capitan, installed using Homebrew (of course). Now I'd like to use some IMAP functions from PHP's IMAP extension, but no matter what I search for, I can't find a way to add the extension on OSX.

    Some things I've tried... I have, of course, tried the most commonly recommended approach:

    $ brew reinstall php --with-imap
    

    Yet this fails, returning:

    Warning: php: this formula has no --with-imap option so it will be ignored!
    

    Another method, which I found mentioned in passing, also fails:

    $ brew install php72-imap
    
    Error: No available formula with the name "php72-imap" 
    ==> Searching for a previously deleted formula (in the last month)...
    Warning: homebrew/core is shallow clone. To get complete history run:
      git -C "$(brew --repo homebrew/core)" fetch --unshallow
    
    Error: No previously deleted formula found.
    ==> Searching for similarly named formulae...
    Error: No similarly named formulae found.
    ==> Searching taps...
    ==> Searching taps on GitHub...
    Error: No formulae found in taps.
    

    I'm not exactly sure which direction to go in with this. I'm sure there's an easy, probably documented, way of doing this, but I am yet to find it. Perhaps I'm just looking in the wrong places and using the wrong search terms...

  • Tom
    Tom over 5 years
    This does not provide IMAP extension for 7.2.
  • Ortomala Lokni
    Ortomala Lokni over 5 years
    There is an IMAP extension for PHP 7.1 : github.com/kabel/homebrew-php-ext/blob/master/Formula/…. You can probably adapt it to 7.2 without too much difficulties.
  • Ashiq
    Ashiq over 4 years
    Life saver. This should be the accepted answer. And while executing the commands anyone should check the proper php, openssl, imap-uw version and folders in their local.....
  • phoenix
    phoenix about 4 years
    While this answer give you good general instructions on how to install PHP extensions, it will install the latest PHP version available and NOT the one you need. I went with the answer Alex provided because it's more specific.
  • Maya McKela
    Maya McKela almost 4 years
    Thank you thank you! This worked for me in PHP 7.4 (just changing the brew install to 7.4 accordingly)
  • seven
    seven over 3 years
    unfortunately it does not work - Error: Cannot tap vishal-sancheti/php-ext: invalid syntax in tap!
  • seven
    seven over 3 years
    this is only solution that worked for me on mojave and php 7.3
  • Juan Carlos Salinas Ojeda
    Juan Carlos Salinas Ojeda over 3 years
    This is for linux rigth ?.. any clue for Mac OS X ?
  • Akshay Lokur
    Akshay Lokur over 3 years
    Truly a life saver! Thanks @wtorsi! Works on my MacOS Big Sur in 2021 with php 7.3.
  • tinkerr
    tinkerr about 3 years
    This is a good answer because it does not depend upon random taps. It worked for me.
  • phoenix
    phoenix almost 3 years
    Thanks! This works for 8.0 as well: brew install kabel/php-ext/[email protected]
  • Danielle Suurlant
    Danielle Suurlant almost 3 years
    It worked! These are the kind of answers I love to see: clear, step by step, and working.
  • Fr0zenFyr
    Fr0zenFyr over 2 years
    This is the way to go. I'm using packages from the the tap provided by shivammathur but the method remains pretty much the same, just that I had to add the tap for extensions first. Cheers!
  • unbreak
    unbreak over 2 years
    Big Sur and [email protected] here, and also this solution worked!