How to install and enable ext-http for php8.1 in Laravel Herd on Mac Sonoma
It can be a bit tricky to install and enable the php ext-http extension on Laravel Herd with homebrew. Here is a small guide to help with that.
Laravel Herd comes with a bunch of default extensions enabled. But if you need ext-http you'll find out that it's not enabled by default. Here is small guide how you can install and enable it. I tested it on a Mac Sonoma. First of all make sure, to read the section in the docs where they explain how to enable and load new extensions into herd: Installing PHP Extensions. Now you understand that you need homebrew to install these extensions, which you then kinda hook into your Laravel Herds php.ini config.
#Install ext-http via PECL
You can install the php http extension with pecl:
1pecl install pecl_http
But they now gonna ask you for a lot of lib paths and maybe some of those libs are not yet installed on your machine.
For me the following worked:
1brew install curl zlib libidn libidn2
Now you can provide the following paths during the installation:
1...
2...
3./autoconf/pecl/pecl.m4:362: PECL_CHECK_DONE is expanded from...
4config9.m4:171: the top level
5where to find zlib [/usr] : /opt/homebrew/opt/zlib
6where to find libcurl [/usr] : /opt/homebrew/opt/curl
7where to find libevent [/usr] : /opt/homebrew/opt/libevent
8where to find libicu [/usr] : /opt/homebrew/opt/icu4c
9where to find libidn2 [/usr] : /opt/homebrew/opt/libidn2
10where to find libidn [/usr] : /opt/homebrew/opt/libidn
11where to find libidnkit2 [/usr] :/opt/homebrew/opt/libidn2
12where to find libidnkit [/usr] /opt/homebrew/opt/libidn
As libidnkit seems to be deprecated on my Mac version, I was just able to put libidn in the path.
#Enable the extensions
Installing pecl also automatically installs raphf.
We need to add these paths to the herd php.ini file (you can open the config files in the Laravel Herd menu bar icon dropdown).
1# make sure that the number matches your php version here!
2extension=/opt/homebrew/lib/php/pecl/20210902/raphf.so
3extension=/opt/homebrew/lib/php/pecl/20210902/http.so
Now restart herd and you're done!