Skip to content

Nextcloud Php Memory

DodaTech 3 min read

In this tutorial, you'll learn about Nextcloud PHP Memory Limit. We cover key concepts, practical examples, and best practices.

Hook

You open your Nextcloud dashboard and see "PHP memory limit below recommended value: 512MB." Your sync client drops connections with "out of memory" errors. Uploads of large files fail halfway through. PHP memory is the silent bottleneck in every Nextcloud server.

The Wrong Way

Some users increase memory_limit in the CLI php.ini and wonder why the web UI still shows the warning. Others set the limit absurdly high (like -1 for unlimited), which allows memory leaks to crash the server.

# BAD: Editing the wrong php.ini or setting unlimited
sed -i 's/memory_limit = 128M/memory_limit = -1/' /etc/php/8.3/cli/php.ini
PHP Warning: Nextcloud requires at least 512 MB memory
Web UI: Still showing 128M limit

The CLI and web server (FPM) use different php.ini files. You must edit the FPM config.

The Right Way

Edit the correct php.ini for your web server's PHP version.

# 1. Find the right php.ini
php -i | grep "Loaded Configuration File" | head -1
# For FPM, check:
grep -r "memory_limit" /etc/php/*/fpm/php.ini
# 2. Edit the FPM php.ini
sudo sed -i 's/memory_limit = 128M/memory_limit = 512M/' /etc/php/8.3/fpm/php.ini
# 3. Also edit the CLI php.ini for occ commands
sudo sed -i 's/memory_limit = 128M/memory_limit = 512M/' /etc/php/8.3/cli/php.ini
# 4. Restart PHP-FPM
sudo systemctl restart php8.3-fpm
PHP memory limit: 512M
Nextcloud Web UI: "All checks passed" ✓

Verify with php -i | grep memory_limit and check Nextcloud Administration → Overview.

Prevention

  • Set memory_limit = 512M (or 1024M for large installations) in both fpm/php.ini and cli/php.ini.
  • Monitor PHP-FPM memory usage with htop or pm.status.
  • Use PHP 8.1 or newer — it is more memory-efficient for Nextcloud.
  • Set upload_max_filesize and post_max_size to at least 8G for large file support.
  • After every PHP update, verify the memory limit is still at your desired value.

Advanced Troubleshooting

Check the Logs

Most TOOL errors are logged to stdout or a dedicated log file. Check your logs first:

# Check system logs
journalctl -u tool --since "1 hour ago"

# Or check the application log
tail -50 ~/.tool/logs/error.log

Test with a Minimal Example

Create the simplest possible tool configuration to verify the base setup works:

tool --version
tool --help

If the minimal test passes, add configuration options one at a time until you find the breaking change.

Common Configuration Mistakes

  • Using the wrong file path or URL in configuration
  • Forgetting to restart TOOL after changing config files
  • Mixing tabs and spaces in YAML configuration files
  • Setting incorrect permissions on configuration directories

When to Reinstall

If none of the above resolves the issue, consider a clean reinstall:

# Backup your configuration
cp -r ~/.tool ~/.tool.bak

# Remove and reinstall
# Follow the official TOOL installation guide

This ensures you start from a known good state and can isolate the issue.

Common Mistakes with php memory

  1. Misunderstanding that String is [Char] with poor performance for large text operations
  2. Using foldl instead of foldl' causing stack overflow on large lists
  3. Forgetting deriving (Show, Eq) on custom data types needed for debugging

These mistakes appear frequently in real-world NEXTCLOUD code. DodaTech's contributors have identified these patterns through analysis of open-source projects and production systems.

Practice Exercise

Write a pure function that safely divides two integers using Maybe, then test it with edge cases like division by zero and negative numbers.

This exercise reinforces the concepts covered in this guide. Try implementing it before checking online solutions.

FAQ

How much memory does Nextcloud actually need?

Nextcloud recommends at least 512 MB for the PHP process. With many apps (Nextcloud Talk, Collabora), 1-2 GB is more realistic. Each concurrent sync client also uses memory on the server.

Why does occ say 'out of memory' even with 512M?

Large database migrations or file scans can exceed 512 MB. Temporarily set memory_limit = 1G in the CLI php.ini for heavy operations. Revert it after the command completes.

Does PHP memory limit affect upload size?

Indirectly. The upload_max_filesize and post_max_size settings control the maximum upload size. But large uploads processed through PHP consume memory proportionally. Increase both limits together.


DodaTech — give Nextcloud the memory it deserves.

Built by the developers of DodaTech

Doda Browser, DodaZIP & Durga Antivirus Pro