Blog

  • How to Set Up Swap on a DigitalOcean Droplet for Improved WordPress Performance

    If you’re running a $6 DigitalOcean Droplet with just 1GB of RAM, you might experience performance issues—especially when hosting multiple WordPress websites. One effective way to enhance performance and prevent crashes due to low memory (OOM errors) is by setting up swap space.

    What is Swap?

    Swap acts as virtual memory, allowing your server to temporarily store inactive processes on the disk when RAM is fully utilized. While swap is slower than RAM, it helps keep your system stable under heavy workloads.

    Why Set Up Swap?

    ✅ Prevents server crashes due to insufficient RAM
    ✅ Improves WordPress and MySQL stability
    ✅ Helps with multi-tasking and background processes

    How to Set Up Swap (Automated Script)

    Instead of manually configuring swap, you can use the following Bash script to automatically set up a 2GB swap file on your DigitalOcean Droplet:

    #!/bin/bash
    
    # Set up a 2GB swap file on DigitalOcean Droplet
    
    # Check if swap already exists
    if swapon --show | grep -q swapfile; then
        echo "Swap already exists. Exiting."
        exit 0
    fi
    
    # Allocate 2GB swap space
    fallocate -l 2G /swapfile || dd if=/dev/zero of=/swapfile bs=1M count=2048
    
    # Set correct permissions
    chmod 600 /swapfile
    
    # Format swap file
    mkswap /swapfile
    
    # Enable swap
    swapon /swapfile
    
    # Make swap permanent
    if ! grep -q "/swapfile" /etc/fstab; then
        echo "/swapfile none swap sw 0 0" >> /etc/fstab
    fi
    
    # Optimize swap settings
    sysctl vm.swappiness=10
    sysctl vm.vfs_cache_pressure=50
    
    echo "vm.swappiness=10" >> /etc/sysctl.conf
    echo "vm.vfs_cache_pressure=50" >> /etc/sysctl.conf
    
    # Verify swap is active
    swapon --show
    free -h
    
    echo "Swap setup complete!"
    
  • Hello world!

    Welcome to WordPress. This is your first post. Edit or delete it, then start writing!