You develop your PHP application on your local machine and everything works perfectly. Then you want to release for the public use. You purchase a VPS then install related services, start a web server, git pull your code into, finally run composer update…and whoops an error of memory is printed out your console.
This is because your VPS is too small or by any certain reasons that your VPS swap memory is out. There is 2 ways to tackle this issue.
- Upgrade your VPS or purchase a new one that have enough RAM for swap.
- Hack your swap memory inside your old VPS with no bucks cost.
The second options may sound more sense right, let’s do it. It’s easy 🙂
The following will help you to hack on your VPS swap memory
1. Initialize your swap.1 file with size of 1Gb root@ip-xxx-xx-6-164:/# sudo /bin/dd if=/dev/zero of=/var/swap.1 bs=1M count=1024
You will see the result
1024+0 records in
1024+0 records out
1073741824 bytes (1.1 GB) copied, 13.6493 s, 78.7 MB/s
2. Make your swap on swap.1 file root@ip-xxx-xx-6-164:/# sudo /sbin/mkswap /var/swap.1
You will see the result
Setting up swapspace version 1, size = 1048572 KiB
no label, UUID=be28fbf5-51ce-49bd-b46d-6b45770a6624
3. Activate your swap root@ip-xxx-xx-6-164:/# sudo /sbin/swapon /var/swap.1
That’s all. Run your compose update again.