Installation

More difficult and requires a number of configuration in Nextcloud + a running MySQL server as backend, which isn't really ideal.

Prerequisites

Requirements

  • Ubuntu Server 20.04 LTS
  • Nginx webserver + PHP fpm

Install the required PHP modules:

$ sudo apt install php7.4-gd php7.4-mysql php7.4-curl php7.4-mbstring php7.4-intl
$ sudo apt install php7.4-gmp php7.4-bcmath php-imagick php7.4-xml php7.4-zip

Install the required MySQL/MariaDB database server, start the service, login (typically no password as root)

$ sudo apt install mariadb-server
$ sudo /etc/init.d/mysql start
$ sudo mysql -uroot -p

From within the MySQL interface, create a new user if needed, create the 'nextcloud' database with 'utf8mb4' character set and grant privileges:

> CREATE USER '[USERNAME]'@'localhost' IDENTIFIED BY '[PASSWORD]';
> CREATE DATABASE IF NOT EXISTS nextcloud CHARACTER SET utf8mb4 COLLATE utf8mb4_general_ci;
> GRANT ALL PRIVILEGES ON nextcloud.* TO '[USERNAME]'@'localhost';
> FLUSH PRIVILEGES;
> quit;

Pull the Nextcloud server release from the changelog page and verify the file integrity (e.g. SHA256). As per convention, store this under the webroot as a virtual host, and set the appropriate permissions (typically www-root user for nginx).

$ cp /var/www  # web root
$ wget https://download.nextcloud.com/server/releases/nextcloud-X.Y.Z.zip  # example
$ sha256sum nextcloud-X.Y.Z.zip
$ unzip nextcloud-21.0.2.zip  # creates a new nextcloud/ directory
$ rm nextcloud-21.0.2.zip
$ chown -R www-data:www-data nextcloud

The usual nginx configuration (create new rules in sites-available/nextcloud and link to sites-enabled/nextcloud). Can refer to the version referenced in the Nextcloud nginx configuration guide as well.

nextcloud
server {
    server_name cloud.pyuxiang.com;
    root /var/www/nextcloud;
    index index.php index.html /index.php$request_uri;
    listen 80;
 
    # If using own SSL certificate, otherwise let Certbot handle this
    #listen 443 ssl;
    #ssl_certificate /etc/letsencrypt/live/cloud.pyuxiang.com/fullchain.pem;
    #ssl_certificate_key /etc/letsencrypt/live/cloud.pyuxiang.com/privkey.pem;
    #include /etc/letsencrypt/options-ssl-nginx.conf;
    #ssl_dhparam /etc/letsencrypt/ssl-dhparams.pem;
 
    # Max upload size
    client_max_body_size 1G;
    fastcgi_buffers 64 4K;
 
    # For security/privacy
    add_header Referrer-Policy                      "no-referrer"   always;
    add_header X-Content-Type-Options               "nosniff"       always;
    add_header X-Download-Options                   "noopen"        always;
    add_header X-Frame-Options                      "SAMEORIGIN"    always;
    add_header X-Permitted-Cross-Domain-Policies    "none"          always;
    add_header X-Robots-Tag                         "none"          always;
    add_header X-XSS-Protection                     "1; mode=block" always;
    fastcgi_hide_header X-Powered-By;
 
    # Allow client access to `/.well-known`
    # Copied from default nginx configuration for Nextcloud
    location ^~ /.well-known {
        location = /.well-known/carddav { return 301 /remote.php/dav/; }
        location = /.well-known/caldav  { return 301 /remote.php/dav/; }
        location /.well-known/acme-challenge    { try_files $uri $uri/ =404; }
        location /.well-known/pki-validation    { try_files $uri $uri/ =404; }
        # Pass to frontend for handling of `/.well-known` URIs to Nextcloud API
        return 301 /index.php$request_uri;
    }
    location ~ ^/(?:build|tests|config|lib|3rdparty|templates|data)(?:$|/)  { return 404; }
    location ~ ^/(?:\.|autotest|occ|issue|indie|db_|console)                { return 404; }
 
    # This will be your own PHP scripts/server
    location ~\.php(?:$|/) {
        include snippets/fastcgi-php.conf;
        fastcgi_pass unix:/var/run/php/php[VER]-fpm.sock;
    }
 
    location ~ \.(?:css|js|svg|gif)$ {
        try_files $uri /index.php$request_uri;
        expires 6M;
        access_log off;
    }
    location ~ \.woff2?$ {
        try_files $uri /index.php$request_uri;
        expires 7d;
        access_log off;
    }
    location /remote {
        return 301 /remote.php$request_uri;
    }
    location / {
        try_files $uri $uri/ /index.php$request_uri;
    }
}

Once ready, access the Nextcloud installation wizard page, say https://cloud.nextcloud.com/, and create an admin account + supply login credentials as well as database name ("nextcloud") and access ("localhost:3306") for the MySQL database.

Warning

Unchecking the "Install recommended apps" tickbox immediately redirects to https://index.php/ instead of https://cloud.pyuxiang.com/index.php, in Nextcloud 21.0.2. Not sure if it is a breaking error, but consider yourself forewarned.

Weirdly a lot of configuration...