NGINX Unit

Plone§

To run the Plone content management system using Unit:

  1. Install Unit with a Python 3.6+ language module.

  2. Install and configure Plone’s prerequisites.

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

    $ mkdir /tmp/plone && cd /tmp/plone/
    $ wget https://launchpad.net/plone/A.B/A.B.C/+download/Plone-A.B.C-UnifiedInstaller-1.0.tgz
    $ tar xzvf Plone-A.B.C-UnifiedInstaller-1.0.tgz  \
          --strip-components=1
    $ ./install.sh --target=/path/to/app/  \
                   --with-python=/full/path/to/python  \
                   standalone
    

    Note

    Plone’s Zope instance and virtual environment are created in the zinstance/ subdirectory; later, the resulting path is used to configure Unit, so take care to note it in your setup. Also, make sure the Python version specified with --with-python matches the module version from Step 1.

  4. To run Plone on Unit, add a new configuration file named /path/to/app/zinstance/wsgi.cfg:

    [buildout]
    extends =
        buildout.cfg
    
    parts +=
        wsgi.py
    
    [wsgi.py]
    recipe = plone.recipe.zope2instance
    user = admin:admin
    eggs =
        ${instance:eggs}
    scripts =
    initialization =
        from Zope2.Startup.run import make_wsgi_app
        wsgiapp = make_wsgi_app({}, '${buildout:parts-directory}/instance/etc/zope.conf')
        def application(*args, **kwargs):return wsgiapp(*args, **kwargs)
    

    It creates a new Zope instance. The part’s name must end with .py for the resulting instance script to be recognized as a Python module; the initialization option defines a WSGI entry point using zope.conf from the instance part in buildout.cfg.

    Rerun Buildout, feeding it the new configuration file:

    $ cd /path/to/app/zinstance/
    $ bin/buildout -c wsgi.cfg
    
          ...
          Installing wsgi.py.
          Generated script '/path/to/app/zinstance/bin/wsgi.py'.
    

    Thus created, the instance script can be used with Unit.

  5. 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.

  6. Next, prepare the Plone configuration for Unit (use real values for path and home):

    {
        "listeners": {
            "*:80": {
                "pass": "applications/plone"
            }
        },
    
        "applications": {
            "plone": {
                "type": "python 3.Y",
                "path": "/path/to/app/zinstance/",
                "home": "/path/to/app/zinstance/",
                "module": "bin.wsgi"
            }
        }
    }
    
  7. 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, your Plone instance should be available on the listener’s IP address and port:

    Plone on Unit - Setup Screen