Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.

mstdmstd's avatar

Out of memory error on server

Hello, On my remote server(ubuntu 16, PHP 7.2.7-1+ubuntu16.04.1+deb.sury.org+1 ) in laravel 5.5 project I got error:

# composer require doctrine/dbal
Using version ^2.8 for doctrine/dbal
./composer.json has been updated
Loading composer repositories with package information
Updating dependencies (including require-dev)

mmap() failed: [12] Cannot allocate memory

mmap() failed: [12] Cannot allocate memory
PHP Fatal error:  Out of memory (allocated 596647936) (tried to allocate 20480 bytes) in /usr/share/php/Composer/DependencyResolver/Rule.php on line 66

Fatal error: Out of memory (allocated 596647936) (tried to allocate 20480 bytes) in /usr/share/php/Composer/DependencyResolver/Rule.php on line 66

# df -h
Filesystem      Size  Used Avail Use% Mounted on
udev            487M     0  487M   0% /dev
tmpfs           100M   11M   89M  11% /run
/dev/vda1        25G  2.3G   22G  10% /
tmpfs           497M     0  497M   0% /dev/shm
tmpfs           5.0M     0  5.0M   0% /run/lock
tmpfs           497M     0  497M   0% /sys/fs/cgroup
/dev/vda15      105M  3.4M  101M   4% /boot/efi
tmpfs           100M     0  100M   0% /run/user/0

In my /etc/php/7.2/cli/php.ini:

;;;;;;;;;;;;;;;;;;;
; Resource Limits ;
;;;;;;;;;;;;;;;;;;;

; Maximum execution time of each script, in seconds
; http://php.net/max-execution-time
; Note: This directive is hardcoded to 0 for the CLI SAPI
max_execution_time = 3300

; Maximum amount of time each script may spend parsing request data. It's a good
; idea to limit this time on productions servers in order to eliminate unexpectedly
; long running scripts.
; Note: This directive is hardcoded to -1 for the CLI SAPI
; Default Value: -1 (Unlimited)
; Development Value: 60 (60 seconds)
; Production Value: 60 (60 seconds)
; http://php.net/max-input-time
max_input_time = 240

; Maximum input variable nesting level
; http://php.net/max-input-nesting-level
;max_input_nesting_level = 64

; How many GET/POST/COOKIE input variables may be accepted
; max_input_vars = 1000

; Maximum amount of memory a script may consume (128MB)
; http://php.net/memory-limit
memory_limit = 1024M

upload_max_filesize = 400M
post_max_size = 400M

I restarted apache server times.

What is wrong and how to fix the error?

Thanks!

0 likes
4 replies
click's avatar

what caused this error? When did it happen (what where you executing)? Do you have a stacktrace in your error log? (storage/logs/laravel.log)

Do you have an infinite loop that never ends and eats up memory?

lostdreamer_nl's avatar

So, trying to find a match for all the dependencies is taking more then the ~570MB you have allowed for php (or your server hosting).

Check the memory usage on the server with

free -m
mstdmstd's avatar

That is Ubuntu hosting(I created it a pair of weeks ago) under Digital Ocean:

root@ubuntu-boxBooking-Dev:/var/www/html/box-booking# lsb_release -d; uname -r; uname -i
Description:    Ubuntu 16.04.4 LTS
4.4.0-130-generic
x86_64

root@ubuntu-boxBooking-Dev:/var/www/html/box-booking# free -m
              total        used        free      shared  buff/cache   available
Mem:            992         325         562          35         104         518
Swap:             0           0           0

I had laravel 5.5 app installed. I pulled changes from git and had to install intervention/image :

# composer require intervention/image 

Using version ^2.4 for intervention/image
./composer.json has been updated
Loading composer repositories with package information
Updating dependencies (including require-dev)

mmap() failed: [12] Cannot allocate memory

mmap() failed: [12] Cannot allocate memory
PHP Fatal error:  Out of memory (allocated 586162176) (tried to allocate 20480 bytes) in /usr/share/php/Composer/DependencyResolver/Rule.php on line 66

Fatal error: Out of memory (allocated 586162176) (tried to allocate 20480 bytes) in /usr/share/php/Composer/DependencyResolver/Rule.php on line 66
root@ubuntu-boxBooking-Dev:/var/www/html/box-booking# 
root@ubuntu-boxBooking-Dev:/var/www/html/box-booking# lsb_release -d; uname -r; uname -i

Also I tried:

# composer update
Loading composer repositories with package information
Updating dependencies (including require-dev)
  - Removing doctrine/dbal (v2.6.3)
The following exception is caused by a lack of memory and not having swap configured
Check https://getcomposer.org/doc/articles/troubleshooting.md#proc-open-fork-failed-errors for details

I see

not having swap configured

error description above and 0 value in free command above. Is it issue and how to fix it?

Also installing Ubuntu hosting under Digital Ocean I did not notice any swap options...

Aslo can be rebooting of the system salve the problem? Usually I reboot the ubuntu(I use kubuntu 18 on my laptop) running under root:

reboot

Is it what I have to run in my case or other command preferable?

lostdreamer_nl's avatar
Level 53

As you can see:

              total        used        free      shared  buff/cache   available
Mem:            992         325         562          35         104         518
Swap:             0           0           0

You have to little RAM in this server (only 1 GB total), but composer usually needs around 1GB to be able to resolve all dependencies. You only have around 560MB free.

There are 3 things you can do:

  1. Setup your dev environment to match your server as close as possible (so vagrant + ubuntu + same php version + more memory) and do "composer update" locally, and "composer install" on the server, this way the server doesnt have to do the resolving, it just installs what your dev environment concluded to be the needed packages.
  2. Increase your server's RAM by upgrading to a higher package
  3. Add swap to your server so it can handle the overload of memory by using it's harddisk in those situations.

For #3 you can follow this tutorial to setup a 1GB swap space on your server:

https://www.digitalocean.com/community/tutorials/how-to-add-swap-space-on-ubuntu-16-04

1 like

Please or to participate in this conversation.