Era Host hosting
EraHost – Free Domain, Cheap Hosting!
Client Area
Support 24/7
Menu

Fixing "A Fatal Error or Timeout Occurred" by Increasing PHP Limits

4 min read
12.06.2025

Identify the PHP Configuration File (php.ini)

Before changing PHP limits, you need to know which PHP configuration file is being used.

PHP Limits Increase Timeout Fix
Raise max_execution_time + memory_limit; verify which SAPI applies.

For related timeout-and-resource topics, see Fixing "Fatal Error or Timeout Occurred" in cPanel, Timeout Error Processing Directive, and How to Update PHP Memory Limit for Magento 2.

Find the Active php.ini

  1. Create a new PHP script called phpinfo.php in your web directory:
    <?php
    phpinfo();
    ?>
  2. Access the script in your browser:
    http://yourwebsite.com/phpinfo.php
  3. Look for the Loaded Configuration File section. It will show the path to the active php.ini file (e.g., /etc/php/8.0/apache2/php.ini).
Linux VDS
High performance for your projects
  • Root access and flexible setup
  • Control panel
  • NVMe disks
  • DDR5
Linux VDS

Edit the php.ini File

The most common solution is to increase the relevant limits in php.ini.

Steps to Increase PHP Limits

  1. Open the php.ini file:
    sudo nano /etc/php/8.0/apache2/php.ini
  2. Locate and adjust the following settings:
    ; Maximum execution time of each script, in seconds
    max_execution_time = 300
    
    ; Maximum amount of memory a script may consume
    memory_limit = 512M
    
    ; Maximum allowed size for uploaded files
    upload_max_filesize = 100M
    
    ; Maximum size of POST data that PHP will accept
    post_max_size = 100M
    
    ; Maximum input time for parsing POST/GET data (in seconds)
    max_input_time = 300
  3. Save the changes and exit the editor.
  4. Restart your web server to apply the changes:
    • For Apache:
      sudo systemctl restart apache2
    • For NGINX:
      sudo systemctl restart php8.0-fpm

Override PHP Settings with .htaccess

If you cannot edit the php.ini file (e.g., on shared hosting), you can override these settings using an .htaccess file.

Add Settings to .htaccess

  1. Open or create the .htaccess file in the root directory of your application.
  2. Add the following lines:
    # Increase PHP execution time and memory limits
    php_value max_execution_time 300
    php_value memory_limit 512M
    php_value upload_max_filesize 100M
    php_value post_max_size 100M
    php_value max_input_time 300
  3. Save the file and reload your website.

Override PHP Settings with ini_set in Code

If you cannot modify php.ini or .htaccess, you can temporarily increase PHP limits within the script.

Add ini_set Calls to Your PHP Code

Insert the following lines at the beginning of the affected PHP script:

<?php
// Increase PHP limits
ini_set('max_execution_time', 300); // 5 minutes
ini_set('memory_limit', '512M');    // 512 MB
ini_set('upload_max_filesize', '100M');
ini_set('post_max_size', '100M');
ini_set('max_input_time', 300);
?>

Verify Changes

After modifying the PHP limits, confirm that the new settings are applied.

Recheck with phpinfo()

  • Reload your phpinfo.php script in your browser.
  • Verify that the updated values appear for:
    • max_execution_time
    • memory_limit
    • upload_max_filesize
    • post_max_size

Debugging Timeouts or Fatal Errors

If the issue persists, collect more information about the error.

Enable PHP Error Reporting

  1. Add the following code to your script to display detailed error messages:
    <?php
    error_reporting(E_ALL);
    ini_set('display_errors', 1);
    ?>
  2. Re-run the script and note the exact error message.

Example Scenarios

Here are two common scenarios with solutions:

Scenario 1: File Uploads Fail with Timeout

Error Message:

Maximum execution time of 30 seconds exceeded

Solution: Increase the max_execution_time, memory_limit, and upload_max_filesize in php.ini or .htaccess:

max_execution_time = 300
memory_limit = 512M
upload_max_filesize = 100M
post_max_size = 100M

Scenario 2: Out of Memory Error

Error Message:

Fatal error: Allowed memory size of 128M exhausted

Solution: Increase the memory_limit in php.ini or .htaccess:

memory_limit = 512M

Final Steps

  1. Restart Services: Ensure you restart the web server after making changes to php.ini.
  2. Test Your Script: Run the application or process again to confirm the issue is resolved.
  3. Monitor Logs: Check logs for additional issues:
    • Apache:
      tail -f /var/log/apache2/error.log
    • PHP:
      tail -f /var/log/php_errors.log

Summary

To resolve "A Fatal Error or Timeout Occurred While Processing This Directive", increase the relevant PHP limits using one of these methods:

  1. Modify the php.ini file.
  2. Use an .htaccess file for overrides.
  3. Add ini_set calls in your PHP script.
  4. Verify the changes using phpinfo().

By following these steps, the timeout or fatal error should be resolved.

Frequently asked questions
`php -i | grep 'Loaded Configuration File'` shows the active one. Then phpinfo() in browser shows the web-SAPI's active php.ini — may differ from CLI. Apache mod_php uses one; PHP-FPM uses another; CLI uses a third. Edit the one matching the SAPI you're trying to fix.
`.user.ini` for PHP-FPM (CGI-style SAPI); recognizes most ini directives. `.htaccess` with `php_value max_execution_time 300` for Apache mod_php; doesn't work under PHP-FPM. Pick based on stack. cPanel "Select PHP Version" → Options UI writes to .user.ini automatically — easier than manual edits.
Mid-script before the limit's hit. E.g., import script: `ini_set('max_execution_time', 0)` at the top sets unlimited for that request only. Doesn't help for compile-time fatal errors (already at limit before script ran). Some directives (memory_limit) only respect ini_set if PER-request mode; verify they take effect.
Some other limit higher in the stack. Apache `Timeout` directive (server-level). nginx `fastcgi_read_timeout`. Cloudflare default 100s. Each adds its own cap. Find which by timing: if exactly 60s, suspect mod_php; exactly 100s, Cloudflare; exactly 30s, nginx default. Raise the matching layer.
Related articles
Fixing "A Fatal Error or Timeout Occurred While Processing This Directive"
Fixing "Internal Server Error" (500) in Apache/Nginx
Fixing "Fatal Error or Timeout" by Adjusting Timeout Settings