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

mstdmstd's avatar

I got composer memory lack error on my ubuntu 16

Hello, In my laravel 5 app I installed spatie/browsershot and after that got memory lack error on my ubuntu 16, under Digital Ocean

I rebooted OS and attached swap memory but memory lack error anyway:

# free
              total        used        free      shared  buff/cache   available
Mem:        1015908      175784      530992       25336      309132      662096
Swap:             0           0           0
root@ubuntu-boxBooking-Dev:~# sudo -s
root@ubuntu-boxBooking-Dev:~# sudo fallocate -l 1G /swapfile
root@ubuntu-boxBooking-Dev:~# sudo mkswap /swapfile
mkswap: /swapfile: warning: wiping old swap signature.
Setting up swapspace version 1, size = 1024 MiB (1073737728 bytes)
no label, UUID=76e8a9d1-2d9c-4a3b-a7af-cd152d03532c
root@ubuntu-boxBooking-Dev:~# sudo swapon /swapfile
swapon: /swapfile: insecure permissions 0644, 0600 suggested.
root@ubuntu-boxBooking-Dev:~# sudo swapon -a
root@ubuntu-boxBooking-Dev:~# free
              total        used        free      shared  buff/cache   available
Mem:        1015908      176972      528020       25336      310916      660980
Swap:       1048572           0     1048572
root@ubuntu-boxBooking-Dev:~# cd /var/www/html/the-box-booking
root@ubuntu-boxBooking-Dev:/var/www/html/the-box-booking# mc

root@ubuntu-boxBooking-Dev:/var/www/html/the-box-booking# composer install
Loading composer repositories with package information
Updating dependencies (including require-dev)

mmap() failed: [12] Cannot allocate memory
Killed
root@ubuntu-boxBooking-Dev:/var/www/html/the-box-booking# lsb_release -d; uname -r; uname -i
Description:    Ubuntu 16.04.4 LTS
4.4.0-184-generic
x86_64

 php -v
PHP 7.2.15-1+ubuntu16.04.1+deb.sury.org+1 (cli) (built: Feb  8 2019 15:37:29) ( NTS )
Copyright (c) 1997-2018 The PHP Group
Zend Engine v3.2.0, Copyright (c) 1998-2018 Zend Technologies
    with Zend OPcache v7.2.15-1+ubuntu16.04.1+deb.sury.org+1, Copyright (c) 1999-2018, by Zend Technologies

I do not have a lot of packages in my composer.json :

{
    "name": "laravel/laravel",
    "type": "project",
    "description": "The Laravel Framework.",
    "keywords": [
        "framework",
        "laravel"
    ],
    "license": "MIT",
    "require": {
        "php": "^7.1.3",
        "arrilot/laravel-widgets": "^3.13",
        "doctrine/dbal": "^2.9",
        "fideloper/proxy": "^4.0",
        "laravel/framework": "5.7.*",
        "laravel/tinker": "^1.0",
        "mews/purifier": "^2.1",
        "phpoffice/phpspreadsheet": "^1.6",
        "proengsoft/laravel-jsvalidation": ">2.2.0",
        "s-ichikawa/laravel-sendgrid-driver": "^2.0",
        "spatie/browsershot": "^3.37",
        "yajra/laravel-datatables-oracle": "~8.0"
    },
    "require-dev": {
        "beyondcode/laravel-dump-server": "^1.0",
        "filp/whoops": "^2.0",
        "fzaninotto/faker": "^1.4",
        "mockery/mockery": "^1.0",
        "nunomaduro/collision": "^2.0",
        "phpunit/phpunit": "^7.0"
    },
    "config": {
        "optimize-autoloader": true,
        "preferred-install": "dist",
        "sort-packages": true
    },
    "extra": {
        "laravel": {
            "dont-discover": []
        }
    },
    "autoload": {
        "psr-4": {
            "App\": "app/"
        },
        "classmap": [
            "database/seeds",
            "database/factories"
        ]
    },
    "autoload-dev": {
        "psr-4": {
            "Tests\": "tests/"
        }
    },
    "minimum-stability": "dev",
    "prefer-stable": true,
    "scripts": {
        "post-autoload-dump": [
            "Illuminate\Foundation\ComposerScripts::postAutoloadDump",
            "@php artisan package:discover --ansi"
        ],
        "post-root-package-install": [
            "@php -r \"file_exists('.env') || copy('.env.example', '.env');\""
        ],
        "post-create-project-cmd": [
            "@php artisan key:generate --ansi"
        ]
    }
}

I suppose that I need to increase memory of my ubuntu instance ( Digital Ocean ). I have a cheapest instance options, as the app has not a lot of data/load. How many of memory do I need? How better to increase options of my ubuntu instance ? I do not like to overpay for the memory I really do not need.

Thanks!

0 likes
4 replies
Tray2's avatar

Have you checked the settings in php.ini about memory because it's more likely that is to small then the memory on the OS.

mstdmstd's avatar

Thanks for the link! Added in /etc/fstab:

/swapfile none swap defaults 0 0

I found and modified php.ini

# php -i | grep php.ini
Configuration File (php.ini) Path => /etc/php/7.2/cli
Loaded Configuration File => /etc/php/7.2/cli/php.ini
root@ubuntu-boxBooking-Dev:/var/www/html/the-box-booking# sudo nano /etc/php/7.2/cli/php.ini

with options:

memory_limit = -1
max_execution_time = 3300
max_input_time = 240
post_max_size = 400M

Also I run

composer clear-cache

php -r "echo ini_get('memory_limit').PHP_EOL;"

root@ubuntu-boxBooking-Dev:/var/www/html/the-box-booking# php -r "echo ini_get('memory_limit').PHP_EOL;"
-1

but rebooting the system to apply my changes I stopped services supposedly I do not need :

sudo service apache2 stop
  service mysql stop

and check memory 1 more time :

# free
              total        used        free      shared  buff/cache   available
Mem:        1015908       37652      559028        3136      419228      822304
Swap:       1048572           0     1048572

and running composer I again get the memory lack error :

 composer install
The "kylekatarnls/update-helper" plugin was skipped because it requires a Plugin API version ("^1.1.0 || ^2.0.0") that does not match your Composer installation ("1.0.0"). You may need to run composer update with the "--no-plugins" option.
Loading composer repositories with package information
Updating dependencies (including require-dev)

mmap() failed: [12] Cannot allocate memory
Killed
...

Are there something else I can try ?

mstdmstd's avatar

My current options : 1 GB Memory / 25 GB Disk / SFO2 - Ubuntu 16.04.4 x64 ipv6: Enable now Private IP: No VPC Network Floating IP: Enable now

How do you think about these new options : https://prnt.sc/t666yq Will it be enough ? Will I overpay?

Also a question if there a way to return back to my original size ?

Please or to participate in this conversation.