§2024-07-06

This is my ubuntu snap installation of nextcloud

$ cat /snap/nextcloud/current/meta/snap.yaml
name: nextcloud
version: 29.0.2snap1
summary: Nextcloud Server - A safe home for all your data
description: |
  Access, share and protect your files, calendars, contacts, communication and
  more at home and in your enterprise.
apps:
  apache:
    command: bin/run-httpd -k start -DFOREGROUND
    stop-command: bin/httpd-wrapper -k stop
    reload-command: bin/httpd-wrapper -k graceful
    daemon: simple
    restart-condition: always
    plugs:
    - network
    - network-bind
    - removable-media
    command-chain:
    - snap/command-chain/snapcraft-runner
  disable-https:
    command: bin/disable-https
    plugs:
    - network
    - network-bind
    command-chain:
    - snap/command-chain/snapcraft-runner
  enable-https:
    command: bin/enable-https
    plugs:
    - network
    - network-bind
    command-chain:
    - snap/command-chain/snapcraft-runner
  export:
    command: bin/export-data
    plugs:
    - network
    - network-bind
    - removable-media
    command-chain:
    - snap/command-chain/snapcraft-runner
  import:
    command: bin/import-data
    plugs:
    - network
    - network-bind
    - removable-media
    command-chain:
    - snap/command-chain/snapcraft-runner
  logrotate:
    command: bin/run-logrotate
    daemon: simple
    restart-condition: on-failure
    timer: 00:00
    command-chain:
    - snap/command-chain/snapcraft-runner
  manual-install:
    command: bin/manual-install
    plugs:
    - network
    - network-bind
    - removable-media
    command-chain:
    - snap/command-chain/snapcraft-runner
  mysql:
    command: bin/start_mysql
    stop-command: support-files/mysql.server stop
    reload-command: bin/reload-mysql
    daemon: simple
    restart-condition: always
    plugs:
    - network
    - network-bind
    command-chain:
    - snap/command-chain/snapcraft-runner
  mysql-client:
    command: bin/run-mysql
    plugs:
    - network
    - network-bind
    command-chain:
    - snap/command-chain/snapcraft-runner
  mysqldump:
    command: bin/run-mysqldump
    plugs:
    - network
    - network-bind
    command-chain:
    - snap/command-chain/snapcraft-runner
  nextcloud-cron:
    command: bin/nextcloud-cron
    daemon: simple
    restart-condition: on-failure
    plugs:
    - network
    - network-bind
    - removable-media
    command-chain:
    - snap/command-chain/snapcraft-runner
  nextcloud-fixer:
    command: bin/nextcloud-fixer
    daemon: simple
    restart-condition: on-failure
    plugs:
    - network
    - network-bind
    - removable-media
    command-chain:
    - snap/command-chain/snapcraft-runner
  occ:
    command: bin/occ
    plugs:
    - network
    - network-bind
    - removable-media
    command-chain:
    - snap/command-chain/snapcraft-runner
  php-fpm:
    command: bin/start-php-fpm
    reload-command: bin/reload-php
    daemon: simple
    restart-condition: always
    plugs:
    - network
    - network-bind
    - network-observe
    - removable-media
    command-chain:
    - snap/command-chain/snapcraft-runner
  redis-server:
    command: bin/start-redis-server
    daemon: simple
    restart-condition: always
    plugs:
    - network
    - network-bind
    command-chain:
    - snap/command-chain/snapcraft-runner
  renew-certs:
    command: bin/renew-certs
    daemon: simple
    restart-condition: always
    plugs:
    - network
    - network-bind
    command-chain:
    - snap/command-chain/snapcraft-runner
architectures:
- arm64
assumes:
- command-chain
base: core18
confinement: strict
grade: stable
hooks:
  configure:
    plugs:
    - network
    - network-bind
    - removable-media
  pre-refresh:
    plugs:
    - network
    - network-bind
    - removable-media

The 413 (Payload Too Large) error typically occurs when the client uploads a file that exceeds the server's file size limit. For your Nextcloud snap installation, you need to adjust the file upload size limit in several places.

Here’s how to fix the 413 error in your Nextcloud snap setup:

  1. Modify PHP Settings:
# pwd
/var/snap/nextcloud/current
# ls
certs  logrotate  logs  mysql  nextcloud  redis
# mkdir -p php/config && cd $_
# nano php.ini
# cat php.ini 
upload_max_filesize = 16G
post_max_size = 16G
  1. Modify Nextcloud Config:

Edit the Nextcloud configuration file to ensure it accepts larger file sizes.

# nano /var/snap/nextcloud/current/nextcloud/config/config.php
Add the following lines within the array to match your desired file size:

'upload_max_filesize' => '16G', 'max_upload_size' => 1610241024*1024,


3. Adjust Apache Settings:

Since your Nextcloud snap uses Apache, you need to adjust its configuration as well.

pwd

/var/snap/nextcloud/current

mkdir -p apache/config/conf.d/ && cd $_

nano nextcloud.conf

cat nextcloud.conf

php_value upload_max_filesize 16G php_value post_max_size 16G ```

and,

# nano /var/snap/nextcloud/current/apache/config/conf.d/custom.conf
Add the following lines to this file:

<Directory "/var/snap/nextcloud/current/nextcloud/">
    LimitRequestBody 17179869184
</Directory>
  1. Restart Services:

After making the above changes, restart the relevant services to apply the new settings.

# snap restart nextcloud.apache
Restarted.
# snap restart nextcloud.php-fpm
Restarted.
  1. Verify Changes:

To ensure the changes have taken effect, you can create a phpinfo() file to verify the settings.

# echo '<?php phpinfo(); ?>' | sudo tee /var/snap/nextcloud/current/nextcloud/extra-apps/phpinfo.php

Then,

Look for upload_max_filesize and post_max_size values to confirm they are set correctly.

  1. Clean Up:

Delete the phpinfo.php file after verification to avoid exposing sensitive information.

# rm /var/snap/nextcloud/current/nextcloud/phpinfo.php

By following these steps, you should be able to resolve the 413 (Payload Too Large) error in your Nextcloud snap installation. If you encounter any issues, ensure that the configuration files are correctly edited and saved, and that the services are properly restarted.