Facing the following error when running any PHP scripts ?

PHP Fatal error: Out of memory (allocated xxxxx, tried to allocate xxxx bytes)

Tried increasing the memory limit from php.ini file and still getting the above error ?

Initially, we might think this issue is with the memory limit factor
seen in php.ini file. But if we analyze the error we get we can see that the issue is not directly related with the PHP configuration settings.

Usually, when a PHP script does not have enough memory to execute itself, the error message seen would indicate the amount of memory exhausted, something like :

=========
Fatal error: Allowed memory size of xxxx bytes exhausted (tried to allocate xxxxxx bytes)
=========

When we analyse things further, we can see that the real issue lies within the Apache configuration. Apache have memory limits of its own set in the configuration files. This value is referred to as ‘RLimitMEM’

Explanation of RLimitMEM from the official documentation of Apache :

RLimitMEM Directive

It sets the soft resource limit for all processes and the second parameter sets the maximum resource limit. It indicate to the server that the limit should be set to the maximum allowed by the operating system configuration. Raising the maximum resource limit requires that the server is running as root, or in the initial startup phase.

This applies to processes forked off from Apache children servicing requests, not the Apache children themselves. This includes CGI scripts and SSI exec commands, but not any processes forked off from the Apache parent such as piped logs. Memory resource limits are expressed in bytes per process.

-> So, increase this value/limit from your httpd configuration file, to get around the issue.