Ubuntu Zero to Hero Ubuntu Zero to Hero | Page 16

Server Performance Swap file Now that you have your security looking good, I'll show you how to configure your server for more consistent performance. I find that the best way to do this is through a swap file. Essentially, a swap file is a dedicated portion of your hard drive, which is used as an extension of your RAM - helping to alleviate any memory constraints you might have. This is particularly useful for php websites with high load (e.g. a popular Wordpress website). In order to set up your swap file, take a look below. 1.Check whether you already have a swap file by typing 'free -m' into the terminal 2.The swap file can be created with the following command (this command may take a few seconds to run). This essentially builds a file of the specified size (in this case 2GB): 'sudo dd if=/dev/zero of=/swapfile bs=1G count=2' 3.Let's check that the space has been allocated by using: 'ls -lh /swapfil' Now we have our swap file created, we just need to enable it. 1.Adjust permissions by typing 'sudo chmod 600 /swapfile' 2.Verify the output with 'ls -lh /swapfile' 3.Set up the swap space with 'sudo mkswap /swapfile' 4.Enable the file 'sudo swapon /swapfile' 5.Verify that the process was successful 'sudo swapon -s' When we reboot, the file will not automatically be enabled. To make that happen, edit the file 'sudo nano /etc/fstab' and add '/swapfile none swap sw 0 0' at the bottom of the file. Cloudflare Further to setting up a swap file, you can enable better website performance through the use of a content delivery network (CDN) like Cloudflare. This tool enables you to cache your entire website (meaning it loads faster for visitors) and also let's you asynchronously load your javascript and css files – leading to much shorter load times. The Cloudflare servers are positioned in strategic locations across the globe. That means that no matter where in the world your customers are, they'll be routed to the closest possible server, reducing latency and improving response times. In addition to the performance improvements, Cloudflare also has many security features which could help you protect from brute force attacks. www.netshock.co.uk