NGINX Unit

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_direct": {
                "type": "php",
                "root": ":/path/to/my_project/public/",
                "user": "www-data"
            },
    
            "symfony_index": {
                "type": "php",
                "root": "/path/to/my_project/public/",
                "user": "www-data",
                "script": "index.php"
            }
        }
    }
    

    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