Differences
This shows you the differences between two versions of the page.
Both sides previous revision Previous revision Next revision | Previous revision | ||
os_nextcloud [2025/03/18 01:36] – [Optimized PHP Configuration] Júne Park | os_nextcloud [2025/04/14 08:48] (current) – [Edit - Panel] Júne Park | ||
---|---|---|---|
Line 1: | Line 1: | ||
- | ====== Nextcloud™ ====== | + | ====== Nextcloud™ ====== |
---- | ---- | ||
+ | ===== Required packages ===== | ||
+ | |||
+ | <code bash> | ||
+ | sudo apt install php8.x php8.x-common php8.x-gmp php8.x-mbstring php8.x-readline php8.x-xmlrpc php8.x-bcmath php8.x-curl php8.x-igbinary php8.x-mcrypt php8.x-redis php8.x-zip php8.x-bz2 php8.x-fpm php8.x-imagick php8.x-mysql php8.x-soap php8.x-cli php8.x-gd php8.x-intl php8.x-opcache php8.x-xml | ||
+ | </ | ||
+ | |||
+ | ---- | ||
==== Optimized PHP Configuration ==== | ==== Optimized PHP Configuration ==== | ||
Line 72: | Line 79: | ||
---- | ---- | ||
+ | === Enable JIT in Opcache === | ||
+ | |||
+ | Edit ''/ | ||
+ | |||
+ | <code php> | ||
+ | ; configuration for php opcache module | ||
+ | ; priority=10 | ||
+ | zend_extension=opcache.so | ||
+ | opcache.enable_cli=1 | ||
+ | opcache.jit_buffer_size=100M | ||
+ | opcache.jit=tracing | ||
+ | </ | ||
+ | |||
+ | Check JIT is enabled | ||
+ | |||
+ | <code bash> | ||
+ | sudo php -i | grep -q ' | ||
+ | </ | ||
+ | |||
+ | ---- | ||
+ | |||
+ | ==== Optimized PHP-FPM Configuration ==== | ||
+ | |||
+ | PHP-FPM settings are typically in a pool configuration file like ''/ | ||
+ | |||
+ | === Process Manager Settings === | ||
+ | |||
+ | <code ini> | ||
+ | pm = dynamic | ||
+ | ; " | ||
+ | |||
+ | pm.max_children = 120 | ||
+ | ; Max number of child processes; calculate as (Total RAM - 1G for OS/other services) / 50-100 MB per process. | ||
+ | ; Example: 4 GB RAM → ~60-80 children; 8 GB RAM → ~120-150 children. | ||
+ | |||
+ | pm.start_servers = 12 | ||
+ | ; Initial processes; set to ~10-20% of max_children. | ||
+ | |||
+ | pm.min_spare_servers = 6 | ||
+ | ; Minimum idle processes; set to ~5-10% of max_children. | ||
+ | |||
+ | pm.max_spare_servers = 18 | ||
+ | ; Maximum idle processes; set to ~15-25% of max_children. | ||
+ | |||
+ | pm.max_requests = 500 | ||
+ | ; Restart child processes after this many requests to prevent memory leaks. | ||
+ | </ | ||
+ | |||
+ | ---- | ||
+ | |||
+ | === Tuning Tips === | ||
+ | |||
+ | * Memory Usage: Each PHP-FPM process may use 50-100 MB of RAM, depending on loaded extensions and workload. Monitor with '' | ||
+ | |||
+ | * CPU Cores: Ensure '' | ||
+ | |||
+ | * Static vs. Dynamic: Use '' | ||
+ | |||
+ | |||
+ | ---- | ||
+ | |||
+ | === Additional PHP-FPM Settings === | ||
+ | |||
+ | Edit ''/ | ||
+ | |||
+ | < | ||
+ | <code ini> | ||
+ | request_terminate_timeout = 300 | ||
+ | ; Match max_execution_time to handle long uploads gracefully. | ||
+ | |||
+ | process.priority = -19 | ||
+ | ; Optional: Boost priority (requires root and SYS_NICE capability). | ||
+ | </ | ||
+ | |||
+ | ---- | ||
+ | |||
+ | Optimal configuration for ''/ | ||
+ | |||
+ | <panel title=" | ||
+ | <code ini> | ||
+ | ; configuration for php opcache module | ||
+ | ; priority=10 | ||
+ | opcache.enable = 1 | ||
+ | ; Enable OPcache. | ||
+ | |||
+ | opcache.memory_consumption = 128 | ||
+ | ; Memory for cached scripts (128 MB is a good starting point; increase to 256 MB if RAM allows). | ||
+ | |||
+ | opcache.interned_strings_buffer = 8 | ||
+ | ; Memory for string interning (8 MB is sufficient for most cases). | ||
+ | |||
+ | opcache.max_accelerated_files = 10000 | ||
+ | ; Max number of files to cache; adjust based on Nextcloud’s file count. | ||
+ | |||
+ | opcache.revalidate_freq = 60 | ||
+ | ; How often to check for file changes (60 seconds balances performance and freshness). | ||
+ | |||
+ | opcache.save_comments = 1 | ||
+ | ; Required by Nextcloud to preserve code comments in bytecode. | ||
+ | |||
+ | zend_extension=opcache.so | ||
+ | opcache.enable_cli = 1 | ||
+ | ; Disable for CLI to avoid unnecessary overhead in cron jobs. | ||
+ | ; | ||
+ | opcache.jit_buffer_size = 100M | ||
+ | opcache.jit = tracing | ||
+ | ; " | ||
+ | ; | ||
+ | opcache.interned_strings_buffer = 16 | ||
+ | opcache.memory_consumption = 256 | ||
+ | </ | ||
+ | </ | ||
+ | </ | ||
+ | |||
+ | |||
+ | ---- | ||
+ | ==== Nextcloud-Specific Tweaks ==== | ||
+ | |||
+ | {{mdi> | ||
+ | |||
+ | * Memory Caching: Use Redis for local and file-locking caches to reduce database load. Edit ''/ | ||
+ | <code php> | ||
+ | ' | ||
+ | ' | ||
+ | ' | ||
+ | ' | ||
+ | ' | ||
+ | ], | ||
+ | </ | ||
+ | | ||
+ | <code php> | ||
+ | <?php | ||
+ | $CONFIG = array ( | ||
+ | ... ... ... | ||
+ | ... | ||
+ | ), | ||
+ | ' | ||
+ | ' | ||
+ | ' | ||
+ | ' | ||
+ | ' | ||
+ | array ( | ||
+ | ' | ||
+ | ' | ||
+ | ' | ||
+ | ' | ||
+ | ), | ||
+ | ); | ||
+ | </ | ||
+ | |||
+ | Install Redis (sudo apt install redis-server on Debian) and ensure it’s running. | ||
+ | |||
+ | <code bash> | ||
+ | sudo apt install redis-server php-redis | ||
+ | </ | ||
+ | |||
+ | <code bash> | ||
+ | sudo ps ax | grep redis | ||
+ | sudo netstat -tlnp | grep redis | ||
+ | </ | ||
+ | |||
+ | Clearing Redis Cache | ||
+ | |||
+ | <code bash> | ||
+ | sudo redis-cli | ||
+ | SELECT < | ||
+ | FLUSHDB | ||
+ | </ | ||
+ | |||
+ | |||
+ | * Cron Jobs: Use a system cron job instead of AJAX for background tasks. Add to ''/ | ||
+ | |||
+ | <code bash> | ||
+ | */5 * * * * www-data php -f / | ||
+ | </ | ||
+ | |||
+ | * Database: Use MySQL/ | ||
+ | |||
+ | |||
+ | ---- | ||
+ | |||
+ | ==== Validation ==== | ||
+ | |||
+ | * Check PHP settings: Create a phpinfo.php file with <?php phpinfo(); and access it via your browser. | ||
+ | |||
+ | * Monitor performance: | ||
+ | |||
+ | * Test responsiveness: | ||
+ | |||
+ | ---- | ||
+ | |||
+ | ==== Scaling Adjustments ==== | ||
+ | |||
+ | * Low-End Servers (e.g., Raspberry Pi, 2 GB RAM): Reduce '' | ||
+ | |||
+ | * High-Traffic Servers (e.g., 16+ GB RAM): Increase '' | ||
+ | |||
+ | |||
+ | This configuration provides a solid starting point for Nextcloud, balancing performance and resource efficiency. Fine-tune based on your server’s actual usage patterns and hardware capabilities. | ||
+ | |||
+ | ---- | ||
+ | ===== Alter datadirectory after installation ===== | ||
+ | |||
+ | <code ini> | ||
+ | ncdir='/ | ||
+ | olddata='/ | ||
+ | newdata='/ | ||
+ | </ | ||
+ | |||
+ | Turn maintenance mode on | ||
+ | |||
+ | <code bash> | ||
+ | sudo -u www-data php " | ||
+ | </ | ||
+ | |||
+ | Move / Copy datadirectory for your purpose. | ||
+ | |||
+ | Change '' | ||
+ | |||
+ | <code bash> | ||
+ | sudo sed -i " | ||
+ | </ | ||
+ | |||
+ | Before change database dataset, backup database for your safety. | ||
+ | |||
+ | Adjust '' | ||
+ | |||
+ | <code mysql> | ||
+ | mysql -u" | ||
+ | </ | ||
+ | |||
+ | ---- | ||
===== Solved Problems ===== | ===== Solved Problems ===== | ||
- | === mjs configuration error === | + | ==== mjs configuration error ==== |
== Error description == | == Error description == | ||
Line 96: | Line 335: | ||
# } | # } | ||
</ | </ | ||
+ | |||
+ | ---- | ||
+ | |||
+ | ==== PHP imagick module ==== | ||
+ | |||
+ | == Error description == | ||
+ | |||
+ | <text type=" | ||
+ | |||
+ | == Solution == | ||
+ | |||
+ | Install php-imagick moduel with associated packages | ||
+ | |||
+ | <code bash> | ||
+ | sudo apt install php-imagick imagemagick | ||
+ | </ | ||
+ | |||
+ | ---- | ||
+ | |||
+ | ==== Incorrect row format found ==== | ||
+ | |||
+ | == Error description == | ||
+ | |||
+ | <text type=" | ||
+ | |||
+ | == Solution == | ||
+ | |||
+ | Create the script and run with root permission with following: | ||
+ | |||
+ | <code bash> | ||
+ | #!/bin/bash | ||
+ | |||
+ | # Prompt for database credentials | ||
+ | read -p "Enter Database Name: " DB_NAME | ||
+ | read -p "Enter Username: " DB_USER | ||
+ | read -s -p "Enter Password: " DB_PASS | ||
+ | echo | ||
+ | |||
+ | # Execute all ALTER TABLE statements in one query | ||
+ | mysql -u " | ||
+ | SELECT CONCAT(' | ||
+ | FROM INFORMATION_SCHEMA.TABLES | ||
+ | WHERE TABLE_SCHEMA = ' | ||
+ | AND ENGINE = ' | ||
+ | " | mysql -u " | ||
+ | |||
+ | </ | ||
+ | |||
+ | ---- |