Fix HTTP2 in cURL and Laravel Valet

While working with Apple’s new API for push notifications and Laravel, I had to make requests to Apple’s servers via http2 from my local Laravel Valet instance.

Lately, the brew team has changed the way PHP and cURL are distributed in Homebrew. You no longer change how PHP is installed without messing with the brew installation.

However, there is a trick: install “curl-openssl” and you will get http2 support included for free. Since “brew php” seems to be linked against “brew curl” you can swap out curl.

# Uninstall curl
brew uninstall --ignore-dependencies curl
brew uninstall --force curl

# Install curl with openssl, which has http2 support
brew install curl-openssl

Here is a simple little script you can run to make sure you have http2-support

if (
    defined("CURL_VERSION_HTTP2") &&
    (curl_version()["features"] & CURL_VERSION_HTTP2) !== 0
) {
    $url = "";
    $ch = curl_init();
    curl_setopt_array($ch, [
        CURLOPT_URL            =>$url,
        CURLOPT_HEADER         =>true,
        CURLOPT_NOBODY         =>true,
    $response = curl_exec($ch);
    if ($response !== false && strpos($response, "HTTP/2") === 0) {
        echo "HTTP/2 support!";
    } elseif ($response !== false) {
        echo "No HTTP/2 support on server.";
    } else {
        echo curl_error($ch);
} else {
    echo "No HTTP/2 support on client.";