There is a much better way to recompile php with IMAP extension directly using Homebrew.
UPDATE 2023/0209: this procedure works even with the php8. Just use php instead of versioned formula [email protected]. Please note openssl has changed version to openssl@3.
Run brew edit [email protected]
Add depends_on "imap-uw" at the end of the depends_on section
Check which version of openssl is in the depends_on section
Add --with-imap=#{Formula["imap-uw"].opt_prefix} at the end of the --with section
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
Run HOMEBREW_NO_INSTALL_FROM_API=1 brew reinstall --build-from-source [email protected]
UPDATE 2023/02: If you dont prepend with HOMEBREW_NO_INSTALL_FROM_API=1, then modified file is not used. Behavior changed from 2023/01, more on https://github.com/Homebrew/brew/pull/14412It 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.