NGINX Unit
v. 1.18.0

Drupal§

To run the Drupal content management system using Unit:

  1. Install Unit with a PHP language module.

  2. Install and configure Drupal’s prerequisites. Note the settings to be used later during setup.

  3. Install Drupal’s core files. For our purposes, the installation path is /path/to/app/.

  4. Set installation path permissions to secure access, for example:

    # chown -R unit_user:unit_group /path/to/app/
    

    Note the values to be used in Unit configuration.

  5. Next, put together the Drupal configuration for Unit. The default .htaccess scheme in a Drupal installation roughly translates into the following:

    {
        "listeners": {
            "*:80": {
                "pass": "routes/drupal"
            }
        },
    
        "routes": {
            "drupal": [
                {
                    "match": {
                        "uri": [
                            "!*/.well-known/*",
                            "/vendor/*",
                            "/core/profiles/demo_umami/modules/demo_umami_content/default_content/*",
                            "*.engine",
                            "*.inc",
                            "*.install",
                            "*.make",
                            "*.module",
                            "*.po",
                            "*.profile",
                            "*.sh",
                            "*.theme",
                            "*.tpl",
                            "*.twig",
                            "*.xtmpl",
                            "*.yml",
                            "*/.*",
                            "*/Entries*",
                            "*/Repository",
                            "*/Root",
                            "*/Tag",
                            "*/Template",
                            "*/composer.json",
                            "*/composer.lock",
                            "*/web.config",
                            "*sql",
                            "*.bak",
                            "*.orig",
                            "*.save",
                            "*.swo",
                            "*.swp",
                            "*~"
                        ]
                    },
    
                    "action": {
                        "return": 403
                    }
                },
                {
                    "match": {
                        "uri": [
                            "/core/authorize.php",
                            "/core/core.api.php",
                            "/core/globals.api.php",
                            "/core/install.php",
                            "/core/modules/statistics/statistics.php",
                            "/core/modules/system/tests/http.php*",
                            "/core/modules/system/tests/https.php*",
                            "/core/rebuild.php",
                            "/update.php"
                        ]
                    },
    
                    "action": {
                        "pass": "applications/drupal/direct"
                    }
                },
                {
                    "match": {
                        "uri": [
                            "!/index.php*",
                            "*.php",
                            "*.php/*"
                        ]
                    },
    
                    "action": {
                        "return": 403
                    }
                },
                {
                    "action": {
                        "share": "/path/to/app/web/",
                        "fallback": {
                            "pass": "applications/drupal/index"
                        }
                    }
                }
            ]
        },
    
        "applications": {
            "drupal": {
                "type": "php",
                "user": "unit_user",
                "group": "unit_group",
                "targets": {
                    "direct": {
                        "root": "/path/to/app/web/"
                    },
    
                    "index": {
                        "root": "/path/to/app/web/",
                        "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 index.php if the URI omits it.
    • The index target specifies the script that Unit runs for any URIs the target receives.
  6. Upload the updated configuration. Assuming the JSON above was added to config.json:

    # curl -X PUT --data-binary @config.json --unix-socket \
           /path/to/control.unit.sock http://localhost/config/
    

    Note

    The control socket path may vary; run unitd --help or see Startup for details.

  7. After a successful update, browse to http://localhost and set up your Drupal installation:

Drupal on Unit - Setup Screen