How to Install OpenLiteSpeed Webserver on Rocky Linux 9

Updated on July 25, 2024
How to Install OpenLiteSpeed Webserver on Rocky Linux 9 header image

Introduction

OpenLiteSpeed is a free, open-source, and lightweight webserver developed by LiteSpeed Technologies. It's known for its high performance and low resource consumption, making it a popular choice for hosting web applications. OpenLiteSpeed is compatible with Apache configurations, supports multiple programming languages, and includes built-in security features and caching mechanisms.

This article explains how to install OpenLiteSpeed webserver on Rocky Linux 9 and create virtual hosts using the web administration console to deliver web applications.

Prerequisites

Before you begin:

Install OpenLiteSpeed

The OpenLiteSpeed webserver package is not available in the default repositories on Rocky Linux 9. Follow the steps below to download the latest OpenLiteSpeed repository setup script to install the webserver using the DNF package manager.

  1. Download the latest OpenLiteSpeed repository script.

    console
    $ wget -O - https://repo.litespeed.sh | sudo bash
    
  2. Install OpenLiteSpeed.

    console
    $ sudo dnf install openlitespeed -y
    
  3. View the installed OpenLiteSpeed version on your server.

    console
    $ sudo /usr/local/lsws/bin/lshttpd -v
    

    Output:

    LiteSpeed/1.7.19 Open (BUILD built: Tue Apr 16 15:14:26 UTC 2024) 
        module versions:
        lsquic 3.3.2
        modgzip 1.1
        cache 1.66
        mod_security 1.4 (with libmodsecurity v3.0.12)
        ```
  4. Run the OpenLiteSpeed administrator password script to set up a new administrative user and password.

    console
    $ sudo /usr/local/lsws/admin/misc/admpass.sh
    

    Enter your desired username and password when prompted similar to the output below.

    Please specify the user name of administrator.
    This is the user name required to login the administration Web interface.
    
    User name [admin]: 
    
    Please specify the administrator's password.
    This is the password required to login the administration Web interface.
    
    Password: 
    Retype password: 
    Administrator's username/password is updated successfully!
  5. Disable the default firewalld firewall to temporarily enable Let's Encrypt validations and configure the webserver.

    console
    $ sudo systemctl stop firewalld
    
  6. Access your server IP address using a web browser such as Chrome on port 8088 to verify that the default OpenLiteSpeed virtual host web application displays.

    http://SERVER-IP:8088 

    The default OpenLiteSpeed virtual host page

Manage the OpenLiteSpeed System Service

OpenLiteSpeed uses the lsws system service to manage the webserver processes using systemd. Follow the steps below to enable the OpenLiteSpeed service to start at boot time and manage the webserver processes.

  1. Enable the OpenLiteSpeed service to automatically start at boot time.

    console
    $ sudo systemctl enable lsws
    
  2. Start the OpenLiteSpeed service.

    console
    $ sudo systemctl start lsws
    
  3. View the OpenLiteSpeed service status and verify that it's active.

    console
    $ sudo systemctl status lsws
    

    Output:

    ● lshttpd.service - OpenLiteSpeed HTTP Server
         Loaded: loaded (/usr/lib/systemd/system/lshttpd.service; enabled; preset: disabled)
         Active: active (running) since Thu 2024-06-27 09:53:53 UTC; 10min ago
       Main PID: 51515 (litespeed)
         CGroup: /system.slice/lshttpd.service
                 ├─51515 "openlitespeed (lshttpd - main)"
                 ├─51522 "openlitespeed (lscgid)"
                 ├─51535 "openlitespeed (lshttpd - #01)"
                 └─51536 "openlitespeed (lshttpd - #02)"
    
    ........ rockylinux systemd[1]: Starting OpenLiteSpeed HTTP Server...

    Based on the above active (running) message in the output, the OpenLiteSpeed service is active and running on your server.

Create a new OpenLiteSpeed Virtual Host

OpenLiteSpeed virtual hosts allow you to host multiple domains or subdomains to securely deliver web applications on your server. Follow the steps below to create a new OpenLiteSpeed virtual host for your domain app.example.com that serves an HTML web application and outputs the message Greetings from Vultr when accessed.

  1. Access the OpenLiteSpeed web administration console using your server IP on the default port 7080 in a new web browser window.

    http://SERVER-IP:7080

    Enter the administrative user and password you set earlier to access the WebAdmin console.

    OpenLiteSpeed login page

  2. Click Virtual Hosts on the main navigation menu.

    Access OpenLiteSpeed Virtual Hosts

  3. Click Add in the top right corner within the Virtual Host List section.

    Virtual Host summary

  4. Enter the following virtual host details in the respective fields.

    • Virtual Host Name: app.example.com
    • Virtual Host Root: $SERVER_ROOT/conf/vhosts/$VH_NAME/
    • Config File: $SERVER_ROOT/conf/vhosts/$VH_NAME/vhconf.conf
    • Follow Symbolic Link: Yes
    • Enable Scripts/ExtApps: Yes
    • Restrained: Yes
  5. Click Save to save the new virtual host configuration. Then, when prompted to resolve errors, find and click CLICK TO CREATE to create a new configuration file and web root directory.

    Create a new virtual host

  6. Click Save to apply the new virtual host configuration on your server.

  7. Verify that the new virtual host is available in your Virtual Host List section. Then, click View within the actions section to modify the virtual host configuration.

    Showing added virtual host

  8. Click Edit within the General tab to modify the virtual host configuration.

    OpenLiteSpeed general configuration

  9. Enter the following values in the respective fields to enable on your virtual host. Replace app.example.com with your actual domain.

    • Document Root: $SERVER_ROOT/conf/vhosts/$VH_NAME/
    • Domain Name: app.example.com
    • Enable GZIP: YES

    Edit website configuration

  10. Click Save to apply the new virtual host configuration changes.

    Edit index files

  11. Click Edit within the Index Files section to set up your virtual host index information.

  12. Enter the following values in the respective fields to set up the default virtual host web application file.

    • Use Server Index Files: No
    • Index Files: index.html
    • Auto Index: No
  13. Click Save to apply the new index page changes.

    Define index file

  14. Navigate to the Log tab.

  15. Click Edit within the Virtual Host Log section to modify the virtual host log information.

  16. Enter the following details in the respective fields to set up logging.

    • Use Servers Log: Yes
    • File Name: $SERVER_ROOT/conf/vhosts/$VH_NAME/error.log
    • Log LevelI: ERROR
    • Rolling Size (bytes): 10M
    • Keep Days: 7
    • Compress Archive: Yes
  17. Click Save to apply the log changes.

  18. Navigate to Listeners on the main navigation menu.

  19. Click Edit in the Actions section next to the Default listener to modify the default webserver configuration.

    View listener page

  20. Click Edit within the Address Settings section to modify the default address and information.

    View default listener

  21. Change the default listening Port value from 8088 to the HTTP port 80.

  22. Click Save to apply the new listening address information.

    Change listeners

  23. Find the Virtual Host Mappings section, and click the Edit icon next to the Example virtual host to modify the default domain.

    Edit virtual host mapping

  24. Enter the following values in the respective fields. Replace app.example.com with your actual domain.

    • Virtual Host: app.example.com
    • Domains: app.example.com
  25. Click Save to apply the new default virtual host domain.

    Define virtual host mapping

  26. Find LSWS PID in the top right corner of the console and click Graceful Restart to restart the OpenLiteSpeed webserver.

    View modified virtual host

  27. Click GO when prompted to restart the LiteSpeed service and apply your configuration changes.

  28. Access your server SSH session.

    console
    $ ssh user@SERVER-IP
    
  29. Create a new index.html web application file in your virtual host's web root directory.

    console
    $ sudo nano /usr/local/lsws/conf/vhosts/app.example.com/index.html
    
  30. Add the following contents to the file.

    html
    <!DOCTYPE html>
    <html lang="en">
    <head>
        <meta charset="UTF-8">
        <meta name="viewport" content="width=device-width, initial-scale=1.0">
        <title>Welcome</title>
    </head>
    <body>
        Greetings from Vultr
    </body>
    </html>
    

    Save and close the file.

    The above HTML application file displays a Greetings from Vultr message when accessed in a web browser.

  31. Create a new error log file for your virtual host.

    console
    $ sudo touch /usr/local/lsws/conf/vhosts/app.example.com/error.log
    
  32. Grant the OpenLiteSpeed user full privileges to the virtual host web root directory.

    console
    $ sudo chown -R lsadm: /usr/local/lsws/conf/vhosts/app.example.com/
    
  33. Change the virtual host web root directory permissions to 755 to grant the OpenLiteSpeed user read, write and execute privileges.

    console
    $ sudo chmod -R 755 /usr/local/lsws/conf/vhosts/app.example.com/
    
  34. Access your domain in a new web browser window and verify that your HTML web application displays the message Greetings from Vultr.

    http://app.example.com  

    Test access to an OpenLiteSpeed virtual host domain

Secure the OpenLiteSpeed Webserver

The OpenLiteSpeed webserver delivers all web applications using the default HTTP port 80 as defined in your listener configurations. Follow the steps below to generate new Let's Encrypt SSL certificates to secure the OpenLiteSpeed webserver with HTTPS traffic.

  1. Install the Certbot Let's Encrypt client tool on your server.

    console
    $ sudo dnf install certbot -y
    
  2. Generate a new Let's Encrypt SSL certificate for your domain using the virtual host's web root directory. Replace app.example.com with your actual domain and admin@example.com with your email address.

    console
    $ sudo certbot certonly --non-interactive --agree-tos -m admin@example.com --webroot -w /usr/local/lsws/conf/vhosts/app.example.com/ -d app.example.com
    

    Output:

    Saving debug log to /var/log/letsencrypt/letsencrypt.log
    Account registered.
    Requesting a certificate for app.example.com
    
    Successfully received certificate.
    Certificate is saved at: /etc/letsencrypt/live/app.example.com/fullchain.pem
    Key is saved at:         /etc/letsencrypt/live/app.example.com/privkey.pem
    This certificate expires on 2024-09-25.
    These files will be updated when the certificate renews.
    Certbot has set up a scheduled task to automatically renew this certificate in the background.

    Based on the above SSL certificate output, your new SSL certificate is available with the /etc/letsencrypt/live/app.example.com/fullchain.pem path and the private key /etc/letsencrypt/live/app.example.com/privkey.pem. You can use the paths to integrate your SSL certificate with virtual hosts in the OpenLiteSpeed WebAdmin console.

  3. Access your OpenLiteSpeed web administration console.

    http://SERVER-IP:7080
  4. Navigate to Listeners on the main navigation menu.

  5. Click Add within the Listener List section to set up a new listener.

    View listeners page

  6. Click Edit within the Address Settings section to set up a new address and port to listen for incoming connections.

  7. Enter the following values in the respective fields to set up a new HTTPS connections listener.

    • Listener Name: HTTPS
    • IP Address: ANY IPv4
    • Port: 443
    • Secure: Yes
  8. Click Save to apply the new HTTPS configuration.

    Add new https listeners

  9. Find the Virtual Host Mappings section and click Add to map the listener with your default virtual host domain.

    View added listeners

  10. Enter the following values in the respective files to enable HTTPS on your main virtual host domain.

    • Virtual Host: app.example.com
    • Domains: app.example.com
  11. Click Save to apply your new domain mapping changes.

  12. Navigate to the SSL tab.

  13. Edit the SSL Private Key & Certificate section to define your SSL certificate information.

  14. Enter your Let's Encrypt SSL private key path /etc/letsencrypt/app.example.com/privkey.pem in the Private Key File field.

  15. Enter your Let's Encrypt SSL certificate path /etc/letsencrypt/app.example.com/fullchain.pem in the Certificate File field.

    Define SSL certificates

  16. Navigate to Virtual Hosts on the main navigation menu to modify your existing virtual host information.

  17. Edit your app.example.com virtual host.

  18. Click Rewrite within the virtual host configuration page to set up new rewrite rules.

  19. Edit the Rewrite Control section and set Enable Rewrite to Yes. Then, click Save to apply the rewrite changes.

    Enable rewrite rule

  20. Find the Rewrite Rules section and click Edit to set up new rules.

    View rewrite page

  21. Add the following configurations within the Rewrite Rules field. Then, click Save to apply the new rules.

    RewriteCond %{SERVER_PORT} ^80$
    RewriteRule .* https://%{SERVER_NAME}%{REQUEST_URI} [R=301,L]

    Add rewrite rule

  22. Click Graceful Restart in the top right corner of the console to restart the OpenLiteSpeed webserver and apply your configuration changes.

  23. Access your domain in a new web browser window using HTTPS and verify that your connection is encrypted with a valid SSL certificate.

    https://app.example.com

    Test access to an OpenLiteSpeed virtual host domain

Set Up Firewall Rules

FirewallD is available and active on Vultr Rocky Linux 9 servers by default. It blocks all unpermitted network connections and requests on the server. Follow the steps below to set up new firewall rules to allow access to the OpenLiteSpeed web administration console, HTTP, and HTTPS connections on your server.

  1. Start the firewalld service again.

    console
    $ sudo systemctl start firewalld
    
  2. Allow the OpenLiteSpeed port 7080, HTTP port 80, and HTTPS port 443 through the firewall.

    console
    $ sudo firewall-cmd --zone=public --permanent --add-port={80/tcp,443/tcp,7080/tcp}
    
  3. Reload the firewalld configuration to apply the new firewall rules.

    console
    $ sudo firewall-cmd --reload
    
  4. View all allowed ports in the firewall table and verify that your permitted ports are available.

    console
    $ sudo firewall-cmd --list-ports
    

    Output.

    80/tcp 443/tcp 7080/tcp 8088/tcp

Conclusion

You have installed the OpenLiteSpeed webserver on Rocky Linux 9 and created a new virtual host to deliver web applications on your server using the web administration console. OpenLiteSpeed supports multiple virtual hosts and domains you can configure on your server to enable secure encrypted connections using valid SSL certificates. For more information, visit the OpenLiteSpeed documentation.