Skip to content

Setting the PHP maximum execution time in .htaccess

The max_execution_time directive in PHP defines how long a script is allowed to run before it is terminated. By default, this value is set to 30 seconds. On ruachost.com, you can override this limit using a custom .htaccess file when you don’t have direct access to php.ini.

  • Prevents scripts from timing out during long operations (e.g., large imports, backups, or heavy queries).

  • Provides flexibility for applications that require extended processing time.

  • Helps avoid errors such as:

    Fatal error: Maximum execution time of 30 seconds exceeded

Steps to Set max_execution_time in .htaccess

Section titled “Steps to Set max_execution_time in .htaccess”
  • Log in to cPanel or use FTP/File Manager.
  • Navigate to your site’s root directory (e.g., /public_html).
  1. If .htaccess already exists, open it for editing.
  2. If not, create a new file named .htaccess.

Insert the following line:

php_value max_execution_time 120
  • Replace 120 with the desired number of seconds (e.g., 60, 300).
  • Setting 0 allows unlimited execution time, but this is not recommended for shared hosting environments.
  1. Save the .htaccess file.

  2. Create a test file info.php with:

    <?php phpinfo(); ?>
  3. Load it in your browser and search for max_execution_time.

  4. Confirm the new value is active.

  5. Delete the test file afterward for security.

  • Increase gradually (e.g., 60 → 120 → 300 seconds).
  • Avoid setting excessively high values to prevent server overload.
  • Monitor application performance after changes.