Memory Leak , use minimum cost for droplet , Let’s create swap file.

I use wordpress, nginx, mysql, php-fpm with minimun cost on DigitalOcean and found the memory leak problem. This cause MySQL stop working and my websit goes down.

I also found there are lots child processes of php-fpm. I thought I should consider to increase the memory (use 1 GB) or not. Anyway I don’t want to spent my money for my website as I’m person to check it out only one HaHa if you came across to read this. You are second.

These are I did for fix the memory issue.

Create swap file https://www.digitalocean.com/community/tutorials/how-to-add-swap-on-centos-7 I create 2GB swapfile because my memory has 1 GB . If you have memory more than 1 GB , you should multiply 1.5 of physical memory.

//Check Swap usage
swapon -s
//if no return message, it mean no swap 

//create swap file
sudo dd if=/dev/zero of=/swapfile count=2096 bs=1MiB

//change permission read write only
sudo chmod 600 /swapfile

//make a swapfile
mkswap /swapfile

//enable swap 
swapon /swapfile

//Check Swap usage again
swapon -s
//should return swap size
[root@ake warawich.com]# swapon -s
Filename Type Size Used Priority
/swapfile file 2097148 264 -2

Make the Swap File Permanent

vi /etc/fstab

/swapfile   swap    swap    sw  0   0

Then reboot OS

Now, you have memory more but the root cause is php-fpm create lots of child process and consume your memory , so you need to limit php-fpm create child process too.

vim /etc/php-fpm.d/www.conf

//change configure as below
pm = ondemand
pm.max_children = 20
pm.start_servers = 5
pm.process_idle_timeout = 10s
pm.max_requests = 100

save and restart php-fpm service

systemctl restart php-fpm 
//check memory free
root@ake warawich.com]# free -m
total used free shared buff/cache available
Mem: 990 544 111 12 335 294
Swap: 2047 0 2047

All of these what i did! Please suguest me if what you think or what I miss. Thank you.

One Reply to “Memory Leak , use minimum cost for droplet , Let’s create swap file.”

Leave a Reply

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