NGINX Unit
v. 1.19.0

WordPress§

To install WordPress if you haven’t already done so:

  1. Check prerequisites and configure the WordPress database.

  2. Download and extract WordPress files:

    $ cd /path/to/
    $ curl -O https://wordpress.org/latest.tar.gz
    $ tar xzf latest.tar.gz
    

    In this example, the files will be stored in /path/to/wordpress/.

  3. Update the wp-config.php file with your database settings and other customizations.

  4. Set up proper file permissions for WordPress:

    # chown -R wp_user:wp_user /path/to/wordpress/
    # find /path/to/wordpress/ -type d -exec chmod g+s {} \;
    # chmod g+w /path/to/wordpress/wp-content
    # chmod -R g+w /path/to/wordpress/wp-content/themes
    # chmod -R g+w /path/to/wordpress/wp-content/plugins
    

Unit Setup§

To run WordPress in Unit:

  1. Install Unit with a PHP language module.

  2. Prepare Unit configuration for your update. To obtain an initial template, query the control API:

    # curl --unix-socket /path/to/control.unit.sock \
           http://localhost/config/ > config.json
    

    Note

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

  3. Edit the file, adding a listener, two apps, and a route. First, the route serves the wp-admin section of the WordPress site and other URIs that explicitly name the .php file; next, it filters out static assets, relaying them to a share, and passes other requests to WordPress’s /index.php via the wp_index app:

    {
        "listeners": {
            "*:8080": {
                "pass": "routes/wordpress"
            }
    
        },
    
        "routes": {
            "wordpress": [
                {
                    "match": {
                        "uri": [
                            "*.php",
                            "*.php/*",
                            "/wp-admin/"
                        ]
                    },
    
                    "action": {
                        "pass": "applications/wordpress/direct"
                    }
                },
                {
                    "action": {
                        "share": "/path/to/wordpress/",
                        "fallback": {
                            "pass": "applications/wordpress/index"
                        }
                    }
                }
            ]
        },
    
        "applications": {
            "wordpress": {
                "type": "php",
                "user": "wp_user",
                "group": "wp_user",
                "targets": {
                    "direct": {
                        "root": "/path/to/wordpress/"
                    },
    
                    "index": {
                        "root": "/path/to/wordpress/",
                        "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.
  4. Upload the updated configuration:

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

Finally, browse to your WordPress site and complete the installation.

Note

The resulting URI scheme will affect your WordPress configuration; updates may require extra steps.