How to set the PHP script memory limit in an .htaccess file

June 4, 2024 / How-to Guide

In this article, we have explained how to set the PHP script memory limit in a .htaccess file. By default, a PHP script can allocate up to 128 megabytes of memory. You can modify this limit by changing the memory_limit directive in a .htaccess file.

This article assumes you have already set up a custom .htaccess file. If you have not, please read this article first : How to set up custom .htaccess files for PHP settings

To change the memory limit for PHP scripts, follow these steps-

  1. Log in to your account using SSH.
  2. Use a text editor to add the following line to the .htaccess file. Replace xxx with the new memory limit value you want to set, in megabytes-
    php_value memory_limit xxxM
  3. Save the changes to the .htaccess file and exit the text editor.
  4. To verify that the new setting is active, create a PHP test file with the following code in the same directory as the .htaccess file-
    <?php phpinfo(); ?>
  5. Load the test file in your web browser and search for the directive name. The Local Value column should display the new setting specified in the .htaccess file.

In this manner, you can set the PHP script memory limit in a .htaccess file. If you encounter any issues, feel free to contact our support staff. They are available 24X7.

Dominos Search