Adding IMAP to PHP 7.2 on OSX

谁说我不能喝 提交于 2019-12-10 03:24:19

问题


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...


回答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



回答2:


Here is how I solved this problem under Mojave:

First, I installed IMAP module for PHP 7.2

brew install kabel/php-ext/php@7.2-imap

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



回答3:


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!




回答4:


For those who have trouble in Mojave, I have forked the repository and fixed it use: brew tap vishal-sancheti/php-ext instead



来源:https://stackoverflow.com/questions/51433648/adding-imap-to-php-7-2-on-osx

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!