How to Install & Configure LiteSpeed Web Server with DirectAdmin

Posted on

How to Install & Configure LiteSpeed Web Server with DirectAdmin

How to Install & Configure LiteSpeed Web Server with DirectAdmin

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, How to Install & Configure LiteSpeed Web Server with DirectAdmin 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. Understanding How to Install & Configure LiteSpeed Web Server with DirectAdmin can significantly improve your server’s performance.

Why Choose LiteSpeed Over Apache

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

  • Superior Performance: LiteSpeed demonstrates better performance benchmarks than Apache, especially under heavy load. Its event-driven architecture handles concurrent connections more efficiently.
  • LSCache: LiteSpeed Cache (LSCache) is a built-in, high-performance caching solution that integrates seamlessly with popular CMS platforms like WordPress, Magento, and Joomla.
  • Compatibility: LiteSpeed is largely compatible with Apache’s .htaccess rules, making migration easier.
  • Security: LiteSpeed comes with built-in anti-DDoS features and a web application firewall (WAF) to protect against attacks.
  • Scalability: LiteSpeed can handle more concurrent connections and traffic with fewer resources than Apache.

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.

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

  • Navigate to the CustomBuild directory:
$ cd /usr/local/directadmin/custombuild
  • Update CustomBuild:
$ ./build update
  • Set the webserver to LiteSpeed:
$ ./build set webserver litespeed
  • Set PHP mode to lsphp:
$ ./build set php1_mode lsphp 
$ ./build set php2_mode lsphp
$ ./build set php3_mode lsphp
$ ./build set php4_mode lsphp
  • Install LiteSpeed:
$ ./build litespeed
  • Build PHP:
$ ./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.

Recommended Configuration Changes

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. Log in to DirectAdmin as the admin user.
  2. Go to Admin Tools -> CustomBuild.
  3. Click on Edit Options.
  4. Set enable_lsapi_cache to yes.
  5. Click Save.
  6. Run ./build litespeed again to apply the 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 the LiteSpeed configuration file (/usr/local/lsws/conf/httpd_config.conf).
  2. Find the maxConnections setting under the tuning section.
  3. Increase the value to a higher number, such as 2000 or 5000.
  4. 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 a database caching plugin (e.g., LSCache plugin for WordPress).
  2. Configure the plugin to cache database queries for a specific duration.
  3. Test the caching to ensure it’s working correctly.

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:

  • WordPress: LSCache for WordPress plugin.
  • Magento: LSCache for Magento extension.
  • Joomla: LSCache for Joomla plugin.

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:

  • Backup: Back up your entire server configuration and website files before making any changes.
  • .htaccess Compatibility: LiteSpeed is largely compatible with Apache .htaccess files. However, review your .htaccess rules to ensure they work as expected.
  • Restart Apache: Disable Apache or change its port to avoid conflicts with LiteSpeed.
  • Test: Thoroughly test your websites after the migration to ensure everything is working correctly.
  • DNS Propagation: Allow time for DNS changes to propagate if you change your server IP address.

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.

Alternative Solutions and Elaborations for Enhancing Web Server Performance

While LiteSpeed offers a powerful solution for improving web server performance, here are two alternative approaches:

1. Implementing a Reverse Proxy with Nginx

Nginx can be configured as a reverse proxy in front of Apache or even LiteSpeed, to handle static content and offload tasks like SSL termination. This significantly reduces the load on the main web server and improves overall performance. This is another method of How to Install & Configure LiteSpeed Web Server with DirectAdmin

Explanation:

A reverse proxy sits in front of one or more web servers, intercepting client requests. It can cache static content (images, CSS, JavaScript) and serve it directly without involving the backend server. Nginx excels at serving static files efficiently. It can also handle SSL/TLS encryption and decryption, freeing up the main web server to focus on dynamic content generation.

Implementation Steps:

  1. Install Nginx: Install Nginx on the server, ensuring it’s configured to listen on ports 80 and 443 (for HTTP and HTTPS).

  2. Configure Nginx as a Reverse Proxy: Create an Nginx configuration file (e.g., /etc/nginx/conf.d/reverse-proxy.conf) with the following content (adjust the server_name and proxy_pass directives as needed):

server {
    listen 80;
    listen 443 ssl;
    server_name example.com www.example.com; # Replace with your domain

    ssl_certificate /path/to/your/ssl_certificate.pem; # Replace with your SSL certificate path
    ssl_certificate_key /path/to/your/ssl_certificate.key; # Replace with your SSL key path

    location / {
        proxy_pass http://127.0.0.1:8080; # Replace with your backend server's address and port (e.g., Apache on port 8080 or LiteSpeed)
        proxy_set_header Host $host;
        proxy_set_header X-Real-IP $remote_addr;
        proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
        proxy_set_header X-Forwarded-Proto $scheme;
    }

    location ~* .(jpg|jpeg|png|gif|css|js|ico)$ { # Static file caching
        expires 30d;
        access_log off;
        add_header Cache-Control "public, max-age=2592000";
    }
}
  1. Configure the Backend Server (Apache or LiteSpeed): If you’re using Apache, you may need to configure it to listen on a different port (e.g., 8080) and adjust its virtual host configuration accordingly. The same applies to LiteSpeed if it’s running behind Nginx.

  2. Restart Nginx: Restart Nginx to apply the changes: sudo systemctl restart nginx

Benefits:

  • Improved Performance: Serving static content directly by Nginx reduces the load on the backend server.
  • SSL Offloading: Nginx handles SSL/TLS encryption, freeing up the backend server.
  • Enhanced Security: Nginx can act as a buffer against attacks, protecting the backend server.

2. Optimizing the Underlying Infrastructure (Hardware and Operating System)

Another approach is to focus on optimizing the server’s hardware and operating system. This involves ensuring sufficient resources (CPU, RAM, disk I/O) and tuning the OS for optimal performance. How to Install & Configure LiteSpeed Web Server with DirectAdmin can be enhanced by hardware configurations.

Explanation:

The performance of any web server is ultimately limited by the underlying hardware and operating system. Insufficient resources or a poorly configured OS can bottleneck performance, regardless of the web server software used.

Optimization Strategies:

  • Hardware Upgrades:

    • CPU: Use a processor with a higher clock speed and more cores.
    • RAM: Ensure sufficient RAM to handle the expected workload. Insufficient RAM can lead to excessive disk swapping, which significantly slows down performance.
    • Disk I/O: Use SSDs (Solid State Drives) for faster disk access compared to traditional HDDs (Hard Disk Drives). Consider using RAID configurations for increased performance and redundancy.
  • Operating System Tuning:

    • Kernel Tuning: Adjust kernel parameters (e.g., net.core.somaxconn, net.ipv4.tcp_tw_recycle, vm.swappiness) to optimize network performance and memory management.
    • File System Optimization: Use a high-performance file system (e.g., ext4, XFS) and tune its mount options for optimal performance.
    • Disable Unnecessary Services: Disable or remove any unnecessary services that are running on the server to free up resources.
    • Use a Lightweight Operating System: Consider using a lightweight Linux distribution (e.g., Alpine Linux, CentOS Minimal) to reduce the overhead of the operating system.

Implementation Example (Kernel Tuning – Adjusting net.core.somaxconn):

The net.core.somaxconn parameter controls the maximum number of pending connections allowed in the socket listen queue. Increasing this value can help prevent connection drops under heavy load.

  1. Edit sysctl.conf: Open the /etc/sysctl.conf file in a text editor.

  2. Add or Modify the Parameter: Add or modify the following line:

net.core.somaxconn = 65535
  1. Apply the Changes: Apply the changes by running:
sudo sysctl -p

Benefits:

  • Overall Performance Improvement: Optimizing the hardware and OS provides a foundation for improved web server performance.
  • Resource Efficiency: Tuning the OS can reduce resource consumption and improve efficiency.
  • Scalability: Adequate hardware resources are essential for scaling the web server to handle increased traffic.

By implementing these alternative solutions, you can further enhance the performance of your web server and ensure it can handle the demands of your website or application.

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. Understanding How to Install & Configure LiteSpeed Web Server with DirectAdmin is crucial for modern server management.

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. The guide on How to Install & Configure LiteSpeed Web Server with DirectAdmin offers valuable insights.

Leave a Reply

Your email address will not be published. Required fields are marked *