How to install & configure LiteSpeed web server with DirectAdmin

config LiteSpeed DirectAdmin configuration Debian Ubuntu Centos RHEL

The web server is a crucial component of any web hosting environment. It is responsible for serving website files and processing requests from visitors. The two most popular web server software are Apache and LiteSpeed. Many web hosts use Apache by default since it’s free, open source, and time-tested. However, LiteSpeed is gaining popularity for its speed, scalability, and advanced caching capabilities.

In this guide, we will walk through the steps to configure LiteSpeed web server with DirectAdmin control panel. We’ll also discuss the advantages of switching from Apache to LiteSpeed and how it can benefit your hosting business.

Why Choose LiteSpeed Over Apache

Here are some of the key reasons to consider switching to LiteSpeed:

  • Faster performance – LiteSpeed uses an event-driven architecture that can handle more concurrent connections with lower CPU/memory usage compared to Apache. Benchmark tests show 2x-10x better throughput and latency.
  • Scalability – LiteSpeed utilizes multiple caching layers like connection pooling, memory caching, and SSL session caching for high scalability. It can handle thousands of concurrent connections easily.
  • Advanced caching features – LiteSpeed comes with built-in caching for static files and dynamic content. This speeds up websites and lowers database load.
  • Easy migration – Switching from Apache to LiteSpeed is relatively seamless. The rewrite rules and .htaccess files work without changes.
  • Web app firewall – LiteSpeed has a built-in firewall that detects and blocks SQL injections, XSS, and other attacks.
  • WebSocket support – LiteSpeed can handle WebSocket connections for real-time web apps. Apache needs additional modules.
  • Cost effective – At high traffic levels, LiteSpeed delivers better performance at lower infrastructure costs. The savings offset the license fees.

For resource-intensive sites, LiteSpeed can potentially deliver 5x more traffic than Apache on the same hardware. The performance gains and ease of scaling make it worthwhile for hosts to switch.

Install LiteSpeed with DirectAdmin

Let’s go through the installation steps to set up LiteSpeed with DirectAdmin control panel.

  • Log in to the DirectAdmin server terminal as the root user.
  • Navigate to the custom build directory:
$ cd /usr/local/directadmin/custombuild
  • Update the custombuild scripts:
$ ./build update
  • Set LiteSpeed as the web server:
$ ./build set webserver litespeed
  • Set the PHP processing mode to LiteSpeed:
$ ./build set php1_mode lsphp 
$ ./build set php2_mode lsphp
$ ./build set php3_mode lsphp
$ ./build set php4_mode lsphp
  • Install LiteSpeed:
$ ./build litespeed
  • Recompile PHP for LiteSpeed:
$ ./build php n

The commands above install LSWS with a trial license and build PHP for LSWS.

More install options are described on the official LiteSpeed wiki page.

You may refer to these instructions to activate the license.

To activate license after trial expires – get one from them and:

$ ./build set litespeed_serialno XXXX-YYYY-ZZZZ
$ ./build litespeed

Restart services for changes to take effect:

$ /etc/init.d/lsws restart
$ /etc/init.d/lscpd restart 

That covers the basic installation! LiteSpeed is now active and serving your websites. Next we’ll go through some recommended configuration tweaks.

LiteSpeed has many powerful features hidden behind the scenes. Here are some configuration tips to tap into its full potential:

1. Enable caching

Caching static files and pages can dramatically speed up websites under load. To enable caching in DirectAdmin:

  1. Go to Select Features in DirectAdmin.
  2. Enable LiteSpeed Web Cache.
  3. Set the desired cache rules, like caching images, CSS files for 1 week.
  4. Save changes.

This will activate LiteSpeed caching for new accounts. For existing accounts, you’ll have to enable caching manually per website or use .htaccess rules.

2. Adjust max connections

Each web server process can handle a limited number of simultaneous connections. The default limit is too low for busy sites. To increase it:

  1. Edit LiteSpeed config: /usr/local/lsws/conf/httpd_config.conf
  2. Bump up maxConnections to a higher limit like 10000-50000 based on your traffic.
  3. Save and restart LiteSpeed.

This enhances capacity to handle more visitors at once.

3. Enable WebSockets

If you host any apps that use WebSockets, enable this in the config:

<moduleHandlers>
  <!-- WebSockets support --> 
  <add name="WebSocket"/>
</moduleHandlers>

4. Set up caching for database queries

You can add caching for database content like WordPress/Joomla pages. This avoids repeatedly running the same queries.

  1. Install the LiteSpeed Cache for WordPress plugin.
  2. For other apps, use query caching features in phpMyAdmin or database.

Caching is one of the biggest performance wins of using LiteSpeed. Take advantage of the different layers offered.

5. Enable LSCache plugins for CMS

LiteSpeed Cache (LSCache) plugins further optimize popular CMS platforms like WordPress, Magento, and Joomla. Install these plugins and enable caching to speed up sites:

6. Add a WAF rule to block malicious requests

LiteSpeed comes with a web application firewall (WAF) module. You can set up custom rules to protect against attacks.

For example, block requests containing suspicious User-Agent strings:

<rule file="Block_Malicious_UserAgent.xml">
  <ruleset>
    <rule>
      <pattern>(libwww-perl|curl|python|nikto|scan|sqlmap|w3af|nmap)</pattern>
      <action>block</action>
    </rule>
  </ruleset>
</rule>

The WAF can help protect sites against exploits beyond normal .htaccess rules.

Migrating from Apache to LiteSpeed

If switching from an existing Apache setup, here is what’s needed to migrate smoothly:

  • Rewrite rules – .htaccess rewrite rules and Permalinks settings in WordPress will work as-is with LiteSpeed.
  • php.ini settings – Minor php.ini tweaks may be needed if PHP version is upgraded.
  • Modules – Enable LiteSpeed equivalents of any Apache modules in use, like mod_rewrite.
  • Layer 7 software – For proxy/CDNs like Varnish, update to support HTTP/2 and LiteSpeed.
  • Security rules – Migrate .htaccess security rules like IP blocking to LiteSpeed rulesets.
  • Performance testing – Do performance testing to tune caching settings and capacity limits.
  • Let’s Encrypt SSL – Migrate SSL certificates or set up a free Let’s Encrypt certificates.
  • Log formats – If needed, configure Apache style logs.

Aside from minor tweaks, the switch from Apache to LiteSpeed is not overly complex. For the large performance gains, it’s worth the upfront migration effort.

Conclusion

Apache has been the go-to web server for many years, but LiteSpeed is emerging as a faster, more scalable successor. On high traffic sites, LiteSpeed can deliver significantly better performance and reduce server load.

Switching web servers may seem daunting, but LiteSpeed makes it relatively smooth. With compatible rewrite rules and caching plugins, you can migrate existing sites over and immediately see gains.

On fresh servers, using LiteSpeed from the start is an excellent choice. The combination of LiteSpeed’s speed with DirectAdmin’s ease of use is compelling for any hosting provider. Your customers will appreciate the faster load times while you benefit from scalability to grow your business.

LEAVE A COMMENT