Read this post if you need to fix the “Apache unable to fork new process – Cannot allocate memory” error.
How to find the error
The error is available in the Apache error log on your Linux platform.
You can find the error in the Apache log at:
- For Debian/Ubuntu: /var/log/apache2/error.log.
- For CentOS/RHEL: /var/log/httpd/error_log.
- Apache unable to fork new process – Cannot allocate memory.
Error log example:
[Fri Apr 12 17:11:04.375181 2019] [core:notice] [pid 18370:tid 140067138411456] AH00094: Command line: '/usr/sbin/apache2' [Fri Apr 12 17:11:04.399018 2019] [mpm_event:error] pid 18370:tid 140067138411456 Cannot allocate memory: AH00481: fork: Unable to fork new process [Fri Apr 12 17:12:03.250007 2019] [mpm_event:notice] [pid 18370:tid 140067138411456] AH00493: SIGUSR1 received. Doing graceful restart [Fri Apr 12 17:12:03.667322 2019] [:emerg] [pid 18370:tid 140067138411456] AH00020: Configuration Failed, exiting
What are the possible cause(s)
The following cause(s) have been identified:
- There is not enough free memory on the server to serve new MPM event processes.
Analysing the cause(s)
Here is sample output from htop when running the ‘htop’ command:
Likewise, here is the sample output when running the ‘free -m’ command:
ubuntu@server:~$ free -m total used free shared buff/cache available Mem: 1991 987 223 36 779 791 Swap: 0 0 0
The analysis via htop shows that Apache is consuming much of the memory. Free indicates that the server only has 791 Mb available. This server seems to be enough memory available but could be a problem when the server get’s busy. (Note: If you cannot see the “available” column, look at the total memory for free + buff/cache.) Do not rely on the results of the used and free columns! Read ‘Linux ate my RAM‘ for more info on this topic.
Free also indicates that the server has no swap file. The swap file provides an additional buffer in case the memory is fully utilized. The server will not permit new fork() operations if it does not have enough memory (in the cache or RAM).
Solution(s) for this issue
Solve this error using one of the following solution(s):
- Increase the available memory of the server. Make sure you are using the correct instance type if you are using AWS.
- Restart Apache and identify memory hogging processes.
- Configure a swap file that is suited to your platform. See this post by AWS showing you how to set a page file on an EC2 instance. Use the “Create Swap Bash Script” to determine the correct swap size and create it on your Linux platform.
- Adjust the MaxRequestWorkers and ServerLimit configuration of Apache. Read this post for more information: Apache Performance Tuning: MPM Directives.
What solution did you find for the “Apache unable to fork new process – cannot allocate memory” error? Post your solution at http://anto.online!
You may also be interested in
About the Authors
Anto's editorial team loves the cloud as much as you! Each member of Anto's editorial team is a Cloud expert in their own right. Anto Online takes great pride in helping fellow Cloud enthusiasts. Let us know if you have an excellent idea for the next topic! Contact Anto Online if you want to contribute.
Support the Cause
Support Anto Online and buy us a coffee. Anything is possible with coffee and code.