The Short Answer
A slow VPS is usually slow for one specific reason — a starved resource, a missing cache, or a misconfigured service — and guessing wastes time. The fastest path to a faster server is: measure first, fix the actual bottleneck, then work through the cheap wins (caching, compression, PHP and database tuning) before spending money on a bigger plan. This guide gives you exactly 12 fixes, ordered from diagnosis to upgrade, each with the commands to apply it on Ubuntu 24.04.
Before you change anything, take a snapshot or backup — see How to Back Up Your VPS. Performance tuning involves editing live configuration, and a snapshot is your undo button.
Fix 1: Find the Real Bottleneck Before Touching Anything
Slow has four possible causes: CPU, RAM, disk, or network. Each has a different fix, so diagnose first with three commands:
htop # CPU and RAM usage per process (install with sudo apt install htop)
df -h # disk space
iostat -x 1 3 # disk I/O wait (install with sudo apt install sysstat)
What the numbers mean:
- CPU at 100% constantly: something is working too hard — a runaway process, an uncached application, or a server that is simply too small. Fixes 2, 3, 6 and 12 apply.
- RAM full with heavy swap use: the server is paging to disk, which is catastrophically slow. Fixes 4, 5 and 12 apply.
- High
%iowaitin iostat: the disk cannot keep up — common on old spinning-disk or overloaded shared-storage plans. Fixes 7 and 12 apply. - Everything looks idle but the site is slow: the problem is the network path, DNS, or the application itself (slow queries, external API calls). Fixes 8, 9 and 10 apply.
Also check the load average with uptime. On a 2-vCPU server, a load average consistently above 2 means processes are queuing for CPU. A load of 0.5 on the same server means the CPU is half idle — look elsewhere.
Fix 2: Enable Page Caching (Biggest Single Win for WordPress)
An uncached WordPress page triggers dozens of database queries and a full PHP execution on every visit. A page cache serves a pre-built HTML file instead — the difference is typically an order of magnitude in response time and server load.
For WordPress, install a caching plugin: WP Super Cache (free, simple) or LiteSpeed Cache (free, powerful, works on any server despite the name). Enable page caching, then verify it works: load a page twice and check the response headers for X-Cache: HIT or a cache comment in the HTML source. If every request still shows a miss, the cache is misconfigured — a common cause is a cookie-setting plugin (analytics, consent banners) that marks every visitor as unique.
For non-WordPress sites, Nginx’s built-in FastCGI cache or proxy cache does the same job at the server level. A basic FastCGI cache for PHP:
fastcgi_cache_path /var/cache/nginx levels=1:2 keys_zone=WORDPRESS:100m inactive=60m;
Then add fastcgi_cache WORDPRESS; to your PHP location block. This is more work than a plugin but caches everything, including non-WordPress PHP applications.
Fix 3: Add OPcache and Tune PHP-FPM
PHP recompiles every script on every request unless OPcache is enabled. OPcache stores compiled bytecode in memory, and it is the single highest-value PHP setting:
php -m | grep -i opcache
If nothing appears, install and enable it:
sudo apt install php8.3-opcache
sudo systemctl restart php8.3-fpm
Then tune PHP-FPM’s process manager. The defaults are conservative. Edit the pool configuration:
sudo nano /etc/php/8.3/fpm/pool.d/www.conf
For a 2 GB server running one site, sensible values are:
pm = dynamic
pm.max_children = 10
pm.start_servers = 3
pm.min_spare_servers = 2
pm.max_spare_servers = 5
pm.max_requests = 500
pm.max_children is the critical number: each PHP child uses roughly 30–60 MB of RAM, so 10 children reserve up to 600 MB. Setting it too high causes out-of-memory kills; too low causes request queuing. Restart PHP-FPM after editing: sudo systemctl restart php8.3-fpm.
Fix 4: Add a Swap File (Emergency RAM for Small Servers)
If your server has 1–2 GB of RAM, a swap file prevents the out-of-memory killer from terminating MySQL or PHP-FPM under load spikes. Swap is slow — disk is not RAM — but slow beats dead. Create a 2 GB swap file:
sudo fallocate -l 2G /swapfile
sudo chmod 600 /swapfile
sudo mkswap /swapfile
sudo swapon /swapfile
echo '/swapfile none swap sw 0 0' | sudo tee -a /etc/fstab
Reduce the system’s eagerness to swap (so it uses swap only when truly necessary):
echo 'vm.swappiness=10' | sudo tee -a /etc/sysctl.conf
sudo sysctl -p
Check with free -h. If swap usage stays high permanently, the server needs more RAM (Fix 12), not more swap.
Fix 5: Tune MySQL/MariaDB for Your Server Size
MySQL’s default configuration assumes a large server. On a small VPS, the InnoDB buffer pool — MySQL’s main memory cache — is often set far too large or far too small. The rule of thumb: set it to about 50–70% of available RAM on a dedicated database server, or 25–40% on a server that also runs PHP and Nginx.
Check your current setting and usage:
sudo mysql -e "SHOW VARIABLES LIKE 'innodb_buffer_pool_size';"
Set it in /etc/mysql/my.cnf or a file under /etc/mysql/conf.d/:
[mysqld]
innodb_buffer_pool_size = 512M
(Use 512M on a 2 GB server, 1G on a 4 GB server.) Restart MySQL: sudo systemctl restart mysql. For a deeper analysis, run mysqltuner (a free Perl script) after the server has been running under load for at least 24 hours — it reads real usage statistics and suggests concrete values rather than guesses.
Also enable the slow query log to find expensive queries:
slow_query_log = 1
slow_query_log_file = /var/log/mysql/slow.log
long_query_time = 2
Any query taking over 2 seconds gets logged. In WordPress, slow queries usually come from a plugin doing unindexed lookups — the fix is replacing the plugin or adding the missing index, not buying a bigger server.
Fix 6: Use Redis or Memcached for Object Caching
Page caching (Fix 2) handles anonymous visitors. Logged-in users, WooCommerce carts and admin pages bypass the page cache — and each one hits the database. An object cache stores database query results in memory so repeated queries return instantly.
Redis is the standard choice:
sudo apt install redis-server php8.3-redis
sudo systemctl enable --now redis-server
For WordPress, add the free Redis Object Cache plugin and enable it — the plugin connects to the local Redis server with no configuration. For other applications, point the app’s cache driver at 127.0.0.1:6379.
Secure Redis: by default it listens only on localhost, which is correct. Never expose Redis to the internet — an open Redis port is one of the most commonly exploited misconfigurations on a VPS. Confirm with sudo ss -tlnp | grep 6379 that it listens on 127.0.0.1 only.
Fix 7: Free Disk Space and Move to Faster Storage
A disk over 90% full slows everything: databases cannot write temp tables, logs rotate aggressively, and some filesystems degrade sharply near capacity. Find what is eating space:
sudo du -sh /var/* 2>/dev/null | sort -rh | head -10
sudo journalctl --disk-usage
Common culprits and fixes:
- Systemd journal: cap it with
sudo journalctl --vacuum-size=200Mand setSystemMaxUse=200Min/etc/systemd/journald.conf. - Old kernels:
sudo apt autoremove --purgeremoves superseded kernel packages. - Docker:
docker system prune -aremoves unused images (see How to Install Docker on a VPS). - Log files: check
/var/logfor a runaway log — a single verbose application can write gigabytes.
If the disk itself is slow (high %iowait in Fix 1), the fix is hardware: move to an NVMe plan. Most providers’ current lineups use NVMe by default; older budget plans may still use SATA SSDs. See NVMe vs SSD VPS: Is NVMe Storage Worth It? for the comparison.
Fix 8: Enable Compression and Browser Caching
Compression shrinks what the server sends; browser caching stops repeat visitors downloading the same files. Both are one-time Nginx configuration:
gzip on;
gzip_vary on;
gzip_min_length 1024;
gzip_types text/plain text/css application/json application/javascript text/xml application/xml text/javascript image/svg+xml;
And for static assets, tell browsers to cache them for a month:
location ~* \.(jpg|jpeg|png|gif|ico|css|js|svg|woff2)$ {
expires 30d;
add_header Cache-Control "public, immutable";
}
Test the configuration and reload: sudo nginx -t && sudo systemctl reload nginx. Verify compression with curl -H "Accept-Encoding: gzip" -I https://yourdomain.com — look for content-encoding: gzip in the response.
Fix 9: Put a CDN in Front of Static Content
A content delivery network serves your images, CSS and JavaScript from servers near your visitors, cutting latency and removing that traffic from your VPS entirely. Cloudflare’s free plan is the usual starting point: point your domain’s nameservers at Cloudflare, enable proxying, and static assets are cached at the edge automatically. Your origin server then handles only dynamic requests.
This also reduces bandwidth usage on metered plans and absorbs traffic spikes that would otherwise overwhelm a small VPS. The trade-off: Cloudflare sits between your visitors and your server, so server logs show Cloudflare IPs unless you configure real-IP restoration (see How to Point a Domain to Your VPS).
Fix 10: Reduce External Requests and Heavy Plugins
A page that calls five external services (analytics, fonts, embeds, chat widgets, ad networks) waits on the slowest of them. Audit with your browser’s developer tools (Network tab) or PageSpeed Insights, then:
- Host fonts locally instead of loading Google Fonts on every page.
- Replace social-media embeds with static images linked to the post.
- Remove plugins you do not use — each active WordPress plugin adds code to every request. Deactivate plugins one at a time and measure the difference; a single bad plugin can add a full second.
- Lazy-load images and videos below the fold so they do not block the initial render.
This fix costs nothing and often beats hardware upgrades, because no amount of CPU helps a page waiting on a slow third-party server.
Fix 11: Keep the Server Clean and Updated
Performance degrades gradually: leftover services consume RAM, old software has known slow paths, and unrotated logs fill disks. A monthly maintenance pass:
sudo apt update && sudo apt upgrade -y
sudo apt autoremove --purge -y
sudo systemctl list-units --type=service --state=running | grep -v "loaded active"
Review the running services and stop anything you do not use — each one holds memory and occasionally wakes the CPU. Check for failed services (sudo systemctl --failed) and for cron jobs that no longer serve a purpose. If you secured the server following How to Secure Your VPS, unattended-upgrades already handles security patches; the manual pass catches everything else.
Fix 12: Upgrade the Server (When Tuning Is Not Enough)
If the bottleneck is genuinely hardware — CPU saturated after caching, RAM exhausted after tuning, disk I/O maxed on NVMe — it is time for a bigger plan. The good news: most providers let you resize without reinstalling, and the process is usually quick. The full procedure, including zero-downtime strategies, is in How to Upgrade Your VPS.
Before upgrading, confirm the bottleneck one more time with Fix 1’s measurements. Upgrading a server whose real problem is an uncached plugin wastes money and fixes nothing — the site will be slow on 8 GB exactly as it was on 2 GB.
Troubleshooting
“I enabled caching but the site is still slow.” Verify the cache is actually hitting: check response headers for X-Cache: HIT, and confirm the cache is not bypassed for every visitor by a cookie-setting plugin. Also re-run Fix 1 — the bottleneck may be the database or CPU, not page generation.
“PHP-FPM keeps crashing after I raised max_children.” You set it too high for the available RAM. Each child uses 30–60 MB; 20 children on a 2 GB server will exhaust memory. Lower max_children and check the PHP-FPM error log at /var/log/php8.3-fpm.log.
“MySQL won’t start after I changed the buffer pool.” The value exceeds available RAM, or the configuration file has a syntax error. Check sudo journalctl -u mysql -n 50 for the error, reduce the value, and restart. Keep a backup of the original configuration file before editing.
“The site is fast for me but slow for visitors elsewhere.” That is latency, not server speed — your visitors are far from the server’s data center. A CDN (Fix 9) helps for static content; for dynamic content, consider a server location closer to your audience, or a second server in another region.
“Load average is high but CPU usage looks low.” High load with low CPU usually means processes waiting on disk I/O — check %iowait in iostat. The fix is faster storage or reducing disk reads (more caching, more RAM for the database buffer pool).
Frequently Asked Questions
How do I know if my VPS is slow or my website is slow?
Test the server directly: run curl -o /dev/null -s -w "Time: %{time_total}s\n" https://yourdomain.com from another machine. Under 0.5 seconds is good; over 2 seconds needs work. Then compare a static file (curl a .jpg URL) with a dynamic page — if the static file is fast and the page is slow, the application is the problem, not the server.
Will more RAM always make my VPS faster?
Only if RAM is the bottleneck. If the server has free RAM and the CPU is saturated, extra memory changes nothing. Measure first (Fix 1), then buy the resource that is actually exhausted. This is the most common money-wasting mistake in VPS upgrades.
Is a CDN worth it for a small site?
Yes — Cloudflare’s free tier costs nothing and removes static-asset load from your server while cutting latency for distant visitors. The setup takes under an hour and the benefit is immediate, especially for image-heavy sites.
How often should I run maintenance?
Security updates: automatic, daily (unattended-upgrades). Manual maintenance pass: monthly. Cache and performance review: after any major change (new plugin, traffic spike, redesign). Set up monitoring (see How to Monitor Your VPS) so problems alert you instead of waiting for the monthly check.
Can a $4/month VPS be fast?
Yes, for a small cached site. A 1 GB server running Nginx, PHP-FPM with OPcache, a page cache and a CDN can serve a modest WordPress blog quickly — the cache means most requests never touch PHP or MySQL. What a cheap server cannot do is handle heavy uncached traffic, large databases, or many concurrent logged-in users.
The Bottom Line
Measure first, cache aggressively, tune PHP and MySQL to your server’s actual size, compress and cache static assets, and put a CDN in front — those five moves fix the vast majority of slow VPS complaints without spending a cent. Upgrade only when the measurements prove the hardware is the limit, and you will spend money on the resource that actually matters.



Leave a Reply