A slow server affects user experience, search engine rankings, and business revenue. This guide helps you identify the cause of poor performance and apply targeted optimizations to speed things up.
Step 1 — Identify the Bottleneck
Server performance issues are typically caused by one of four resources:
Check CPU Usage
htopIf CPU is consistently above 80%, identify the top processes and determine if they need optimization.
Check Memory
free -hIf available memory is very low (under 100 MB), you may need to optimize memory usage or upgrade.
Check Disk Space and I/O
# Disk space
df -hDisk I/O performance
iostat -x 5High I/O wait (%iowait in top or vmstat) indicates disk bottlenecks.
Check Network
# Bandwidth usage
sudo nethogsNetwork connections
ss -tulnStep 2 — CPU Optimization
Identify CPU-Hungry Processes
# Sort by CPU usage
ps aux --sort=-%cpu | head -20Common CPU Consumers and Fixes
| Process | Fix |
|---|---|
| MySQL/MariaDB | Optimize queries, add indexes, increase buffer pool |
| PHP-FPM | Reduce worker processes, enable opcache |
| Apache | Reduce MaxRequestWorkers, switch to event MPM or Nginx |
| Node.js | Check for infinite loops, optimize code |
| Cron jobs | Stagger schedules, optimize scripts |
| Malware/miners | Investigate unknown processes, secure server |
Optimize MySQL
-- Find slow queries SHOW PROCESSLIST;
-- Enable slow query log SET GLOBAL slow_query_log = 'ON'; SET GLOBAL long_query_time = 2;
Step 3 — Memory Optimization
Identify Memory-Hungry Processes
ps aux --sort=-%mem | head -20Reduce Memory Usage
Web server:
# Nginx — reduce worker connections sudo nano /etc/nginx/nginx.confSet: worker_connections 512;
Apache — reduce MaxRequestWorkers
sudo nano /etc/apache2/mods-enabled/mpm_prefork.conf
Reduce MaxRequestWorkers to match available RAM
PHP:
sudo nano /etc/php/*/fpm/php.ini
Set: memory_limit = 128M (reduce from 256M if possible)
Database:
sudo nano /etc/mysql/mysql.conf.d/mysqld.cnf
Tune innodb_buffer_pool_size to ~70% of available RAM for dedicated DB servers
Add Swap Space (Temporary Fix)
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/fstabSwap is not a replacement for adequate RAM — it prevents crashes but is slower.
Step 4 — Disk Optimization
Free Up Disk Space
# Find large files
du -sh /var/log/* | sort -h | tail -10Clear package cache
sudo apt clean # Ubuntu/Debian
sudo dnf clean all # CentOS/AlmaLinuxRotate and compress logs
sudo logrotate -f /etc/logrotate.confImprove Disk I/O
- Enable caching — Use Redis or Memcached for frequently accessed data.
- Optimize database queries — Reduce disk reads with proper indexing.
- Move to SSD — If on HDD storage, consider upgrading to an SSD-backed plan.
Step 5 — Web Server Optimization
Enable Gzip Compression (Nginx)
gzip on;
gzip_types text/plain text/css application/json application/javascript text/xml;
gzip_min_length 256;Enable Browser Caching (Nginx)
location ~* \.(jpg|jpeg|png|gif|ico|css|js|svg|woff2)$ {
expires 30d;
add_header Cache-Control "public, immutable";
}Enable PHP OPcache
sudo nano /etc/php/*/fpm/php.iniopcache.enable=1
opcache.memory_consumption=128
opcache.max_accelerated_files=10000
opcache.revalidate_freq=60Restart PHP-FPM:
sudo systemctl restart php*-fpmStep 6 — Application Optimization
- Enable application caching — Use Redis or Memcached for session storage and page caching.
- Optimize database queries — Add indexes, rewrite slow queries, use query caching.
- Optimize images — Compress images and serve appropriate sizes.
- Use a CDN — Offload static assets to a Content Delivery Network.
- Minimize HTTP requests — Combine CSS/JS files, use lazy loading.
When to Upgrade
If optimizations are not enough, consider upgrading your plan:
- CPU consistently above 80% after optimization.
- Available RAM consistently below 200 MB.
- Disk space above 85% after cleanup.
- Traffic growth exceeding current capacity.
What to Do Next
- Monitoring Server Performance — Track resource usage.
- How to Upgrade Your Server Plan — Scale up resources.
- Website Down — Quick Diagnosis — If performance leads to downtime.
- Complete Server Security Checklist — Ensure security is not causing overhead.