'Laravel Fatal Error memory but memory_limit set to 2048MB [closed]

I have just set up a new Laravel 8 project. When i try and run it i get the following fatal error:

PHP Fatal error:  Allowed memory size of 2097152 bytes exhausted (tried to allocate 32768 bytes) in /media/cal/500GB/cal/backend/vendor/composer/autoload_static.php on line 2297

PHP memory_limit is set to 2048MB

if I try and run any command related to Laravel or Composer I get a fatal error so this command

laravel --version

gives me this error:

PHP Fatal error:  Allowed memory size of 2097152 bytes exhausted (tried to allocate 12288 bytes) in /home/cal/.config/composer/vendor/symfony/console/Color.php on line 165

Even just typing composer give me the memory_error.

This command shows I have 2048MB memory_limit

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

Where does composer get that value of just 2MB from?

How can I fix this please? Any help is greatly appreciated.



Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source