proc_open(): fork failed-can not allocate memory, error on aws ec2 instance while updating/installing some libraries or packages using composer

Introduction:
                    Firstly we have to understand why this error occurs? If we understand the problem then it  is very easy to solve the problem. While we create instances on a cloud platform, we notice lot of parameters to decrease the bill and as well as performance should remain fantastic. Actually if the instance produces no bill, it is tremendous for us. With considering these parameters, generally we create an instance with a very small amount of memory. When we configure our project, then lots of libraries/packages needed to configure the project. These libraries/packages take a bunch of memories. While there is not enough memories then the error "proc_open(): fork failed-can not allocate memory" arises.



Solution:
              If we allocate some memory from ssd or hdd that would be used as ram that is needed to install/update some libraries/packages. It may solve the problem. In ubuntu we call it as 'swap'. By adding swap space, we can solve the not allocating memory problem.

Adding swap space:

Step1: At the beginning we need to check if there is any configuring swap by running the command. If there is no result on the screen. it means that there is no configured swap space.
$ sudo swapon --show  
Step2: If you want to see your memory stats. You can run the command. you will see swap memory is 0B.
$ free -h

Step3: Observing all memory status to allocate swap
$ df -h

Step4: preparing a 1G size swap file in the root directory by using fallocate program by running the command.
$ sudo fallocate -l 1G /swapfile
Step5: confirming the reserved space by running the command
$ ls -lh /swapfile

Step6: making /swapfile accessible by the command

$ sudo chmod 600 /swapfile

Again run the step5 command to see the permission directory. it will make you confirm and satiated.


Step7: making the swapfile as swap space by the command
$ sudo mkswap /swapfile

Step8: enabling swapfile to utilize by the command
$ sudo swapon /swapfile
Step9: to see status of swap space by typing the command to see available swap space
$ sudo swapon --show

$ free -h

Step10: making the swapfile permanent. Our swapfile has been enabled to utilize. if we reboot/restart then it will flash/remove. To do permanent this we need to put the file into /etc/fstab directory by running the command
$ sudo cp /etc/fstab /etc/fstab.bak$ echo '/swapfile none swap sw 0 0' | sudo tee -a /etc/fstab
Step11: adjusting swappiness parameters. to see the swappiness value run the command
$ cat /proc/sys/vm/swappiness

to assign a value with swappiness run the command
$ sudo sysctl vm.swappiness=12

 to set the value permanently run the command
$ sudo nano /etc/sysctl.conf

and write the value below of the file as vm.swappiness=12 and press 'cltr + x' and 'shift + Y' and 'enter' button to save.

Step12: adjusting swappiness cache pressure by typing the command
$ cat /proc/sys/vm/vfs_cache_pressure

to change the value run the command
$ sudo sysctl vm.vfs_cache_pressure=55

to set the value permanently run the command
$ sudo nano /etc/sysctl.conf

and write the value below of the file as vm.vfs_cache_pressure=55 and press 'cltr + x' and 'shift + Y' and 'enter' button to save.

save and close the when finishing the edition. Now your swap file has been created.

And now run that command for what you saw the error

it may vanish.................wowwwww


Comments

Popular posts from this blog

composer installation on aws ec2 instance ami ubuntu 18.04

nginx installation on aws ec2 instance ami ubuntu 18.04

PHP7.3 installation on aws ec2 instance ami ubuntu 18.04