Documentation
Documentación » Hosting » Configure and optimize LiteSpeed Hosting

Configure and optimize LiteSpeed Hosting

Quick access to sections of this document

1 - Introduction to LiteSpeed

LiteSpeed is a powerful web server that offers a remarkable performance improvement compared to Apache
LiteSpeed is fully retro-compatible with Apache, don’t worry, the server operation remains the same.
LiteSpeed brings by default an advanced cache system called LSCache, what this system does is to catch the dynamic content of the websites to serve them as static content, thus improving the loading time of a website in an outstanding way. The user is browsing the web and the pages load instantly.
The secret of this exceptional performance lies in the native integration between the different CMSs (WordPress, Prestashop, Magento, Drupal, Joomla, etc …) and LiteSpeed itself.
Below we explain how to configure LiteSpeed to get the most out of your website.

2 - Activate LSCaché through plugin

To activate LSCache is very simple, you just have to install the corresponding plugin for your CMS. These are the links where you can download it:
After having installed the plugin, you will notice how the loading times of your website drop drastically, thus providing an excellent browsing experience to your users. In case you want to empty the LiteSpeed cache, from cPanel itself you will see that you have an icon available to perform this action.
In case you want to empty the LiteSpeed cache, from cPanel itself you will see that you have an icon available to perform this action.
Remember that the plugins are totally free, the LiteSpeed server does have a license cost, but we already assume that cost in GINERNET so that you can use the plugins without having to pay anything.

3 - Activate LSCaché without plugin

If your website does not have a module for LiteSpeed, you can apply the following directive at the beginning of your .htaccess file to cache the content of your website:
  • To cache all content:
RewriteRule ^(.*) - [E=Cache-Control:max-age=86400]
  • To cache a specific file:
RewriteRule ^fichero.php$ - [E=Cache-Control:max-age=86400]
The max-age variable specifies in seconds the time that the content will remain cached after that time the cache will be emptied. 86400 seconds = 1 day
86400 seconds = 1 day

4- LiteSpeed ReCAPTCHA Protection

On servers with LiteSpeed there is the possibility to protect access to the website by means of a reCAPTCHA check. This protection is configured in a very simple way through .htaccess, below we explain how. (ERROR:a continuación de explicamos como)

This protection is configured in a very simple way through .htaccess, below we explain how. 

  • • If you want to protect the entire web for specific countries:
<IfModule LiteSpeed>
RewriteCond %{ENV:GEOIP_COUNTRY_CODE} ^(CN|RU)$
RewriteRule .* - [E=verifycaptcha][L]
</IfModule>
where the CN | RU value indicates that the countries with protection are China and Russia
  • If you want to protect the entire web worldwide
<IfModule LiteSpeed>
RewriteRule .* - [E=verifycaptcha]
</IfModule>

Be careful with this rule, since the payment gateways will not be able to execute notifications as they cannot resolve the re-captcha.

  • If you want to protect the entire web except some specific directories / files
<IfModule LiteSpeed>
RewriteCond %{REQUEST_URI} !^/directorio/excluido/ RewriteCond %{REQUEST_URI} !^/fichero/excluir.php RewriteRule .* - [E=verifycaptcha]
</IfModule>
  • If you want to protect only some specific directories / files
<IfModule LiteSpeed>
RewriteRule fichero.php - [E=verifycaptcha]
RewriteRule ^directorio - [E=verifycaptcha]
RewriteRule ^directorio/permitido - [E=verifycaptcha]
RewriteRule ^directorio/fichero.php - [E=verifycaptcha]
</IfModule>

5 - Configure Crawler LiteSpeed for Prestashop

The LiteSpeed crawler for Prestashop is a script that is responsible for automatically crawling all the products on your website to introduce them into the cache. In this way, when a user visits a product for the first time, they can already download it from the cache (faster). In order for the crawler to know which products we want to cache, we have to generate a sitemap. We can do this with the Prestashop Google Sitemap tool.
In order for the crawler to know which products we want to cache, we have to generate a sitemap. We can do this with the Prestashop Google Sitemap tool.

Download the crawler file and upload it via FTP (you don’t have to put it inside public_html)

Access your cPanel and create a daily cron, for example at 3:00 AM with this command:
bash /home/USUARIO/cachecrawler.sh URL_SITEMAP >/dev/null 2>&1
For example, like this:
bash /home/ginernet/cachecrawler.sh http://ginernet.com/1_index_sitemap.xml >/dev/null 2>&1
You can contact us so we can verify that you have correctly created the cron and that the crawler is running correctly.

6 - Configure custom php.ini values in LiteSpeed

LiteSpeed allows you to modify certain PHP parameters using .htaccess.
  • Edit your .htaccess file and define the values you want, here is an example of syntax.
php_value max_execution_time 300
php_value memory_limit 2048M
php_value upload_max_filesize 2048M
php_value post_max_size 2048M
  • To verify what values the server is returning, you must create a test php page and run the phpinfo function inside, like this:
<?php
phpinfo();
?>

7 - Remove LiteSpeed server timeout

The directives in this section causes LiteSpeed processes are never killed, which can cause your server to crash and therefore make your website inaccessible. You must be sure of what you are doing.
We have any LiteSpeed process configured to kill itself automatically 120 seconds after it has started. Normally, when a user executes an action on a website and the result takes more than this time to execute, it is because there is a problem, therefore, the process is killed to avoid saturating the server with zombie processes. However, if you need to remove this limit you can do it, we will explain it to you below.
LiteSpeed has a .htaccess directive that allows you to configure the web server to ignore the timeout, it is the following:
1. For some URLs
Let’s imagine that we have 3 files that we want to execute and whose execution time is greater than 120 seconds.
These files are called for example:
  • wp-cron.php
  • backupbuddy.php
  • importbuddy.php
This is the directive:
  • Method 1 – mod_rewrite
<IfModule Litespeed> 
RewriteEngine On
RewriteRule (wp-cron|backupbuddy|importbuddy)\.php - [E=noabort:1, E=noconntimeout:1]
</IfModule>
  • Method 2 – SetEnv
<IfModule Litespeed> 
SetEnvIf Request_URI "(wp-cron|backupbuddy|importbuddy)\.php" noabort noconntimeout
</IfModule>
2. For all URLs
We do not recommend eliminating the timeout for all pages, 99% of the cases it is only necessary to eliminate the timeout to a specific file, therefore see method 1 above to eliminate the timeout only in some URLs.

If you still need to remove it for all pages, this is the directive you should use:
<IfModule Litespeed> 
RewriteEngine On
RewriteRule .* - [E=noabort:1, E=noconntimeout:1]
SetEnv noconntimeout
</IfModule>
or this way…
<IfModule Litespeed>
SetEnv noabort 1
SetEnv noconntimeout 
</IfModule>
IF YOUR SERVER HAS BEEN SATURATED AND YOUR WEB IS INACCESSIBLE, YOU CAN REPAIR IT LIKE THIS:
You must access the cPanel of the domain in matter and click on the “Terminal” button
A terminal will open where you can kill all processes by executing the following command:
kill -9 -1