Maaz Zindani

Loading the index…

↑↓ move↵ openesc close4072 pages
Node.js, PHP and APIs

Composer stops with 'fork failed - Cannot allocate memory' on a small server

Errorproc_open(): fork failed - Cannot allocate memory

Short answer

This error means the operating system refused to start a child process because the server is out of memory, not because PHP's memory_limit is too low. Check free -m. If Swap is 0, add a swap file. Also run Composer 2, which uses far less memory than Composer 1.

  • Applies to Composer 2.8, PHP 8.3, Ubuntu 24.04
  • Updated
  • By Maaz Zindani, Senior Software Engineer

Fix it fast

  1. 1Find out which cause you have

    Look at total memory and the Swap line. A Swap total of 0 on a small VPS is the classic setup for this error.

    free -m
  2. 2Match what you see, then jump to its fix

    1. 1free -m shows Swap: 0 and little free memoryThe server has no swap spaceFix
    2. 2composer --version prints 1.xAn old Composer 1 is installedFix
    3. 3The error appears even though free memory looks fine, on a cPanel hostShell fork bomb protection on shared hosting (cPanel)Fix

What does the error look like?

  • proc_open(): fork failed - Cannot allocate memory
  • PHP Fatal error: Uncaught exception 'ErrorException' with message 'proc_open(): fork failed - Cannot allocate memory'

Cause 1 of 3

The server has no swap space

1Check

Composer's own troubleshooting guide says this error usually means the VPS ran out of memory and has no swap.

free -m

2Fix

Create a swap file and switch it on. These are the commands from the Composer guide (1 GB).

sudo dd if=/dev/zero of=/var/swap.1 bs=1M count=1024
sudo mkswap /var/swap.1
sudo chmod 0600 /var/swap.1
sudo swapon /var/swap.1

3Verify

Swap now shows a total, and Composer finishes.

free -m
composer update

Confirmed by getcomposer.org

Did this fix it?

Cause 2 of 3

An old Composer 1 is installed

1Check

Composer 1 used much more memory than Composer 2. The troubleshooting guide asks you to use Composer 2, ideally 2.2.0 or later.

composer --version

2Fix

Update Composer to the current 2.x release.

sudo composer self-update --2

3Verify

The version is 2.x and the same command runs.

composer --version

Confirmed by getcomposer.org

Did this fix it?

Cause 3 of 3

Shell fork bomb protection on shared hosting (cPanel)

1Check

The Composer guide lists cPanel's Shell Fork Bomb Protection as a trigger for memory-style failures. Look for it in the account's shell settings.

# cPanel / WHM: Security Center > Shell Fork Bomb Protection

2Fix

Ask the host to relax the shell limit for your account, or run Composer on your own machine or in CI and upload the vendor folder.

composer install --no-dev --optimize-autoloader

3Verify

Run the install again over SSH.

composer install

Confirmed by getcomposer.org

Did this fix it?

How do I stop it coming back?

  • Give every VPS with 1 GB of RAM or less a swap file before the first deploy.
  • Build vendor in CI or on a build machine and ship it, instead of running Composer on a tiny production server.
  • Keep Composer itself up to date.

Sources

How was this page made?

I drafted this page with AI assistance from the official documents listed under Sources. Every cause above names the document that confirms it. I have not reproduced this fix on a machine of my own yet, so read it as documented guidance, not a test report. Found a mistake? Tell me.

Which stack is behind this page?

Projects of mine built on the same technologies:

Related fixes

Back end

composer require dies with 'Allowed memory size exhausted'

PHP Fatal error: Uncaught exception 'ErrorException' with message 'proc_open(): fork failed - Cannot allocate memory'

Composer already lifts PHP's memory_limit to 1.5G on its own, so hitting this error means the job needs more than that, or the machine itself has too little memory.

4 causes, each with a fix

Back end

CodeIgniter 4 cannot write its cache files

CodeIgniter\Cache\Exceptions\CacheException: Cache unable to write to /var/www/app/writable/cache/

CodeIgniter 4's file cache needs a cache directory that the web server can really write to.

2 causes, each with a fix

Back end

CodeIgniter 3 loads the model but the property is undefined

The model name you are loading is the name of a resource that is already being used: user

CodeIgniter 3 expects a model file named like its class, with the first letter capitalised, for example User_model.php holding class User_model.

2 causes, each with a fix

Next step

Want this handled for good?

I look after servers, apps and releases end to end. Tell me what keeps breaking.