Thought this was worth to share here in these times of financial depression. A lot of applications today needs a lot of RAM but RAM isn't cheap, so here's how you can add a SWAP file and theoretically expand your servers memory without paying more.
sudo dd if=/dev/zero of=/root/swap.img bs=1024 count=1048576
sudo chmod 600 /root/swap.img
sudo mkswap /root/swap.img
sudo swapon /root/swap.img
So basically, this will create a 1GB file named: /root/swap.img
, set appropriate permissions (only root can read and write), convert it to a swap space and then turn it on. To preserve this space after reboot, use a cron job:
# sudo crontab -e
@reboot sudo swapon /root/swap.img