Apache unable to fork new process – Cannot allocate memory

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.

Error message:

  • 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)

First, analyze the available memory on the server by using ‘htop‘ and ‘free‘.

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.

Wrapping up

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.

Buy me a coffee

About Anto Online

Having started his career in 1999 as a Desktop Support Engineer, Anto soon changed paths and became a developer. After several years of development experience, he transitioned into a consultant. As an enterprise application consultant for a leading SaaS software provider, Anto specializes in AWS's serverless technologies. By day, Anto focuses on helping customers leverage the power of serverless technologies. By night, he indulges his passion for cloud computing by playing with Python and trying out things that are currently beyond the scope of his work. Sometimes Anto needs help as there are not enough hours at night. So Anto relies on a team of fellow Cloud enthusiasts to help him out. Each one is a Cloud expert in their own right, and Anto takes great pride in helping them learn and grow.

View all posts by Anto Online →

Leave a Reply

Your email address will not be published.