Setting up RamDisk on WebCP

We all know that one of the ranking factors in SEO these days is site speed. When you use WebCP Web hosting control panel on your Ubuntu server you’re already getting out of the box web server optimisation with features like Nginx web server, pagespeed module, brotli compression, etc.

You may still want to cache your dynamic content for faster access on subsequent visits. If you’re hosting a WordPress site then you’ll likely use a plugin for the caching. If you use an SSD with Nvme then a disk cache will be pretty fast already. However, you may want to get even more speed by caching to RAM.

If you have SSH root access to the server follow these steps to set up RAMdisk. This will allow you to mount a folder directly in RAM.

Going back to our WordPress example, WordPress caches are usually stored in wp-content/cache. So, if we are able to turn that cache directory into a RAM based folder then our plugins would work unaltered, but our cache would in fact be stored in memory which makes it super fast.

Making the RamDisk

Making the Ramdisk is pretty easy and takes only three commands!

We’ll assume that we’re working on a WordPress site and so we’re turning wp-content/cache into a ram disk.

Decide how much RAM you want to use. That will depend on how much RAM you have available. In a terminal, go to your wp-content directory and type:

du -chs ./cache

That will tell you how much data is currently in your cache directory. If you have enough RAM to spare then make it larger than this. I’m going to use 100Mb for my cache directory.

Next, mount the directory as a tmpfs like this:

sudo mount -t tmpfs -o size=100M tmpfs /home/webcp/public_html/wp-content/cache

At this stage we’ve mounted our cache directory TEMPORARILY. If you reboot your server then it goes back to being a plain old disk based folder.

To make the ramdisk persists across reboots you can run the following command:

  sudo grep /home/webcp/public_html/wp-content/cache /etc/mtab | sudo tee -a /etc/fstab

In both cases above, please substitute the correct values in place of the red text!

 

Leave a Reply

Your email address will not be published. Required fields are marked *