So you want to host your website in RAM? It will certainly help if you a database or very large flat files and I recently decided our sqlite database and the tons of images we have should probably be hosted in RAM since I certainly have plenty of it (24GB’s).
On linux, you can use pretty much one command to do this by using tmpfs which will manage the memory usage for you based on what files you decide to put in ram.
After making the directory you want to mount in and setting perms on it, run:
mount -t tmpfs -o size=1024M tmpfs /mnt/ramdisk
The above will create a ramdisk using 1GB of your ram. If you for some reason don’t have 1GB available, swap space will start being used (gross!)
NOTE: This is temporary and if you UNMOUNT or REBOOT you will LOOSE all the data stored in this ramdisk.
I suggest having a cronjob that runs an rsync command to copy everything in the ramdisk to a directory on the hard drive every so often (depending on how often you modify your web site or whatever you host in ram)
#!/bin/bash if [ -d /mnt/ram/dir ]; then rsync -a –progress –stats –delete -l -z -v -r -p /mnt/ram/* /rambackup fi
The above will check that a dir I have put in the ramdisk is there before preceeding to backup everything in ram to /rambackup
I would do this in the event that the ramdisk did get unmounted for some reason and since you wouldn’t want your backup to get erased.