How to set the PHP memory limit for Nextcloud

Nextcloud depends on PHP's memory_limit setting for web requests, background jobs, previews, upgrades, and occ maintenance tasks. Raising the limit is common when the administration overview warns about low PHP memory or when larger operations stop before the server itself is short on RAM.

The setting belongs to the active PHP runtime, not /var/www/nextcloud/config/config.php. PHP-FPM or the Apache PHP module handles browser traffic, while the CLI runtime handles occ and cron jobs; both layers need the intended value when the same instance uses web and command-line paths.

Nextcloud's current administration documentation says memory_limit should be at least 512 MB. Set a concrete value such as 1024M instead of relying on an unlimited or distro-default value that may differ between PHP runtimes, and replace 8.3 in /etc/php/8.3/…/conf.d paths with the active PHP version on the server.

Steps to set Nextcloud PHP memory limit:

  1. Check the active CLI PHP configuration path.
    $ php --ini
    Configuration File (php.ini) Path: "/etc/php/8.3/cli"
    Loaded Configuration File:         "/etc/php/8.3/cli/php.ini"
    Scan for additional .ini files in: "/etc/php/8.3/cli/conf.d"
    Additional .ini files parsed:      /etc/php/8.3/cli/conf.d/10-opcache.ini,
    ##### snipped #####

    The CLI path controls occ and cron jobs. The web runtime is checked separately through a temporary web probe later.

  2. Check the current CLI memory limit.
    $ php -r 'echo ini_get("memory_limit"), PHP_EOL;'
    512M
  3. Create a PHP-FPM drop-in for the Nextcloud web runtime.
    $ sudoedit /etc/php/8.3/fpm/conf.d/90-nextcloud-memory-limit.ini
    memory_limit = 1024M

    This path matches PHP-FPM packages on Debian and Ubuntu. Apache module installs use the matching /etc/php/8.3/apache2/conf.d tree instead of /fpm.

  4. Create a matching CLI drop-in for occ and cron jobs.
    $ sudoedit /etc/php/8.3/cli/conf.d/90-nextcloud-memory-limit.ini
    memory_limit = 1024M
  5. Test the PHP-FPM configuration.
    $ sudo php-fpm8.3 -t
    [29-Jun-2026 07:13:54] NOTICE: configuration file /etc/php/8.3/fpm/php-fpm.conf test is successful
  6. Reload the PHP-FPM service that serves Nextcloud.
    $ sudo systemctl reload php8.3-fpm

    If the service unit has a different version suffix, reload that unit instead. Apache module installs usually need an apache2 reload or restart rather than a PHP-FPM reload.

  7. Create a temporary web probe in the Nextcloud web root.
    $ sudo tee /var/www/nextcloud/memory-limit-check.php > /dev/null <<'PHP'
    <?php echo ini_get('memory_limit'), PHP_EOL;
    PHP

    Remove this file after checking the value. It exposes a PHP runtime setting through the public web path.

  8. Request the probe through the Nextcloud web hostname.
    $ curl -sS https://cloud.example.com/memory-limit-check.php
    1024M

    A web response of 1024M confirms that the PHP runtime behind the site loaded the new FPM or web-server setting.

  9. Remove the temporary probe.
    $ sudo rm /var/www/nextcloud/memory-limit-check.php
  10. Verify the CLI value as the web-server user.
    $ sudo -E -u www-data php -r 'echo ini_get("memory_limit"), PHP_EOL;'
    1024M

    On Debian and Ubuntu, www-data is the usual web-server user. Replace it with the account that owns the Nextcloud files on other platforms.
    Related: How to run Nextcloud occ commands

  11. Re-run setup checks when the original warning came from the administration overview.
    $ sudo -E -u www-data php /var/www/nextcloud/occ setupchecks

    The PHP memory-limit warning should no longer appear. Use the remaining red or yellow items as separate follow-up work instead of changing unrelated PHP settings.
    Related: How to check Nextcloud administration overview warnings