NGINX Unit
v. 1.19.0

Symfony§

To run apps based on the Symfony framework using Unit:

  1. Install Unit with a PHP language module.

  2. Next, install Symfony and create or deploy your app. Here, we use Symfony’s reference app:

    $ cd /path/to/
    $ symfony new --demo my_project
    

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

    Note

    The difference between the pass targets is their usage of the script setting:

    • The direct target runs the .php script from the URI or defaults to index.php if the URI omits it.
    • The index target specifies the script that Unit runs for any URIs the target receives.

    For a detailed discussion, see Configuring a Web Server in Symfony docs.

    Assuming the config above is saved as symfony.json:

    # curl -X PUT --data-binary @symfony.json --unix-socket \
           /path/to/control.unit.sock http://localhost/config
    
    Symfony Demo App on Unit - Admin Post Update