NGINX Unit

Yii§

To run apps based on the Yii framework using Unit:

  1. Install Unit with a PHP language module.

  2. Next, install Yii and create or deploy your app. Here, we use Yii’s basic project template and Composer:

    $ cd /path/to/
    $ composer create-project --prefer-dist yiisoft/yii2-app-basic yii
    

    This creates the app’s directory tree at /path/to/yii/. Its web/ subdirectory contains both the root index.php and the static files; if your app requires additional .php scripts, also store them here.

  3. Finally, prepare and upload the app configuration to Unit (note the use of uri, share, and fallback):

    {
        "listeners": {
            "*:80": {
                "pass": "routes/yii"
            }
        },
    
        "routes": {
            "yii": [
                {
                    "match": {
                        "uri": [
                            "!/assets/*",
                            "*.php",
                            "*.php/*"
                        ]
                    },
    
                    "action": {
                        "pass": "applications/yii_direct"
                    }
                },
                {
                    "action": {
                        "share": "/path/to/yii/web/",
                        "fallback": {
                            "pass": "applications/yii_index"
                        }
                    }
                }
            ]
        },
    
        "applications": {
            "yii_direct": {
                "type": "php",
                "root": "/path/to/yii/web/",
                "user": "www-data"
            },
    
            "yii_index": {
                "type": "php",
                "root": "/path/to/yii/web/",
                "user": "www-data",
                "script": "index.php"
            }
        }
    }
    

    For a detailed discussion, see Configuring Web Servers and Running Applications in Yii docs.

    Assuming the config above is saved as yii.json:

    # curl -X PUT --data-binary @yii.json --unix-socket \
           /path/to/control.unit.sock http://localhost/config
    
    Yii Basic Template App on Unit