How to Fix PHP Timeouts on LiteSpeed Servers Print

  • php timeout, litespeed, htaccess, cpanel, server configuration, php settings, max execution time, script timeout
  • 0

To prevent PHP script timeouts on LiteSpeed servers, you need to configure timeout limits in your .htaccess file by adding specific LiteSpeed directives that disable connection timeouts and script aborts. This simple configuration change allows your PHP scripts to run for the full duration set in your PHP settings, preventing premature termination of long-running processes like database imports, migrations, or complex operations.

PHP timeout errors occur when scripts exceed the default execution time limits imposed by the web server. While you can adjust PHP's max_execution_time setting, LiteSpeed servers also have their own connection timeout controls that can interrupt scripts independently. The solution involves adding LiteSpeed-specific rules to your .htaccess file that work alongside your PHP timeout settings.

Accessing Your .htaccess File in cPanel

First, log into your cPanel account and locate the File Manager under the FILES section. This tool allows you to browse and edit files on your hosting account directly through your web browser.

Once File Manager opens, navigate to the document root directory for the domain experiencing timeout issues. This is typically the public_html folder for your primary domain, or a subdirectory for addon domains. If you don't see a file named .htaccess in this folder, you need to enable the display of hidden files.

Click the Settings button in the top right corner of File Manager and ensure the checkbox for "Show hidden files (dotfiles)" is enabled. Files beginning with a dot are hidden by default on Linux systems, but this setting makes them visible so you can edit them.

Adding LiteSpeed Timeout Configuration

Once you can see the .htaccess file, right-click it and select Edit (or Code Edit for syntax highlighting). Scroll to the bottom of the file and add the following code block:

<IfModule Litespeed>
RewriteEngine On
RewriteRule .* - [E=noconntimeout:1]
RewriteRule .* - [E=noabort:1]
</IfModule>

These directives tell LiteSpeed to disable connection timeouts and prevent automatic script aborts for all requests. The IfModule wrapper ensures this code only runs on LiteSpeed servers, preventing errors if your site is ever moved to a different server type. Save the file after adding this code.

Adjusting PHP Timeout Limits

After configuring the .htaccess file, your scripts will respect the PHP timeout limits set in cPanel's Select PHP Version tool (or PHP Settings/MultiPHP INI Editor, depending on your cPanel version). Navigate to this tool in cPanel and adjust the following values as needed:

  • max_execution_time - Maximum time in seconds a script can run (e.g., 300 for 5 minutes)
  • max_input_time - Maximum time in seconds a script can parse input data
  • memory_limit - Maximum memory a script can use (increase if scripts fail due to memory constraints)

For most long-running operations like WordPress imports or database migrations, setting max_execution_time to 300 seconds (5 minutes) or 600 seconds (10 minutes) provides sufficient time without leaving your server vulnerable to runaway scripts.

Verifying the Configuration

After implementing these changes, test your previously failing script to confirm the timeout issue is resolved. If you still experience timeouts, verify that:

  • The .htaccess code was added correctly without typos
  • Your PHP timeout values are set high enough for your specific operation
  • The .htaccess file is in the correct directory (the document root for the affected domain)
  • Your server has sufficient resources to complete the operation

If problems persist after verification, the issue may be related to server resource limits rather than timeout settings. OBHost servers include generous resource allocations, but extremely intensive operations may require optimization or dedicated resources.

Frequently Asked Questions

What's the difference between PHP timeouts and LiteSpeed timeouts?

PHP timeouts control how long a PHP script can execute, set via max_execution_time in your PHP configuration. LiteSpeed timeouts are server-level connection timeouts that can terminate requests independently of PHP settings. Both need to be configured properly to prevent premature script termination on LiteSpeed servers.

Can I set different timeout values for specific scripts or directories?

Yes, you can place the .htaccess configuration in specific subdirectories to apply timeout rules only to those locations. You can also use conditional RewriteCond directives to apply timeout exemptions only to specific scripts or URLs, giving you granular control over which operations receive extended execution time.

Will disabling timeouts make my server vulnerable?

The configuration shown adds timeout exemptions but your PHP max_execution_time setting still provides a safety limit. Set reasonable PHP timeout values (typically 5-10 minutes maximum) to prevent runaway scripts from consuming server resources indefinitely while allowing legitimate long-running operations to complete successfully.

Why does my script still timeout after these changes?

If timeouts persist, check that your PHP max_execution_time is set high enough, verify the .htaccess syntax is correct, and ensure you're editing the .htaccess file in the right directory. Some scripts may also hit memory limits rather than time limits, requiring an increase to the PHP memory_limit setting instead.

If you need assistance configuring timeout settings or troubleshooting persistent timeout issues, the OBHost support team is available 24/7 to help. Visit https://www.obhost.net/contact or email support@obhost.org for expert assistance with your hosting configuration.


Was this answer helpful?

« Back