4

I have a Laravel project working on docker. When I want to add a package with "composer require" this error occurs:

Fatal error: Allowed memory size of 1610612736 bytes exhausted (tried to allocate 83886080 bytes) in phar:///usr/bin/composer/src/Composer/DependencyResolver/RuleSet.php on line 90

I have changed the memory_limit in php.ini to "-1". The same error continues.

I have tried this command. Updates the composer.json file but then gets killed everytime.

php -d memory_limit=-1 /usr/bin/composer require waavi/sanitizer ~1.0

I have tried "composer update" same error about memory limit.

Fatal error: Allowed memory size of 1610612736 bytes exhausted (tried to allocate 8192 bytes) in phar:///usr/bin/composer/src/Composer/DependencyResolver/GenericRule.php on line 36

composer.json file;

{
    "name": "laravel/laravel",
    "type": "project",
    "description": "The Laravel Framework.",
    "keywords": [
        "framework",
        "laravel"
    ],
    "license": "MIT",
    "require": {
        "php": "^7.3|^8.0",
        "aws/aws-sdk-php-laravel": "^3.1",
        "fideloper/proxy": "^4.4",
        "fruitcake/laravel-cors": "^2.0",
        "graham-campbell/flysystem": "^3.0",
        "guzzlehttp/guzzle": "^7.2",
        "laravel/framework": "^8.12",
        "laravel/passport": "^10.1",
        "laravel/tinker": "^2.5",
        "laravel/ui": "^3.2",
        "league/flysystem-aws-s3-v3": "1.0.29",
        "predis/predis": "^1.1",
        "spatie/laravel-activitylog": "^3.16",
        "spatie/laravel-permission": "^3.18",
        "waavi/sanitizer": "~1.0",
        "yajra/laravel-datatables-oracle": "~9.0"
    },
    "require-dev": {
        "beyondcode/laravel-dump-server": "^1.0",
        "facade/ignition": "^2.5",
        "fakerphp/faker": "^1.9.1",
        "filp/whoops": "^2.0",
        "jason-guru/laravel-make-repository": "^0.0.3",
        "mockery/mockery": "^1.4.2",
        "nunomaduro/collision": "^5.0",
        "phpunit/phpunit": "^9.3.3"
    },
    "config": {
        "optimize-autoloader": true,
        "preferred-install": "dist",
        "sort-packages": true
    },
    "extra": {
        "laravel": {
            "dont-discover": []
        }
    },
    "autoload": {
        "psr-4": {
            "App\\": "app/",
            "Database\\Factories\\": "database/factories/",
            "Database\\Seeders\\": "database/seeders/"
        },
        "files": [
            "app/Helpers/Helpers.php"
        ]
    },
    "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'm using MacOS and Docker.

I've tried to composer clear-cache and composer install command.

2 Answers 2

2

In docker-compose.yml

php:
    container_name: php-server
    build: ./php/
    volumes:
      - ./..:/var/www
      - ./php/ini:/usr/local/etc/php // note that this line maps docker's /usr/local/etc/php

At your php Dockerfile directory under ini/conf.d/ create a file named memory_limit.ini So your directory will be .../php/ini/conf.d/memory_limit.ini Inside memory_limit.ini

memory_limit = -1
Sign up to request clarification or add additional context in comments.

Comments

0

My solution looks like the solution of Morteza Pouretemadi. But with some edits, because the original does not work for me.

My php image parsed additional .ini files. Something like this:

Additional .ini files parsed:
/usr/local/etc/php/conf.d/docker-php-ext-mcrypt.ini, /usr/local/etc/php/conf.d/docker-php-ext-mysqli.ini, /usr/local/etc/php/conf.d/docker-php-ext-pdo_mysql.ini, /usr/local/etc/php/conf.d/docker-php-ext-redis.ini, /usr/local/etc/php/conf.d/docker-php-ext-sodium.ini, /usr/local/etc/php/conf.d/docker-php-ext-zip.ini,

So, I've just created memory_limit.ini file in my project directory with settings for the memory_limit param. And link the file (not a folder!) in the docker-compose.

php-apache-environment:
    container_name: php-apache
    build:
        context: .
    volumes:
      - ./public:/var/www/html/
      - ./:/var/www/
      - ./php/ini/memory_limit.ini:/usr/local/etc/php/conf.d/memory_limit.ini

Maybe it will help someone.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.