NGINX Unit

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.

  3. Install Drupal’s core files. Here, we install it at /path/to/app/; use a real path in your configuration.

  4. Run the following command so Unit can access the application directory:

    # chown -R unit:unit /path/to/app/
    

    Note

    The unit:unit user-group pair is available only with official packages, Docker images, and some third-party repos. Otherwise, account names may differ; run the ps aux | grep unitd command to be sure.

    For further details, including permissions, see the security checklist.

  5. Next, prepare the Drupal configuration for Unit. The default .htaccess scheme in a Drupal installation roughly translates into the following (use real values for share and root):

    {
        "listeners": {
            "*:80": {
                "pass": "routes"
            }
        },
    
        "routes": [
            {
                "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": 404
                }
            },
            {
                "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/https?\\.php",
                        "/core/rebuild.php",
                        "/update.php",
                        "/update.php/*"
                    ]
                },
    
                "action": {
                    "pass": "applications/drupal/direct"
                }
            },
            {
                "match": {
                    "uri": [
                        "!/index.php*",
                        "*.php"
                    ]
                },
    
                "action": {
                    "return": 404
                }
            },
            {
                "action": {
                    "share": "/path/to/app/web$uri",
                    "fallback": {
                        "pass": "applications/drupal/index"
                    }
                }
            }
        ],
    
        "applications": {
            "drupal": {
                "type": "php",
                "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 -h or see Startup and Shutdown for details.

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

Drupal on Unit - Setup Screen