Yii 2

In this guide, I will provide you with some ideas on how to implement Shieldon Firewall in your Yii application.

Firewall in Yii Framework


Use PHP Composer:

composer require shieldon/shieldon

This will also install dependencies required for Shieldon:


Yii 2

1. Before initializing Kernel

In your public/index.php, before this line:

require __DIR__ . '/../vendor/yiisoft/yii2/Yii.php';

Add the following code:


| Run The Shieldon Firewall
| Shieldon Firewall will watch all HTTP requests coming to your website.
| Running Shieldon Firewall before initializing Yii will avoid possible
| conflicts with Yii's built-in functions.

if (isset($_SERVER['REQUEST_URI'])) {
    $storage = __DIR__ . '/../runtime/shieldon';

    $firewall = new \Shieldon\Firewall\Firewall();

    // The base url for the control panel.

    $response = $firewall->run();

    if ($response->getStatusCode() !== 200) {
        $httpResolver = new \Shieldon\Firewall\HttpResolver();

2. Define a Route for Firewall Panel

Create a controller named FirewallPanelController.



namespace app\controllers;

use yii\web\Controller;

class FirewallController extends Controller
    public function beforeAction($action)
        $this->enableCsrfValidation = false;

        return parent::beforeAction($action);

     * The entry point of the Firewall Panel.
     * @return string
    public function actionPanel()
        $panel = new \Shieldon\Firewall\Panel();

Make sure that enablePrettyUrl is set to true in your config/web.php file.


'urlManager' => [
    'enablePrettyUrl' => true,
    'showScriptName' => false,
    'rules' => [
        'firewall/panel/' => 'firewall/panel',
        'firewall/panel/<slug:.*>' => 'firewall/panel',

That's it.

You can access the Firewall Panel by visiting /firewall-panel in your browser.

Controll Panel


The default login is shieldon_user, and the password is shieldon_pass. After logging into the Firewall Panel, the first thing you should do is change the login and password.

If Shieldon Firewall is enabled in the Daemon setting section, it will start monitoring your website. Make sure you have correctly set up the settings.