The "PHP Fatal error: Allowed memory size of X bytes exhausted" error in Drush indicates that a PHP process initiated by Drush has exceeded the allocated memory limit.
This can occur during various operations, such as clearing caches, running updates, or importing content, especially on sites with numerous modules, complex data, or demanding administrative tasks.
There's two solutions to bypass this issue; increase the php memory limit in the php configuration file or set the memory limit as parameter when executing the php drush command.
Increase PHP Memory Limit via the php configuration file.
First you have to locate the php.ini file loaded in the console. You use the article to locate the php configuration file: How to know which ini configuration files are loaded with PHP.
Then find the directive memory_limit and increase its value (e.g., memory_limit = 256M or 512M).
Set the memory limit as parameter when executing Drush
For a single Drush command, you can prefix it with
php -d memory_limit=256M vendor/bin/drush.php In this cas you should the drush.php and not the binary drush.
.