Start HTTP/2
Enable HTTP/2 with libnghttp2, PHP FFI and local TLS, then check the negotiated version.
Install the package
Use PHP CLI 8.3 or a later 8.x release on a supported Unix system. Install the package in your application directory. Composer checks for the required pcntl, posix and sockets extensions.
apt · Debian / Ubuntu
sudo apt update
sudo apt install php-cli php-common composer curlsudo apt install libnghttp2-14apk · Alpine 3.24 (community)
apk add php85 php85-pcntl php85-posix php85-sockets composer curlapk add php85-ffi nghttp2-libspacman · Arch Linux
sudo pacman -Syu --needed php composer curl
php --iniEnable sockets in the CLI php.ini. For HTTP/2 and HTTP/3, also enable ffi.
sudo pacman -S --needed libnghttp2dnf · Fedora
sudo dnf install php-cli php-process composer curlsudo dnf install php-ffi libnghttp2brew · macOS
brew install php composer curlbrew install libnghttp2In the test terminal, use Homebrew curl.
export PATH="$(brew --prefix curl)/bin:$PATH"php -v
composer require mini4work/webserver
composer check-platform-reqsphp --ri opensslphp --ri ffi
curl -VPHP needs OpenSSL and the FFI extension. The launch command enables FFI for this CLI invocation. The client should list HTTP2 under Features.
Start the server
Save this as m4w.json in the application root. It creates development certificates in var/tls. The client will trust the public CA explicitly for its request.
{
"listen": { "port": 9000 },
"protocols": {
"http": "2"
},
"tls": {
"mode": "local",
"storage": "var/tls",
"local": {
"trust_ca": "off"
}
}
}php -d ffi.enable=true vendor/mini4work/webserver/examples/server.php m4w.jsonSend a request
In another terminal, replace the CA path below with the public certificate path from the server’s tls.trust.root event.
CA=/path/from/tls.trust.root
curl --http2 --cacert "$CA" -sS -o /dev/null \
-w 'HTTP/%{http_version} %{http_code}\n' https://127.0.0.1:9000/HTTP/2 200