Start HTTP/1.1 with TLS

HTTP/1.1 with local TLS and an explicit CA for curl.

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
Shell
sudo apt update
sudo apt install php-cli php-common composer curl
apk · Alpine 3.24 (community)
Shell
apk add php85 php85-pcntl php85-posix php85-sockets composer curl
pacman · Arch Linux
Shell
sudo pacman -Syu --needed php composer curl
php --ini

Enable sockets in the CLI php.ini. For HTTP/2 and HTTP/3, also enable ffi.

dnf · Fedora
Shell
sudo dnf install php-cli php-process composer curl
brew · macOS
Shell
brew install php composer curl

In the test terminal, use Homebrew curl.

Shell
export PATH="$(brew --prefix curl)/bin:$PATH"
Shell
php -v
composer require mini4work/webserver
composer check-platform-reqs
php --ri openssl

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.

JSON
{
  "listen": { "port": 9000 },
  "protocols": {
    "http": "1.1"
  },
  "tls": {
    "mode": "local",
    "storage": "var/tls",
    "local": {
      "trust_ca": "off"
    }
  }
}
Shell
php vendor/mini4work/webserver/examples/server.php m4w.json

Send a request

In another terminal, replace the CA path below with the public certificate path from the server’s tls.trust.root event.

Shell
CA=/path/from/tls.trust.root
curl --http1.1 --cacert "$CA" -sS -o /dev/null \
  -w 'HTTP/%{http_version} %{http_code}\n' https://127.0.0.1:9000/

HTTP/1.1 200

Choose a TLS mode