How to add Swap Memory on cPanel Server?
First of all, need to disable swap so the usage of swap move to main memory.
Before running this command, make it sure that your mem free space is larger that
the swap by using free -m command. If free showing larger than Swap used, then rung this command:
This will take some time, once command prompt free, check if swap available?
You will see 0 swap memory, now use this command to create swap file: (I am creating 8 GB swap, so you can change it as per your need)
dd if=/dev/zero of=/swapfile bs=1G count=8
Now apply the correct permission to this file with this command:
chmod 0600 /swapfile
Now need to set this file as swap, so run this command:
Now we need to enable Swap again, this command will be used:
Now check if swap is in use? run this:
You will see that your created swap memory is in use.
To make this work on reboot, add this in fstab:
at the end of the file, add these lines: (press i to enable editing)
/swapfile swap swap sw 0 0