NGINX Unit

NextCloud§

Note

This howto uses NextCloud 16, PHP 7.3, MariaDB, and apt; adjust it to your scenario as needed.

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

  1. Download and extract NextCloud files:

    $ cd /path/to/
    $ curl -O https://download.nextcloud.com/server/releases/nextcloud-16.0.4.tar.bz2
    $ tar xf nextcloud-16.0.4.tar.bz2
    

    This creates the /path/to/nextcloud directory.

  2. Change the directory ownership, supplying a username that will be used to configure and run Nextcloud:

    # chown -R nc_user:nc_user /path/to/nextcloud/
    
  3. Install and check NextCloud’s prerequisites:

    # apt install mariadb-server
    # apt install php7.3 php7.3-imagick php7.3-curl php7.3-gd php7.3-intl \
          php7.3-mbstring php7.3-mysql php7.3-xml php7.3-zip
    $ mysql --version
    $ php --version
    
  4. Set up the NextCloud database (note the sample credentials):

    # mysql -u root -p
    
        > CREATE DATABASE nextcloud;
        > CREATE USER 'nextuser'@'localhost' IDENTIFIED BY 'nextpass';
        > GRANT ALL PRIVILEGES ON nextcloud.* TO 'nextuser'@'localhost';
        > FLUSH PRIVILEGES;
    
  5. Finish the installation (here, the occ utility is used; note the credentials and the sudo -u username):

    $ cd /path/to/nextcloud/
    $ sudo -u nc_user php occ maintenance:install --database "mysql" \
           --database-name "nextcloud" --database-user "nextuser"     \
           --database-pass "nextpass" --admin-user "admin" --admin-pass "adminpass"
    
          Nextcloud was successfully installed
    

    Note

    Verify the resulting settings in /path/to/nextcloud/config/config.php; in particular, check the trusted domains to ensure your installation will be accessible from within your network:

    'trusted_domains' =>
    array (
      0 => 'localhost',
      1 => '*.example.com',
    ),
    

Unit§

To run NextCloud 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 route, a few apps and a listener to make NextCloud available (based on NextCloud’s own guide):

    {
        "listeners": {
            "*:80": {
                "pass": "routes/nextcloud"
            }
        },
    
        "routes": {
            "nextcloud": [
                {
                    "match": {
                        "uri": [
                            "/build/*",
                            "/tests/*",
                            "/config/*",
                            "/lib/*",
                            "/3rdparty/*",
                            "/templates/*",
                            "/data/*",
                            "/.*",
                            "/autotest*",
                            "/occ*",
                            "/issue*",
                            "/indie*",
                            "/db_*",
                            "/console*"
                        ]
                    },
    
                    "action": {
                        "share": "/dev/null/"
                    }
                },
                {
                    "match": {
                        "uri": [
                            "/core/ajax/update.php*",
                            "/cron.php*",
                            "/index.php*",
                            "/ocs/v1.php*",
                            "/ocs/v2.php*",
                            "/public.php*",
                            "/remote.php*",
                            "/status.php*"
                        ]
                    },
    
                    "action": {
                        "pass": "applications/nextcloud_direct"
                    }
                },
                {
                    "match": {
                        "uri": [
                            "/ocm-provider*",
                            "/ocs-provider*",
                            "/updater*"
                        ]
                    },
    
                    "action": {
                        "pass": "routes/nextcloud_fallthrough"
                    }
                },
                {
                    "action": {
                        "share": "/path/to/nextcloud/",
                        "fallback": {
                            "pass": "applications/nextcloud_index"
                        }
                    }
                }
            ],
    
            "nextcloud_fallthrough": [
                {
                    "match": {
                        "uri": "*.php*"
                    },
    
                    "action": {
                        "pass": "applications/nextcloud_direct"
                    }
                },
                {
                    "match": {
                        "uri": "/ocm-provider*"
                    },
    
                    "action": {
                        "pass": "applications/nextcloud_ocm"
                    }
                },
                {
                    "match": {
                        "uri": "/ocs-provider*"
                    },
    
                    "action": {
                        "pass": "applications/nextcloud_ocs"
                    }
                },
                {
                    "action": {
                        "pass": "applications/nextcloud_updater"
                    }
                }
            ]
        },
    
        "applications": {
            "nextcloud_direct": {
                "type": "php",
                "user": "nc_user",
                "group": "nc_user",
                "root": "/path/to/nextcloud/"
            },
    
            "nextcloud_index": {
                "type": "php",
                "user": "nc_user",
                "group": "nc_user",
                "root": "/path/to/nextcloud/",
                "script": "index.php"
            },
    
            "nextcloud_ocm": {
                "type": "php",
                "user": "nc_user",
                "group": "nc_user",
                "root": "/path/to/nextcloud/ocm-provider/",
                "script": "index.php"
            },
    
            "nextcloud_ocs": {
                "type": "php",
                "user": "nc_user",
                "group": "nc_user",
                "root": "/path/to/nextcloud/ocs-provider/",
                "script": "index.php"
            },
    
            "nextcloud_updater": {
                "type": "php",
                "user": "nc_user",
                "group": "nc_user",
                "root": "/path/to/nextcloud/updater/",
                "script": "index.php"
            }
        }
    }
    
  4. Upload the updated configuration:

    # curl -X PUT --data-binary @config.json --unix-socket \
           /path/to/control.unit.sock http://localhost/config
    
  5. Adjust Unit’s max_body_size option to avoid potential issues with large file uploads, for example:

    # curl -X PUT -d '{"http":{"max_body_size": 2147483648}}' --unix-socket \
           /path/to/control.unit.sock http://localhost/config/settings
    

Finally, browse to your NextCloud site and complete the installation:

NextCloud in Unit - Home Screen