NGINX Unit

CakePHP§

To run apps based on the CakePHP framework using Unit:

  1. Install Unit with a PHP 7.2+ language module.

  2. Install CakePHP and create or deploy your app. Here, we use CakePHP’s basic template and Composer:

    $ cd /path/to/
    $ composer create-project --prefer-dist cakephp/app:4.* cakephp
    

    This creates the app’s directory tree at /path/to/cakephp/. Its webroot/ 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/cakephp"
            }
        },
    
        "routes": {
            "cakephp": [
                {
                    "match": {
                        "uri": [
                            "*.php",
                            "*.php/*"
                        ]
                    },
    
                    "action": {
                        "pass": "applications/cakephp_direct"
                    }
                },
                {
                    "action": {
                        "share": "/path/to/cakephp/webroot/",
                        "fallback": {
                            "pass": "applications/cakephp_index"
                        }
                    }
                }
            ]
        },
    
        "applications": {
            "cakephp_direct": {
                "type": "php",
                "root": "/path/to/cakephp/webroot/",
                "user": "www-data"
            },
    
            "cakephp_index": {
                "type": "php",
                "root": "/path/to/cakephp/webroot/",
                "user": "www-data",
                "script": "index.php"
            }
        }
    }
    

    For a detailed discussion, see Fire It Up in CakePHP docs.

    Assuming the config above is saved as cakephp.json:

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