NGINX Unit

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 wpuser:www-data /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/wp_direct"
                    }
                },
                {
                    "match": {
                        "uri": [
                             "/wp-admin/*",
                             "/wp-content/*",
                             "/wp-includes/*"
                        ]
                    },
    
                    "action": {
                        "share": "/www/wordpress/"
                    }
                },
                {
                    "action": {
                        "pass": "applications/wp_index"
                    }
                }
            ]
        },
    
        "applications": {
            "wp_direct": {
                "type": "php",
                "user": "wpuser",
                "group": "www-data",
                "root": "/path/to/wordpress/"
            },
    
            "wp_index": {
                "type": "php",
                "user": "wpuser",
                "group": "www-data",
                "root": "/path/to/wordpress/",
                "script": "index.php"
            }
        }
    }
    

    Note

    The difference between the apps is their usage of script setting. Here, wp_index specifies the script that Unit will run for any URIs the app receives. In contrast, the wp_direct app will serve URIs that reference a specific .php file by running it; if there’s no file specified, it defaults to index.php.

  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

Resulting URI scheme will trickle into your WordPress configuration; updates may require extra steps.