Skip to content

Changing the PHP Memory Limit for Scripts

The memory_limit directive in PHP controls the maximum amount of memory a script can allocate. By default, this value is set to 128 MB. On ruachost.com, you can increase or decrease this limit depending on your application’s requirements.

  • Prevents “Allowed memory size exhausted” errors when running large scripts.
  • Supports applications that process big files, images, or complex database queries.
  • Helps optimize performance by balancing memory usage and server stability.

Create or edit a php.ini file in your application directory:

memory_limit = 256M

This sets the maximum memory allocation to 256 MB.

If your hosting environment supports .user.ini, add:

memory_limit = 256M

On Apache servers, you can override the directive:

php_value memory_limit 256M
  1. Log in to cPanel.
  2. Go to Software → Select PHP Version → Options tab.
  3. Locate memory_limit.
  4. Set the desired value (e.g., 256M, 512M).
  5. Save changes.
  • Increase gradually (e.g., 256M → 512M) instead of setting excessively high values.
  • Avoid setting unlimited memory (-1) unless absolutely necessary, as it can destabilize the server.
  • Monitor application performance after changes to ensure stability.