> For the complete documentation index, see [llms.txt](https://help.aikido.dev/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://help.aikido.dev/docs/docs-ja/zen-firewall/zen-installation-instructions/zen-firewall-for-php/frankenphp-worker.md).

# FrankenPHP worker

このガイドでは、アプリケーション向けに Aikido の Zen Firewall をインストールして設定する方法を順を追って説明します。アプリケーションを保護するために、以下の手順に従ってください。

問題や不具合が発生した場合は、サポートチャットまたは GitHub の issue でお気軽にご連絡ください

<https://github.com/AikidoSec/firewall-php>

## 要件

* FrankenPHP 8.2+（FrankenPHP 8.5 までテスト済み）。
* フレームワークなし / カスタムミドルウェア。
* [Aikidoアカウント](/docs/docs-ja/hajimeni/setting-up-your-account.md) & [Zen Firewallトークン](/docs/docs-ja/zen-firewall/zen-installation-instructions/creating-an-aikido-zen-firewall-token.md)

## インストールと設定

{% stepper %}
{% step %}
**AikidoによるZen Firewallをインストール**

FrankenPHP 用の Zen はシステムパッケージとしてインストールされます。

前提条件：

* 次の権限があることを確認してください `sudo` 権限。
* サポートされている FrankenPHP バージョン（8.2 以上）を使用してください。

Red Hat 系のシステム（RHEL、CentOS、Fedora）の場合：

```bash
rpm -Uvh --oldpackage https://github.com/AikidoSec/firewall-php/releases/latest/download/aikido-php-firewall.x86_64.rpm
```

Red Hat 系の arm64 / aarch64 の場合：

```bash
rpm -Uvh --oldpackage https://github.com/AikidoSec/firewall-php/releases/latest/download/aikido-php-firewall.aarch64.rpm
```

Debian 系のシステム（Debian、Ubuntu）の場合：

```bash
curl -L -O https://github.com/AikidoSec/firewall-php/releases/latest/download/aikido-php-firewall.x86_64.deb
dpkg -i -E ./aikido-php-firewall.x86_64.deb
```

Debian 系の arm64 / aarch64 の場合：

```bash
curl -L -O https://github.com/AikidoSec/firewall-php/releases/latest/download/aikido-php-firewall.aarch64.deb
dpkg -i -E ./aikido-php-firewall.aarch64.deb
```

{% endstep %}

{% step %}
**Zen Firewall をドライ / 検出のみモードで開始する**

トークンをあなたの `Caddyfile` Aikido Zen エージェントがそれを取得できるようにします。まだトークンがない場合は、従ってください [こちらの手順](/docs/docs-ja/zen-firewall/zen-installation-instructions/creating-an-aikido-zen-firewall-token.md).

{% @aikido-custom-code/code-highlight content="! Caddyfile
example.com {
root \* /var/www/html/public

```
php_server {
```

* ```
     env AIKIDO_TOKEN "AIK_RUNTIME_...."
  ```
* ```
     env AIKIDO_BLOCK "True"
    worker {
      // your worker parameters
    }
  ```

  }

  file\_server
  }" %}

アプリが期待どおりに動作し、いかなるリクエストもブロックしないことを確認するため、まずは dry モードでアプリを起動することを推奨します。誤検知を避けるため、Zen Firewall はステージング環境で 2 週間実行することをお勧めします。

```bash
env AIKIDO_BLOCK "False"
```

{% hint style="info" %}
環境変数を定義できます `AIKIDO_DEBUG=true` エージェントの動作について、より詳細な情報を得るためにデバッグモードを有効にするためのものです。環境変数の詳細については: [環境変数による設定](/docs/docs-ja/zen-firewall/zen-installation-instructions/configuration-via-environment-variables.md)
{% endhint %}

たとえば

```env
AIKIDO_TOKEN=AIK_RUNTIME_...
AIKIDO_BLOCK=false
```

変更後は FrankenPHP のプロセスマネージャー／Web サーバーを再起動してください。
{% endstep %}

{% step %}
**Octane ワーカースクリプトを更新**

Octane のワーカースクリプトで \aikido\worker\_rinit() と \aikido\worker\_rshutdown() を呼び出します

{% @aikido-custom-code/code-highlight language="php" content="\<?php

require **DIR** . '/../vendor/autoload.php';
$app = require\_once **DIR** . '/../bootstrap/app.php';

while (frankenphp\_handle\_request(function () use ($app) {

* \aikido\worker\_rinit();

```
// Your application logic
```

* \aikido\worker\_rshutdown();
  })) {
  // keep looping
  }" %}
  {% endstep %}

{% step %}
**レート制限とユーザーブロックを有効にする**

使用 `set_user` と `should_block_request` をリクエストパイプラインで:

{% @aikido-custom-code/code-highlight language="php" content="+if (extension\_loaded('aikido')) {

* \aikido\set\_user('123', 'John Doe');
*
* $decision = \aikido\should\_block\_request();
*
* if ($decision->block) {
* ```
    if ($decision->type === 'ratelimited') {
  ```
* ```
        http_response_code(429);
  ```
* ```
        header('Retry-After: ' . $decision->retry_after);
  ```
* ```
        exit('You are rate limited by Zen.');
  ```
* ```
    }
  ```
* ```
    http_response_code(403);
  ```
* ```
    exit('You are blocked by Zen.');
  ```
* }
  +}" %}
  {% endstep %}

{% step %}
**アプリをテスト**

アプリケーションを開いて、いくつかの操作を行うか、いくつかのページを開いてください。Zen がアプリケーション内のルートを自動的に検出します。

{% hint style="info" %}
Zen は10分ごとに Aikido にデータを送信します
{% endhint %}

Zen アプリケーションの次のページを見ることで、エージェントが正常に動作しているか確認できます:

* **イベント**: 「Application started」イベントが表示されるはずです。
* **ルート**: しばらくすると、アプリケーションのルートがここにメソッド、ルート、リクエストとともに表示され始めます。
* **インスタンス**: Zen がインストールされているアプリケーションのアクティブなインスタンス数が表示されるはずです。

<figure><img src="https://715870456-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FyKbzcQGrx7UtrG0nPZZ7%2Fuploads%2Fgit-blob-79af8470fd5feef0b378588fc5de01c3ea89d9ae%2FScreenshot%202025-06-23%20at%2010.08.35.png?alt=media" alt=""><figcaption></figcaption></figure>
{% endstep %}

{% step %}
**ダッシュボードでレート制限を設定**

Zen Firewall ミドルウェアを追加したら、Aikido ダッシュボードでレート制限を設定することで、ルートをブルートフォース攻撃から保護するテストができます。

1. 作成したアプリをクリックします。
2. へ移動 **ルート** タブを選択します。
3. 制限したいルートを見つけてクリック **レート制限の設定**.
4. 手順に従ってレート制限を設定します（例：1分あたり5リクエスト）。

![保護およびレート制限のオプション付きで認証ルートを表示する API ルート管理インターフェース。](https://715870456-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FyKbzcQGrx7UtrG0nPZZ7%2Fuploads%2Fgit-blob-4f588cb82dce7a932262f90046f280ee5115a13d%2FScreenshot%202025-10-30%20at%2010.38.17.png?alt=media)

![POST /auth/login に対して、1分あたり5リクエストのレート制限を設定します。](https://715870456-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FyKbzcQGrx7UtrG0nPZZ7%2Fuploads%2Fgit-blob-2633dcea71b485b0257ecf6b607323a9646dae06%2Fucarecdn-34b1af76-facb-4b6d-9c87-155236236b8f.png?alt=media)

**レート制限の確認**

アプリを起動し、レート制限を設定したルートに1分以内に5回アクセスしてみてください。5回目の試行後、レート制限エラーが表示されるはずです：

```
Aikido ファイアウォールによりレート制限されています。（あなたのIP: 1.2.3.4）
```

{% endstep %}

{% step %}
**次のステップ**

Zen Firewall のインストールに成功しました。おめでとうございます。問題が発生した場合、ご不明点や機能の要望がある場合は、遠慮なくサポートまでご連絡ください。

これで、Zen Firewall が提供する多彩な機能をぜひご確認ください：

* [Zen FirewallでBotトラフィックをブロックする](/docs/docs-ja/zen-firewall/zen-features/blocking-bot-traffic-with-zen-firewall.md)
* [Zen FirewallでTorトラフィックをブロックまたは監視する](/docs/docs-ja/zen-firewall/zen-features/blocking-tor-traffic-with-zen-firewall.md)
* [Zen Firewallでユーザーを追跡する](/docs/docs-ja/zen-firewall/zen-features/blocking-users-with-zen-firewall.md)
* [Zen Firewallで既知の脅威アクターをブロックする](/docs/docs-ja/zen-firewall/zen-features/blocking-known-threat-actors-with-zen-firewall.md)
* [Zen Firewall で国別にトラフィックをブロックする](/docs/docs-ja/zen-firewall/zen-features/blocking-traffic-by-country-with-zen-firewall.md)
* [ルートのレート制限を設定する](/docs/docs-ja/zen-firewall/zen-features/setting-up-rate-limiting-for-routes.md)
* [アウトバウンドドメインを監視する](/docs/docs-ja/zen-firewall/zen-features/monitor-outbound-domains.md)

追加情報：

* [Zen のパフォーマンスと信頼性](/docs/docs-ja/zen-firewall/miscellaneous/how-zen-works-performance-reliability.md)
* [Zen Firewall のブロックモードと検知モード](/docs/docs-ja/zen-firewall/zen-features/blocking-vs-detection-mode-in-zen-firewall.md)
* [Zen の統計を理解する](/docs/docs-ja/zen-firewall/zen-features/understanding-your-zen-statistics.md)
  {% endstep %}
  {% endstepper %}


---

# Agent Instructions
This documentation is published with GitBook. GitBook is the documentation platform designed so that both humans and AI agents can read, navigate, and reason over technical content effectively. Learn more at gitbook.com.

## Querying This Documentation
If you need additional information that is not directly available in this page, you can query the documentation by asking a question.

Perform an HTTP GET request on the following URL with the `ask` and `goal` query parameters:

```
GET https://help.aikido.dev/docs/docs-ja/zen-firewall/zen-installation-instructions/zen-firewall-for-php/frankenphp-worker.md?ask=<question>&goal=<user_goal>
```

`ask` is the immediate question: it should be specific, self-contained, and written in natural language.
`goal` is what the user is ultimately trying to achieve, the reason they need the answer. Sharing it helps GitBook give you a better, more relevant answer. A goal is most helpful when it describes the outcome the user wants rather than restating the question. For example, with `ask=how do I create an API token`, a goal like `automate deployments from our CI pipeline` lets GitBook tailor the answer to that use case.

The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
