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.
Why Change max_execution_time?
Section titled “Why Change max_execution_time?”-
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”Step 1: Access Your Hosting Account
Section titled “Step 1: Access Your Hosting Account”- Log in to cPanel or use FTP/File Manager.
- Navigate to your site’s root directory (e.g.,
/public_html).
Step 2: Create or Edit .htaccess
Section titled “Step 2: Create or Edit .htaccess”- If
.htaccessalready exists, open it for editing. - If not, create a new file named
.htaccess.
Step 3: Add the Directive
Section titled “Step 3: Add the Directive”Insert the following line:
php_value max_execution_time 120- Replace
120with the desired number of seconds (e.g.,60,300). - Setting
0allows unlimited execution time, but this is not recommended for shared hosting environments.
Step 4: Save and Verify
Section titled “Step 4: Save and Verify”-
Save the
.htaccessfile. -
Create a test file
info.phpwith:<?php phpinfo(); ?> -
Load it in your browser and search for
max_execution_time. -
Confirm the new value is active.
-
Delete the test file afterward for security.
Best Practices
Section titled “Best Practices”- Increase gradually (e.g., 60 → 120 → 300 seconds).
- Avoid setting excessively high values to prevent server overload.
- Monitor application performance after changes.