21

我在 OS X El Capitan 上使用 PHP 7.2,使用 Homebrew 安装(当然)。现在我想使用 PHP 的 IMAP 扩展中的一些 IMAP 函数,但是无论我搜索什么,我都找不到在 OSX 上添加扩展的方法。

我尝试过的一些事情......当然,我尝试了最常用的方法:

$ brew reinstall php --with-imap

然而这失败了,返回:

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

我发现顺便提到的另一种方法也失败了:

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

我不确定该朝哪个方向发展。我确信有一种简单的、可能有记录的方法可以做到这一点,但我还没有找到。也许我只是在错误的地方寻找并使用错误的搜索词......

4

6 回答 6

29

Kevin Abel提供了一些从Homebrew/core中删除的 PHP 扩展。您可以通过以下方式安装 IMAP 扩展:

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

要安装特定版本,例如 7.2,请使用:

brew install php@7.2-imap
于 2018-07-29T20:18:27.440 回答
17

以下是我在 Mojave 下解决此问题的方法:

首先,我为 PHP 7.2 安装了 IMAP 模块

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

其次,我将 imap.so 从已安装文件夹复制到 php.ini 使用的“extension_dir”

sudo cp /usr/local/lib/php/20170718/imap.so to /usr/local/lib/php/pecl/20170718
于 2019-02-07T09:47:56.917 回答
11

对于那些喜欢imap使用本机命令安装 ext 而不添加其他水龙头或其他东西的人来说,这个答案。

简而言之,我们需要从源代码编译扩展。好的,这是过程。

$ # 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"

而已。幸运!

于 2019-05-10T10:19:46.033 回答
9

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

  1. Run brew edit php@7.4

  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["openssl@1.1"].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 php@7.4

  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.

于 2021-02-04T14:04:44.223 回答
5

expired 后kabel/php-ext/php@7.2-imap,我用了另一个水龙头:

brew tap shivammathur/php

brew tap shivammathur/extensions

brew install imap@7.2
于 2020-12-22T10:19:54.140 回答
1

对于那些在莫哈韦遇到麻烦的人,我已经分叉了存储库并修复了它使用: brew tap vishal-sancheti/php-ext而不是

于 2019-01-07T08:02:59.493 回答