Roots Discourse

Can't use WP-CLI due to php memory limit

In my dev environment, I try to use the trellis built-in variable wp_cli_packages to provision my site with and additional wp-cli package, but I get this error :

Fatal error: Allowed memory size of 134217728 bytes exhausted (tried to allocate 2621440 bytes) in 
phar:///usr/bin/wp/vendor/composer/composer/src/Composer/Json/JsonFile.php on line 275

I tried increasing the php_memory_limit to 512M, but I still get the same error.
In wordpress backend I can see the php limit has been increased, but if I vagrant ssh in my dev environment and type :

php --info | grep memory_limit

I get :

memory_limit => 128M => 128M

which seems to be the cause of the issue.

If I try to install the package with :
php -d memory_limit=512M "$(which wp)" package install

It works. But this is not an acceptable solution for me as I want to automate this wp-cli package install.

This is what the top of my groups_var/all/main.yml file looks like :

php_memory_limit: 512M

composer_keep_updated: true

apt_cache_valid_time: 3600

apt_package_state: present

apt_security_package_state: latest

apt_dev_package_state: latest

ntp_timezone: Europe/Paris

ntp_manage_config: true

www_root: /srv/www

theme: example-theme

wp_cli_packages: [""]

What am I missing here ?

EDIT: I did reprovision the VM with vagrant provisison and vagrant reload --provision

Have you reprovisioned the Vagrant VM after changing the memory config?

1 Like

Yes, I did run vagrant provision.

SSH into the vagrant box (vagrant ssh) and inspect the PHP configuration files. Has the memory limit changed, notably in the PHP CLI configuration file?

/etc/php/7.4/fpm/php.ini :

memory_limit = 512M

/etc/php/7.4/cli/php.ini :

;Ansible managed

error_reporting = E_ALL
sendmail_path = /opt/mailhog/mhsendmail
expose_php = Off
date.timezone = Europe/Paris

mysqlnd.collect_memory_statistics = On

opcache.enable = 0
opcache.enable_cli = 1
opcache.memory_consumption = 128
opcache.interned_strings_buffer = 8
opcache.max_accelerated_files = 4000
opcache.revalidate_freq = 60
opcache.fast_shutdown = 1

Apparently the PHP CLI memory limit has to be set differently/explicitly, see this discussion

This topic was automatically closed after 42 days. New replies are no longer allowed.