How To Enable Swap on aaPanel VPS (Low RAM Fix – 2026 Guide)
If your VPS:
❌ Freezes randomly
❌ Shows 502 / 500 errors under load
❌ Hits 100% memory usage
❌ Restarts automatically
And you’re using:
Your problem is likely no swap memory.
—
🧠 What Is Swap Memory?
Swap is virtual memory stored on disk.
When RAM is full:
✔ Linux moves inactive memory to swap
✔ Prevents sudden crashes
✔ Stabilizes small VPS
Without swap → 1GB VPS crashes instantly when memory fills.
—
🚨 Why 1GB VPS Needs Swap
Default VPS setups often have:
❌ No swap
❌ High PHP workers
❌ High MySQL buffers
Result:
RAM reaches 100% → Kernel kills services → Server crashes.
Swap acts as a safety buffer.
—
✅ Step-by-Step: Create 1GB Swap on aaPanel VPS
Works on Ubuntu / Debian / CentOS.
—
🟢 STEP 1: Check If Swap Already Exists
Run:
$$
free -m
$$
If Swap shows:
$$
0
$$
You need to create it.
—
🟢 STEP 2: Create Swap File (1GB Recommended)
Run:
$$
fallocate -l 1G /swapfile
$$
If fallocate not available:
$$
dd if=/dev/zero of=/swapfile bs=1M count=1024
$$
—
🟢 STEP 3: Set Correct Permissions
$$
chmod 600 /swapfile
$$
This secures swap file.
—
🟢 STEP 4: Format as Swap
$$
mkswap /swapfile
$$
—
🟢 STEP 5: Enable Swap
$$
swapon /swapfile
$$
Check again:
$$
free -m
$$
You should now see 1024MB swap.
—
🟢 STEP 6: Make Swap Permanent
Edit:
$$
nano /etc/fstab
$$
Add this line:
$$
/swapfile none swap sw 0 0
$$
Save and exit.
Now swap activates on reboot.
—
⚙ Optional: Optimize Swappiness (Recommended)
Swappiness controls how aggressively Linux uses swap.
Check current value:
$$
cat /proc/sys/vm/swappiness
$$
Set to 10 (recommended for VPS):
$$
sysctl vm.swappiness=10
$$
To make permanent:
Add to /etc/sysctl.conf:
$$
vm.swappiness=10
$$
Lower value = system prefers RAM first.
—
🔥 How Much Swap Should You Use?
| VPS RAM | Recommended Swap |
| 1GB | 1GB |
| 2GB | 1GB–2GB |
| 4GB+ | Optional |
Too much swap on SSD may reduce disk lifespan.
—
⚡ After Enabling Swap
You should notice:
✔ Fewer crashes
✔ More stability
✔ Lower service interruptions
✔ Reduced sudden 500 errors
But swap is NOT a performance boost — it’s a safety net.
—
🚀 Combine Swap With These Optimizations
For best results:
✔ Use Nginx instead of Apache
✔ Enable OPcache
✔ Install Redis
✔ Reduce PHP-FPM workers
✔ Optimize MariaDB
✔ Use Cloudflare for traffic offload
—
🧠 How To Monitor Memory
Run:
$$
htop
$$
Healthy 1GB VPS should stay:
✔ RAM usage below 80%
✔ Swap usage minimal under normal load
If swap constantly high → upgrade VPS.
—
Web Development #aaPanel #SwapMemory #LowRAM #VPSOptimization #ServerFix #LinuxServer #Cloudflare