apache2.conf
To diagnose and solve the recurring Apache memory issue on your 2 GB RAM + 2 GB swap Debian 13 VPS, let's break this down systematically.
From your logs:
status=1/FAILURE and a memory peak of 1G (RAM) + 771.9M (swap).Run:
bashtail -n 100 /var/log/apache2/error.log
Look for:
Out of memory errors.mod_php, mod_perl).malloc failures.Run:
bashdmesg | grep -i "oom\|kill"
If the kernel killed Apache, you'll see entries like:
textOut of memory: Kill process 12345 (apache2) score 900 or sacrifice child
Use htop, glances, or sar to track memory usage before the next crash.
Example:
bashapt install htop htop
F6 → MEM%).bashecho "0 3 * * * systemctl restart apache2" | sudo tee /etc/cron.d/apache_restart
mod_php, mod_perl, mod_wsgi (Python), or custom modules.basha2dismod php8.2 mpm_prefork # Example: Disable PHP and prefork systemctl restart apache2
mpm_event (lower memory footprint):
basha2dismod mpm_prefork a2enmod mpm_event systemctl restart apache2
bashtail -n 100 /var/log/php8.2-fpm.log
/etc/php/8.2/fpm/pool.d/www.conf:
Then restart:inipm.max_children = 10 # Reduce from default (e.g., 50) pm.start_servers = 2 pm.min_spare_servers = 2 pm.max_spare_servers = 4 pm.max_requests = 500 # Restart workers after 500 requests
bashsystemctl restart php8.2-fpm apache2
MaxRequestWorkers (formerly MaxClients):
In /etc/apache2/apache2.conf or /etc/apache2/mpm_prefork.conf:
apache<IfModule mpm_prefork_module> StartServers 2 MinSpareServers 2 MaxSpareServers 4 MaxRequestWorkers 10 # Default is often 150+! Reduce to 10-20 for 2GB RAM MaxConnectionsPerChild 1000 </IfModule>
MaxRequestsPerChild:
Forces Apache to recycle workers after N requests (prevents leaks):
apacheMaxRequestsPerChild 1000
bashecho "vm.swappiness=10" | sudo tee -a /etc/sysctl.conf sysctl -p
/etc/sysctl.conf:
Then runinivm.min_free_kbytes = 65536 # Reserve 64MB for kernel
sysctl -p.bashapt install nginx php8.2-fpm systemctl disable apache2 systemctl enable nginx php8.2-fpm
netdata or prometheus for real-time monitoring:
bashbash <(curl -Ss https://my-netdata.io/kickstart.sh)
/etc/apache2/apache2.conf (as you mentioned attaching it) so I can check for misconfigurations.mpm_event + reduced MaxRequestWorkers and monitor for 24-48 hours.Question: Are you running any specific web apps (e.g., WordPress, Nextcloud) or custom Apache modules? This will help narrow down the root cause.
Vibe can make mistakes. Check answers. Learn more