Open Swoole TLS and HTTPS

4.x is outdated, please check the latest version 22.x

Latest version: pecl install openswoole-22.1.2

Generate SSL certificate for your development environment with mkcert

You can use mkcert to generate SSL certificate and setup CA at your local development environment.

mkcert -install

# Created a new local CA 💥
# The local CA is now installed in the system trust store! ⚡️
# The local CA is now installed in the Firefox trust store (requires browser restart)! 🦊

mkcert "*" example.test localhost ::1

#Created a new certificate valid for the following names 📜
# - ""
# - "*"
# - "example.test"
# - "localhost"
# - ""
# - "::1"

# The certificate is at "./" and the key at "./" ✅

Enable HTTPS at Open Swoole Server?

You can enable SSL for HTTP server or HTTP2 server, WebSocket server with the following settings:

    'ssl_cert_file' => __DIR__ . '/config/',
    'ssl_key_file' => __DIR__ . '/config/'

You an find other SSL configrations at Open Swoole Server Configuration.

You have to pass SWOOLE_SSL when defining a Open Swoole server to enable SSL:

$server = new Swoole\Server("", 9501, SWOOLE_PROCESS, SWOOLE_SOCK_TCP | SWOOLE_SSL);
Last updated on August 31, 2022