6.19 Installing and Initially Setting Up OpenLiteSpeed on a Clean Server
OpenLiteSpeed is a lightweight and highly efficient open source web server designed to run dynamic and static web applications. It is a faster and more flexible option than traditional web servers such as Apache and Nginx due to its built-in HTTP/3 support, as well as caching and request processing technology. In this article, we will look at how to install and configure OpenLiteSpeed on a clean virtual server with Ubuntu 22.
Advantages of OpenLiteSpeed:
- High performance when serving static files.
- Built-in support for HTTP/2 and HTTP/3.
- Optimized for working with PHP (LiteSpeed SAPI module).
- Easy to configure and use via a web interface.
Cons of OpenLiteSpeed:
- The open source version has limited capabilities compared to the commercial one (for example, a limit on the number of simultaneous connections).
- Somewhat difficult to configure in case of using more complex configurations.
- Limited community support compared to Nginx or Apache.
Server preparation
Important: OpenLiteSpeed should only be installed on a clean server. Already during the preparation process, it is necessary to remove other web servers, which will lead to complete inoperability of the running server and all your sites.
Before installing OpenLiteSpeed, it is important to make sure that there are no conflicting services on the server and that the system is updated.
Check if Nginx or Apache are installed on the server, and if so, stop them to avoid conflicts with OpenLiteSpeed.
- To check the status of Nginx and Apache, run the following commands:
systemctl status nginx
systemctl status apache2
- If either service is running, stop it:
sudo systemctl stop nginx
sudo systemctl stop apache2
- If you don’t plan to use Nginx or Apache, you can remove them:
sudo apt-get remove --purge nginx apache2
sudo apt-get autoremove
This will minimize potential conflicts in the future.
Tip: Before installing new software, it is always a good idea to update packages:
sudo apt-get update
sudo apt-get upgrade
The server is now ready to install OpenLiteSpeed.
Step-by-step installation instructions
1. Now let’s install OpenLiteSpeed. The command below will download the installation script to your server:
wget -O - https://repo.litespeed.sh | sudo bash
2. The following command initiates the installation process:
sudo apt-get install -y openlitespeed
3. After installation, run OpenLiteSpeed:
sudo systemctl start openlitespeed
4. To make sure the server is running, check its status:
sudo systemctl status openlitespeed
5. To automatically start OpenLiteSpeed at system boot, enable it with the following command:
sudo systemctl enable openlitespeed
Now OpenLiteSpeed will run automatically after server reboot.
Configuration
Accessing the web interface
After installing OpenLiteSpeed, you need to access its web interface for further configuration.
The first time you connect, you will need to enter your username and password. By default, the login is admin, and you need to set the password manually. To do this, run the command:
sudo /usr/local/lsws/admin/misc/admpass.sh
The OpenLiteSpeed web interface is available on port 7080. To connect, open your browser and go to:
http://<your-server-ip>:7080
The panel interface looks like this:
You will then be prompted to enter a new password for the administrator account. Make sure to choose a strong password.
Setting up a virtual host
Now you need to set up a virtual host for your site.
Go to the OpenLiteSpeed web interface (http://<your-server-ip>:7080
).
Select Virtual Hosts in the menu and click Add:
Specify the host name (e.g. test.com
) and the path to the root directory where your site will be stored:
Make sure you have specified the correct path to the folder with your site. It is also important to add the domain that the virtual host will work with in the OpenLiteSpeed settings.
Please note: after making changes to the configuration, the panel will ask you to perform a Graceful Restart. You can do this in the panel itself by clicking the following button:
PHP Configuration
OpenLiteSpeed supports PHP via the LiteSpeed SAPI module. You need to configure PHP to work with your site.
First, let’s install the required PHP version. This can be done in the panel, in the Compile PHP tab in the Tools section:
Select the desired version, make changes to the configuration if necessary and click Next after each step is successfully completed:
After that, activate the desired PHP version in the OpenLiteSpeed settings. This can be done through the web interface in the PHP section.
To configure PHP, you can change parameters such as memory_limit
, upload_max_filesize
, in the PHP configuration. To do this, edit the php.ini
file, which can be found in the /usr/local/lsws/lsphpX.X/etc/
folder.
Example of changing the parameter:
memory_limit = 128M
upload_max_filesize = 50M
After that, restart OpenLiteSpeed manually or using the panel:
sudo systemctl restart openlitespeed
This will complete the PHP configuration.
Opening ports in UFW/iptables
In order for OpenLiteSpeed to be accessible from the outside, you need to make sure that the appropriate ports are open in your firewall. OpenLiteSpeed typically uses ports 80 (HTTP) and 443 (HTTPS).
UFW
Open ports with:
sudo ufw allow 80,443/tcp
sudo ufw reload
iptables
Open ports with:
sudo iptables -A INPUT -p tcp --dport 80 -j ACCEPT
sudo iptables -A INPUT -p tcp --dport 443 -j ACCEPT
Let’s Encrypt SSL Installation
For a secure connection, let’s set up SSL via Let’s Encrypt.
1. Install Certbot to automatically obtain and install SSL certificates:
sudo apt-get install certbot
2. Obtain a certificate for your domain, replacing test.com
with your actual domain:
sudo certbot certonly --standalone -d test.com
3. Once you have the certificate, configure OpenLiteSpeed to use it. In the OpenLiteSpeed web interface, go to the Listeners section, select SSL and specify the paths to the certificate and private key:
SSL Certificate File: /etc/letsencrypt/live/test.com/fullchain.pem
SSL Private Key File: /etc/letsencrypt/live/test.com/privkey.pem
Save the changes and restart OpenLiteSpeed:
sudo systemctl restart openlitespeed
Your site should now work over HTTPS.
Testing and Finishing Up
Once you’ve finished setting up your server and installing your SSL certificate, it’s important to check that everything is working correctly. There are several commands and tools you can use to do this.
- Check the OpenLiteSpeed status to make sure the server is running:
sudo systemctl status openlitespeed
The status should be active (running)
.
- You can also check if the server is running using the curl command:
curl -I http://test.com
The response should be something like:
HTTP/1.1 200 OK
Server: OpenLiteSpeed
Date: ...
Content-Type: text/html; charset=UTF-8
If everything is OK, the server is responding.
- To check if HTTPS is working, run:
curl -I https://test.com
The response should include a 200 OK code and the use of SSL.
Go to your browser and open your site to make sure it is accessible via both HTTP and HTTPS. Make sure the SSL certificate is installed correctly and the site is secure.
Conclusion
Once the site is up and running, you can perform additional optimizations, such as setting up caching or changing the server configuration. OpenLiteSpeed makes it easy to enable various caching mechanisms, such as LSCache for PHP, which significantly speeds up page loading.
To do this:
- Enable LSCache in the virtual host settings.
- Configure its parameters for your content type (e.g. for static files or dynamic content).
- Test the caching to make sure it is working correctly and improving performance.
This completes the installation and basic setup of OpenLiteSpeed. If needed, you can configure additional features such as anti-DDoS protection, additional modules, or integration with other services.
It is recommended to periodically check for OpenLiteSpeed updates and keep the system up to date. You can also continue optimizing by setting up caching and other improvements.