How do I create a swap on my cloud server that has no swap

Most of the cloud service provider disable swap on their systems to better isolate resources at the server level. There is a way around this, you can create your own swap file and configure the system to use the file. This has a bit more overhead than a swap partition so use it wisely.

Create a 1GB file: dd if=/dev/zero of=/swapfile bs=1M count=1024 (Note: be careful when using dd as you can wipe out valuable data very quickly)
Prepare the file: mkswap /swapfile
Make the swap file only usable by root: chmod 600 /swapfile
Enable swap using the new file: swapon /swapfile
Make the swap persistent: to /etc/fstab, append the following line; /swapfile none swap sw 0 0