How to Enable Swap on Ubuntu 14.04 and 15.10
Have you encountered this error before "error establishing a database connection" your vps hosted wordpress then you need to create a swap file. a swap file basically helps create more ram in order to run applications smoothly. This simple tutorial will help you create a swap file in linux ubuntu after install.
Check System Swap – Before you start to work on it make sure that system has already swap enabled. If there are no swap, you will get output header only. like this
$ sudo swapon -s
Create Swap File – Lets create a file to use for swap in system of required size. Before making file make sure you have enough free space on disk. Generally its recommends that swap should be equal to double of installed physical memory.I have 2GB memory in my system. So I am creating swap of 4GB in size.
$ sudo swapon -s
Create Swap File – Lets create a file to use for swap in system of required size. Before making file make sure you have enough free space on disk. Generally its recommends that swap should be equal to double of installed physical memory.I have 2GB memory in my system. So I am creating swap of 4GB in size.
$ sudo fallocate -l 4G /swapfile
$ chmod 600 /swapfile
Make It Swap – Now make is swap usable file using mkswap command.
$ sudo mkswap /swapfile
Enable Swap – Now setup the swap for system using swapon command.
$ sudo swapon /swapfile
Now again check that swap is enabled or not. You will see results something like below.
$ sudo swapon -s
Filename Type Size Used Priority
/swapfile file 4194300 0 -1
Setup Swap Permanent – Append the following entry in /etc/fstab file to enable swap on system reboot.
Filename Type Size Used Priority
/swapfile file 4194300 0 -1
Setup Swap Permanent – Append the following entry in /etc/fstab file to enable swap on system reboot.
# vim /etc/fstab
/swapfile none swap sw 0 0
Setup Kernel Parameter – Now change the swappiness kernel parameter as per your requirement. It tells the system how often system utilize this swap area.Edit /etc/sysctl.conf file and append following configuration in file.
/swapfile none swap sw 0 0
Setup Kernel Parameter – Now change the swappiness kernel parameter as per your requirement. It tells the system how often system utilize this swap area.Edit /etc/sysctl.conf file and append following configuration in file.
$ sudo vim /etc/sysctl.conf
vm.swappiness=10
vm.swappiness=10
Now reload the sysctl configuration file
$ sudo sysctl -p
if you successfully reach this point you have successfully enabled swap on your Ubuntu system.
if you successfully reach this point you have successfully enabled swap on your Ubuntu system.
No comments: