This is part of my complete guide to Setting up a CentOS Digital Ocean droplet with Nginx for beginners.
If you just need the commands, here they are. Read on for an explanation of what is happening.
sudo fallocate -l 1G /swapfile sudo chmod 600 /swapfile sudo mkswap /swapfile sudo swapon /swapfile sudo sh -c 'echo "/swapfile none swap sw 0 0" >> /etc/fstab'
I am not going to bother repeating the excellent explanation of these commands from their source guide. If you are interested, check it out.