How to fix the «Allowed memory size exhausted» / «Out of memory / Bad gateway» failure in Magento/Framework/ObjectManager/Relations/Runtime.php?

The problem is caused by a lack of memory for the Oyejorge Less compiler (which is used by Magento 2) or for other Magento 2 components.

The memory is limited by the .htaccess and the .user.ini files used by Magento 2.

###How to fix the problem

Increase the memory limit (e.g., up to 2048M) in the following places:

1. .user.ini

2. .htaccess (2 places)

3.pub/.user.ini

4. pub/.htaccess (2 places)