{"id":779,"date":"2026-08-03T02:45:27","date_gmt":"2026-08-03T02:45:27","guid":{"rendered":"https:\/\/virtualserversvps.com\/blog\/?p=779"},"modified":"2026-08-03T02:45:27","modified_gmt":"2026-08-03T02:45:27","slug":"apache-performance-tuning-vps-mpm-keepalive-caching","status":"publish","type":"post","link":"https:\/\/virtualserversvps.com\/blog\/apache-performance-tuning-vps-mpm-keepalive-caching\/","title":{"rendered":"Apache Performance Tuning on a VPS: MPM, KeepAlive, and Caching Configs That Matter"},"content":{"rendered":"\n\n<p class=\"wp-block-paragraph\">Apache has a reputation for being memory-hungry and slow under high concurrency \u2014 a reputation that mostly comes from misconfigured default installs. On a VPS with 2\u20134 GB of RAM, a stock Apache with the <code>prefork<\/code> MPM and <code>mod_php<\/code> can exhaust memory at a few hundred concurrent connections. Reconfigured with the <code>event<\/code> MPM, PHP-FPM, compression, and caching, the same Apache instance can serve thousands of requests per second on the same hardware.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">This guide walks through the Apache settings that matter most on a VPS, with exact configs and an <code>ab<\/code> benchmark to prove the difference. If you are still deciding between web servers for a small instance, the nginx vs Apache comparison on this site covers the trade-offs; and to see which provider&#8217;s plans give you enough RAM headroom for a threaded MPM, check <a href=\"https:\/\/virtualserversvps.com\/#providers\">our VPS comparison table<\/a>.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">1. Use the Event MPM, Not Prefork<\/h2>\n\n\n\n<p class=\"wp-block-paragraph\">The MPM (Multi-Processing Module) defines how Apache handles connections. <code>prefork<\/code> spawns one process per connection, each with a full copy of the interpreter \u2014 the memory killer on small VPS. The <code>event<\/code> MPM uses a small number of processes with many threads per process, and handles keep-alive connections in a dedicated thread pool. The result is roughly an order of magnitude fewer processes for the same traffic.<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code># Debian\/Ubuntu\na2dismod mpm_prefork\na2enmod mpm_event\nsystemctl restart apache2\n\n# Verify\napache2ctl -M | grep mpm<\/code><\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">One condition: <code>event<\/code> requires PHP to run as a separate process (PHP-FPM), not as <code>mod_php<\/code>. That is step 3 \u2014 and it is a requirement, not a suggestion.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">2. Size MaxRequestWorkers to Your RAM<\/h2>\n\n\n\n<p class=\"wp-block-paragraph\">The single most common Apache failure on a VPS is running out of memory because <code>MaxRequestWorkers<\/code> is far too high. Each worker thread costs memory, so compute the ceiling from your available RAM:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code># Measure a real worker's memory footprint:\nps -o rss,cmd -C apache2 | awk 'NR&gt;1 {sum+=$1} END {print \"avg KB\/worker:\", sum\/(NR-1)}'\n\n# On a 2 GB VPS with ~1.6 GB usable and ~30 MB per worker:\n# MaxRequestWorkers ~ (1.6GB * 1024) \/ 30MB \u2248 50<\/code><\/pre>\n\n\n\n<pre class=\"wp-block-code\"><code>\n    StartServers            3\n    MinSpareThreads         10\n    MaxSpareThreads         40\n    ThreadsPerChild         25\n    MaxRequestWorkers       50\n    MaxConnectionsPerChild  10000\n<\/code><\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">Start conservative (40\u201360 workers on a 2 GB VPS) and raise it while watching <code>free -h<\/code> under load. An OOM-killed Apache is far worse than a few queued requests.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">3. Serve PHP Through PHP-FPM<\/h2>\n\n\n\n<p class=\"wp-block-paragraph\">Running PHP inside Apache ties every worker to a PHP interpreter and forces the prefork model. Moving PHP to FPM lets Apache stay threaded and gives you per-pool memory limits, process control, and better opcode caching:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>apt install php-fpm\na2dismod php8.3\na2enmod proxy_fcgi setenvif\na2enconf php8.3-fpm\nsystemctl restart apache2 php8.3-fpm\n\n# Per-pool memory cap in \/etc\/php\/8.3\/fpm\/pool.d\/www.conf\npm = dynamic\npm.max_children = 20\npm.start_servers = 4\npm.min_spare_servers = 2\npm.max_spare_servers = 8\npm.max_requests = 500<\/code><\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">With <code>pm.max_requests = 500<\/code>, PHP-FPM recycles workers periodically, which prevents memory leaks from accumulating \u2014 a common cause of slow degradation on long-running VPS.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">4. KeepAlive: On, but Short<\/h2>\n\n\n\n<p class=\"wp-block-paragraph\">KeepAlive lets a client reuse the TCP connection for multiple requests \u2014 essential for pages with many assets. The mistake is leaving <code>KeepAliveTimeout<\/code> at the default 5\u201315 seconds, which pins worker threads to idle connections. Two to three seconds is plenty for HTTP\/1.1:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>KeepAlive On\nKeepAliveTimeout 2\nMaxKeepAliveRequests 100<\/code><\/pre>\n\n\n\n<h2 class=\"wp-block-heading\">5. Compression and Caching<\/h2>\n\n\n\n<p class=\"wp-block-paragraph\">Compression is the cheapest bandwidth win on a VPS. Enable <code>mod_deflate<\/code> (or <code>mod_brotli<\/code> if available) for text assets, and use <code>mod_expires<\/code> so browsers cache static files instead of re-requesting them:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>a2enmod deflate expires headers\n\n# \/etc\/apache2\/conf-available\/compression.conf\nAddOutputFilterByType DEFLATE text\/html text\/css application\/javascript application\/json\nExpiresActive On\nExpiresByType image\/png \"access plus 1 month\"\nExpiresByType text\/css \"access plus 1 week\"<\/code><\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">For dynamic content, add a reverse cache in front (Varnish) or use <code>mod_cache<\/code> with <code>CacheEnable disk<\/code> for cacheable responses. Even a 60-second cache on expensive pages can cut Apache&#8217;s CPU load by half on a traffic spike.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">6. Trim Modules You Do Not Use<\/h2>\n\n\n\n<p class=\"wp-block-paragraph\">Every loaded module costs memory per worker and CPU per request. List what is active and disable anything unnecessary:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>apache2ctl -M\n# Common candidates for removal on a lean VPS:\na2dismod autoindex status info userdir\nsystemctl restart apache2<\/code><\/pre>\n\n\n\n<h2 class=\"wp-block-heading\">7. Benchmark Before and After<\/h2>\n\n\n\n<p class=\"wp-block-paragraph\">Use ApacheBench against a small PHP page, and compare requests\/sec and the memory footprint before and after each change:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>ab -n 5000 -c 50 http:\/\/127.0.0.1\/index.php\nfree -m<\/code><\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">On a 2 vCPU \/ 2 GB VPS, the typical before\/after with the full recipe above is 3\u20135x more requests\/sec and 60% lower memory usage. The event MPM plus PHP-FPM is the bulk of the win; compression and caching are the multiplier.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">Conclusion<\/h2>\n\n\n\n<p class=\"wp-block-paragraph\">Apache is not the bottleneck on a VPS \u2014 a default configuration is. Switch to the event MPM, move PHP to FPM, size workers to RAM, and add compression and caching. Benchmark after every change, and keep an eye on <code>free -h<\/code> under load. If your plan is too small to run a threaded MPM comfortably, consider a host with more RAM headroom \u2014 <a href=\"https:\/\/virtualserversvps.com\/#providers\">see the full specs<\/a> across providers to find one that fits. For a budget-friendly KVM VPS with enough memory for a tuned Apache stack, <a href=\"https:\/\/interserver.net\/vps?id=1067805&amp;sid=virtualserversvps\" rel=\"noreferrer noopener sponsored\" target=\"_blank\">InterServer<\/a> is a popular choice among readers of this site.<\/p>\n\n","protected":false},"excerpt":{"rendered":"<p>Apache only becomes the bottleneck when it runs default configs. Switch to the event MPM, pair it with PHP-FPM, size workers to RAM, and add compression and caching \u2014 with benchmarks.<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"iawp_total_views":2,"footnotes":""},"categories":[3],"tags":[],"class_list":["post-779","post","type-post","status-publish","format-standard","hentry","category-performance-optimization"],"yoast_head":"<!-- This site is optimized with the Yoast SEO Premium plugin v26.1 (Yoast SEO v26.1) - https:\/\/yoast.com\/wordpress\/plugins\/seo\/ -->\n<title>Apache Performance Tuning on a VPS: MPM, KeepAlive, and Caching Configs That Matter - Virtual Servers VPS Blog<\/title>\n<meta name=\"robots\" content=\"index, follow, max-snippet:-1, max-image-preview:large, max-video-preview:-1\" \/>\n<link rel=\"canonical\" href=\"https:\/\/virtualserversvps.com\/blog\/apache-performance-tuning-vps-mpm-keepalive-caching\/\" \/>\n<meta property=\"og:locale\" content=\"en_US\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"Apache Performance Tuning on a VPS: MPM, KeepAlive, and Caching Configs That Matter\" \/>\n<meta property=\"og:description\" content=\"Apache Performance Tuning on a VPS: MPM, KeepAlive, and Caching Configs That Matter\" \/>\n<meta property=\"og:url\" content=\"https:\/\/virtualserversvps.com\/blog\/apache-performance-tuning-vps-mpm-keepalive-caching\/\" \/>\n<meta property=\"og:site_name\" content=\"Virtual Servers VPS Blog\" \/>\n<meta property=\"article:published_time\" content=\"2026-08-03T02:45:27+00:00\" \/>\n<meta name=\"author\" content=\"Virtual-Servers-Vps-Editor\" \/>\n<meta name=\"twitter:card\" content=\"summary_large_image\" \/>\n<meta name=\"twitter:label1\" content=\"Written by\" \/>\n\t<meta name=\"twitter:data1\" content=\"Virtual-Servers-Vps-Editor\" \/>\n\t<meta name=\"twitter:label2\" content=\"Est. reading time\" \/>\n\t<meta name=\"twitter:data2\" content=\"4 minutes\" \/>\n<script type=\"application\/ld+json\" class=\"yoast-schema-graph\">{\"@context\":\"https:\/\/schema.org\",\"@graph\":[{\"@type\":\"WebPage\",\"@id\":\"https:\/\/virtualserversvps.com\/blog\/apache-performance-tuning-vps-mpm-keepalive-caching\/\",\"url\":\"https:\/\/virtualserversvps.com\/blog\/apache-performance-tuning-vps-mpm-keepalive-caching\/\",\"name\":\"Apache Performance Tuning on a VPS: MPM, KeepAlive, and Caching Configs That Matter - Virtual Servers VPS Blog\",\"isPartOf\":{\"@id\":\"https:\/\/virtualserversvps.com\/blog\/#website\"},\"datePublished\":\"2026-08-03T02:45:27+00:00\",\"author\":{\"@id\":\"https:\/\/virtualserversvps.com\/blog\/#\/schema\/person\/82a299a8284a66ff49f97c74684724a0\"},\"breadcrumb\":{\"@id\":\"https:\/\/virtualserversvps.com\/blog\/apache-performance-tuning-vps-mpm-keepalive-caching\/#breadcrumb\"},\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"https:\/\/virtualserversvps.com\/blog\/apache-performance-tuning-vps-mpm-keepalive-caching\/\"]}]},{\"@type\":\"BreadcrumbList\",\"@id\":\"https:\/\/virtualserversvps.com\/blog\/apache-performance-tuning-vps-mpm-keepalive-caching\/#breadcrumb\",\"itemListElement\":[{\"@type\":\"ListItem\",\"position\":1,\"name\":\"Home\",\"item\":\"https:\/\/virtualserversvps.com\/blog\/\"},{\"@type\":\"ListItem\",\"position\":2,\"name\":\"Apache Performance Tuning on a VPS: MPM, KeepAlive, and Caching Configs That Matter\"}]},{\"@type\":\"WebSite\",\"@id\":\"https:\/\/virtualserversvps.com\/blog\/#website\",\"url\":\"https:\/\/virtualserversvps.com\/blog\/\",\"name\":\"Virtual Servers VPS Blog\",\"description\":\"\",\"potentialAction\":[{\"@type\":\"SearchAction\",\"target\":{\"@type\":\"EntryPoint\",\"urlTemplate\":\"https:\/\/virtualserversvps.com\/blog\/?s={search_term_string}\"},\"query-input\":{\"@type\":\"PropertyValueSpecification\",\"valueRequired\":true,\"valueName\":\"search_term_string\"}}],\"inLanguage\":\"en-US\"},{\"@type\":\"Person\",\"@id\":\"https:\/\/virtualserversvps.com\/blog\/#\/schema\/person\/82a299a8284a66ff49f97c74684724a0\",\"name\":\"Virtual-Servers-Vps-Editor\",\"image\":{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\/\/virtualserversvps.com\/blog\/#\/schema\/person\/image\/\",\"url\":\"https:\/\/secure.gravatar.com\/avatar\/d820b15f1cd028e97610d9adf536df7be5cb6423869967037d468d5355fa003f?s=96&d=mm&r=g\",\"contentUrl\":\"https:\/\/secure.gravatar.com\/avatar\/d820b15f1cd028e97610d9adf536df7be5cb6423869967037d468d5355fa003f?s=96&d=mm&r=g\",\"caption\":\"Virtual-Servers-Vps-Editor\"},\"sameAs\":[\"https:\/\/virtualserversvps.com\/blog\"],\"url\":\"https:\/\/virtualserversvps.com\/blog\/author\/virtualserversvps\/\"}]}<\/script>\n<!-- \/ Yoast SEO Premium plugin. -->","yoast_head_json":{"title":"Apache Performance Tuning on a VPS: MPM, KeepAlive, and Caching Configs That Matter - Virtual Servers VPS Blog","robots":{"index":"index","follow":"follow","max-snippet":"max-snippet:-1","max-image-preview":"max-image-preview:large","max-video-preview":"max-video-preview:-1"},"canonical":"https:\/\/virtualserversvps.com\/blog\/apache-performance-tuning-vps-mpm-keepalive-caching\/","og_locale":"en_US","og_type":"article","og_title":"Apache Performance Tuning on a VPS: MPM, KeepAlive, and Caching Configs That Matter","og_description":"Apache Performance Tuning on a VPS: MPM, KeepAlive, and Caching Configs That Matter","og_url":"https:\/\/virtualserversvps.com\/blog\/apache-performance-tuning-vps-mpm-keepalive-caching\/","og_site_name":"Virtual Servers VPS Blog","article_published_time":"2026-08-03T02:45:27+00:00","author":"Virtual-Servers-Vps-Editor","twitter_card":"summary_large_image","twitter_misc":{"Written by":"Virtual-Servers-Vps-Editor","Est. reading time":"4 minutes"},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"WebPage","@id":"https:\/\/virtualserversvps.com\/blog\/apache-performance-tuning-vps-mpm-keepalive-caching\/","url":"https:\/\/virtualserversvps.com\/blog\/apache-performance-tuning-vps-mpm-keepalive-caching\/","name":"Apache Performance Tuning on a VPS: MPM, KeepAlive, and Caching Configs That Matter - Virtual Servers VPS Blog","isPartOf":{"@id":"https:\/\/virtualserversvps.com\/blog\/#website"},"datePublished":"2026-08-03T02:45:27+00:00","author":{"@id":"https:\/\/virtualserversvps.com\/blog\/#\/schema\/person\/82a299a8284a66ff49f97c74684724a0"},"breadcrumb":{"@id":"https:\/\/virtualserversvps.com\/blog\/apache-performance-tuning-vps-mpm-keepalive-caching\/#breadcrumb"},"inLanguage":"en-US","potentialAction":[{"@type":"ReadAction","target":["https:\/\/virtualserversvps.com\/blog\/apache-performance-tuning-vps-mpm-keepalive-caching\/"]}]},{"@type":"BreadcrumbList","@id":"https:\/\/virtualserversvps.com\/blog\/apache-performance-tuning-vps-mpm-keepalive-caching\/#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"Home","item":"https:\/\/virtualserversvps.com\/blog\/"},{"@type":"ListItem","position":2,"name":"Apache Performance Tuning on a VPS: MPM, KeepAlive, and Caching Configs That Matter"}]},{"@type":"WebSite","@id":"https:\/\/virtualserversvps.com\/blog\/#website","url":"https:\/\/virtualserversvps.com\/blog\/","name":"Virtual Servers VPS Blog","description":"","potentialAction":[{"@type":"SearchAction","target":{"@type":"EntryPoint","urlTemplate":"https:\/\/virtualserversvps.com\/blog\/?s={search_term_string}"},"query-input":{"@type":"PropertyValueSpecification","valueRequired":true,"valueName":"search_term_string"}}],"inLanguage":"en-US"},{"@type":"Person","@id":"https:\/\/virtualserversvps.com\/blog\/#\/schema\/person\/82a299a8284a66ff49f97c74684724a0","name":"Virtual-Servers-Vps-Editor","image":{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/virtualserversvps.com\/blog\/#\/schema\/person\/image\/","url":"https:\/\/secure.gravatar.com\/avatar\/d820b15f1cd028e97610d9adf536df7be5cb6423869967037d468d5355fa003f?s=96&d=mm&r=g","contentUrl":"https:\/\/secure.gravatar.com\/avatar\/d820b15f1cd028e97610d9adf536df7be5cb6423869967037d468d5355fa003f?s=96&d=mm&r=g","caption":"Virtual-Servers-Vps-Editor"},"sameAs":["https:\/\/virtualserversvps.com\/blog"],"url":"https:\/\/virtualserversvps.com\/blog\/author\/virtualserversvps\/"}]}},"_links":{"self":[{"href":"https:\/\/virtualserversvps.com\/blog\/wp-json\/wp\/v2\/posts\/779","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/virtualserversvps.com\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/virtualserversvps.com\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/virtualserversvps.com\/blog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/virtualserversvps.com\/blog\/wp-json\/wp\/v2\/comments?post=779"}],"version-history":[{"count":2,"href":"https:\/\/virtualserversvps.com\/blog\/wp-json\/wp\/v2\/posts\/779\/revisions"}],"predecessor-version":[{"id":788,"href":"https:\/\/virtualserversvps.com\/blog\/wp-json\/wp\/v2\/posts\/779\/revisions\/788"}],"wp:attachment":[{"href":"https:\/\/virtualserversvps.com\/blog\/wp-json\/wp\/v2\/media?parent=779"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/virtualserversvps.com\/blog\/wp-json\/wp\/v2\/categories?post=779"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/virtualserversvps.com\/blog\/wp-json\/wp\/v2\/tags?post=779"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}