PHPackages                             mattvb91/caddy-php - PHPackages - PHPackages  [Skip to content](#main-content)[PHPackages](/)[Directory](/)[Categories](/categories)[Trending](/trending)[Leaderboard](/leaderboard)[Changelog](/changelog)[Analyze](/analyze)[Collections](/collections)[Log in](/login)[Sign up](/register)

1. [Directory](/)
2. /
3. [Utility &amp; Helpers](/categories/utility)
4. /
5. mattvb91/caddy-php

ActivePackage[Utility &amp; Helpers](/categories/utility)

mattvb91/caddy-php
==================

Control your Caddy instance through PHP

v0.0.16-alpha(1y ago)318.3k6[1 issues](https://github.com/mattvb91/caddy-php/issues)MITPHPPHP ^8.1

Since Jul 23Pushed 1y ago4 watchersCompare

[ Source](https://github.com/mattvb91/caddy-php)[ Packagist](https://packagist.org/packages/mattvb91/caddy-php)[ RSS](/packages/mattvb91-caddy-php/feed)WikiDiscussions develop Synced 1mo ago

READMEChangelog (10)Dependencies (8)Versions (17)Used By (0)

[![](https://user-images.githubusercontent.com/11991564/180657106-aec2eb78-def3-4bad-aa4e-44f1e6ef1628.png)](https://user-images.githubusercontent.com/11991564/180657106-aec2eb78-def3-4bad-aa4e-44f1e6ef1628.png)

[![.github/workflows/ci_cd.yml](https://github.com/mattvb91/caddy-php/actions/workflows/ci_cd.yml/badge.svg)](https://github.com/mattvb91/caddy-php/actions/workflows/ci_cd.yml)[![codecov](https://camo.githubusercontent.com/9de5b9d9dff47d19a19b15028f6d5b5790dd245a0845226f0e3b851f26b115b2/68747470733a2f2f636f6465636f762e696f2f67682f6d617474766239312f63616464792d7068702f6272616e63682f646576656c6f702f67726170682f62616467652e7376673f746f6b656e3d5259464758324157364a)](https://codecov.io/gh/mattvb91/caddy-php)[![Total Downloads](https://camo.githubusercontent.com/2f2d955d106c6da6687464abb2c9d44196de802ffb48b180b42eb924725a8bb7/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f64742f6d617474766239312f63616464792d706870)](https://packagist.org/packages/mattvb91/caddy-php)[![Latest Stable Version](https://camo.githubusercontent.com/0cb5fc0860e158c8aa6224bfbdbb50c84820c0c9bc8126b4dc214122a640e75b/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f762f6d617474766239312f63616464792d706870)](https://packagist.org/packages/mattvb91/caddy-php)[![License](https://camo.githubusercontent.com/c475f69f1c7262bbd9f7fc795715ef1b0022c465a1545693c761d714831b8cf0/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f6c2f6d617474766239312f63616464792d706870)](https://packagist.org/packages/mattvb91/caddy-php)

### Control your Caddy instance through PHP

[](#control-your-caddy-instance-through-php)

This is more of a proof of concept rather than a fully working project. This tries to replicate the [caddy JSON API](https://caddyserver.com/docs/json/)structure to work through chainable PHP classes.

At the moment there is only a tiny subset of commands available from Caddy 2.0 that covered my currently needed use case.

### Install

[](#install)

```
composer require mattvb91/caddy-php
```

### Basic Usage

[](#basic-usage)

A basic example of a http server with a static response:

```
$caddy = new Caddy();

$caddy->addApp(
    (new Http())->addServer(
        'server1', (new Http\Server())->addRoute(
        (new Route())->addHandle(
            new StaticResponse('Hello world', 200)
        )
    ))
);

$caddy->load();
```

This will result in the following Caddy config:

```
{
  "admin": {
    "disabled": false,
    "listen": ":2019"
  },
  "apps": {
    "http": {
      "servers": {
        "server1": {
          "listen": [
            ":80"
          ],
          "routes": [
            {
              "handle": [
                {
                  "handler": "static_response",
                  "body": "Hello world",
                  "status_code": 200
                }
              ]
            }
          ]
        }
      }
    }
  }
}
```

```
curl -v localhost

-----
