Install OpenLiteSpeed, MariaDB, PHP8.0 on Ubuntu 20.04/18.04 Server

This tutorial is going to show you how to install LOMP stack (OpenLiteSpeed, MariaDB, and PHP8.0) on Ubuntu 20.04/18.04. A software stack is a set of software tools bundled together. LOMP stands for Linux, OpenLiteSpeed, MariaDB/MySQL and PHP, which can power dynamic websites and web applications. Linux is the operating system; OpenLiteSpeed is the web server; MariaDB/MySQL is the database server and PHP is the server-side scripting language responsible for generating dynamic web pages.

Why is OpenLiteSpeed Better Than Apache/Nginx

Previously we discussed how to install LAMP stack (Apache) and LEMP stack (Nginx). Why are we switching to OpenLiteSpeed? Because it’s much more performant.

  • 5X More requests per second.
  • LSAPI allows better PHP performance than mod_PHP and PHP-FPM.
  • Extremely low CPU and memory footprint.
  • HTTP/3. As OpenLiteSpeed focuses on speed, it adopts new technology faster than Nginx does.
  • Built-in PageSpeed and ModSecurity module. If you use Nginx, you have to re-compile these two modules every time you upgrade Nginx.
  • Buil-in page cache integration with popular web applications like WordPress, Magento, Joomla, Prestashop, Opencart, Drupal, xenForo, Laravel, Shopware, and MediaWiki.
  • Anti-DDoS connection and bandwidth throttling.
  • Built-in Brotli compression for static files.
  • Web-based admin panel.

Requirements

To follow this tutorial, you need an Ubuntu 20.04/18.04 OS running on a remote server.

If you are looking for a high-performance VPS (Virtual Private Server), then you can go to ScalaHosting website to create an account. Choose the self-managed Linux VPS plan. Use coupon code linuxbabe2021 on payment page to save $100 if you choose to pay 12 months upfront. You can follow the tutorial linked below to properly set up your Linux VPS server on ScalaHosting.

And if you need to set up LOMP stack with a domain name, I recommend buying domain names from NameCheap because the price is low and they give whois privacy protection free for life.

Step 1: Update Software Packages

Before we install the LOMP stack, it’s a good practice to update repository and software packages by running the following command on your Ubuntu 20.04/18.04 OS.

sudo apt update;sudo apt upgrade

Step 2: Install OpenLiteSpeed Web Server

OpenLiteSpeed isn’t included in the default Ubuntu software repository, so we will have to install it from the upstream official repository. Run the following command to add OpenLiteSpeed repository to your Ubuntu system.

wget -O - http://rpms.litespeedtech.com/debian/enable_lst_debian_repo.sh | sudo bash

The above command will also import the OpenLiteSpeed GPG key to Ubuntu system so that APT can verify package integrity during installation. Then install OpenLiteSpeed with:

sudo apt install -y openlitespeed

After it’s installed, we can enable OpenLiteSpeed to auto-start at boot time by running the following command.

sudo systemctl enable lshttpd

Then start OpenLiteSpeed with this command:

sudo systemctl start lshttpd

Now check its status.

sudo systemctl status lshttpd

Sample output:

 lshttpd.service - OpenLiteSpeed HTTP Server
     Loaded: loaded (/etc/systemd/system/lshttpd.service; enabled; vendor preset: enabled)
     Active: active (running) since Mon 2021-05-31 04:59:06 EDT; 14min ago
   Main PID: 7213 (litespeed)
     CGroup: /system.slice/lshttpd.service
             ├─7213 openlitespeed (lshttpd - main)
             ├─7224 openlitespeed (lscgid)
             ├─7253 openlitespeed (lshttpd - #01)
             └─7254 openlitespeed (lshttpd - #02)

May 31 04:59:04 focal systemd[1]: Starting OpenLiteSpeed HTTP Server...
May 31 04:59:04 focal lswsctrl[7171]: [OK] litespeed: pid=7213.
May 31 04:59:06 focal systemd[1]: Started OpenLiteSpeed HTTP Server.

Enabled” indicates that auto-start at boot time is enabled and we can see that OpenLiteSpeed is running. If the above command doesn’t immediately quit after running. You need to press “q” to make it quit.

Check OpenLiteSpeed version.

/usr/local/lsws/bin/openlitespeed -v

Output:

LiteSpeed/1.6.21 Open
	module versions:
	modgzip 1.1
	cache 1.62
	modinspector 1.1
	uploadprogress 1.1
	mod_security 1.4
 (built: Tue Apr  6 13:20:57 UTC 2021) 
	module versions:
	modgzip 1.1
	cache 1.62
	modinspector 1.1
	uploadprogress 1.1
	mod_security 1.4

By default, OpenLiteSpeed listens on port 8088, we need to make it listening on port 80. Edit the main configuration file with a command-line text editor like Nano.

sudo nano /usr/local/lsws/conf/httpd_config.conf

Find the following lines

listener Default{
    address                  *:8088
    secure                   0
    map                      Example *
}

Change 8088 to 80.

listener Default{
    address                  *:80
    secure                   0
    map                      Example *
}

Save and close the file. Then restart OpenLiteSpeed.

sudo systemctl restart lshttpd

Note: If you have other web servers like Nginx running on the server, you need to stop it, then restart OpenLiteSpeed.

sudo systemctl stop nginx

Now type in the public IP address of your Ubuntu 20.04/18.04 server in the browser address bar. You should see the “Congratulations” Web page, which means OpenLiteSpeed Web server is running properly.

Ubuntu 20.04 openlitespeed

If the connection is refused or failed to complete, there might be a firewall preventing incoming requests to TCP port 80. If you are using iptables firewall, then you need to run the following command to open TCP port 80.

sudo iptables -I INPUT -p tcp --dport 80 -j ACCEPT

If you are using UFW firewall, then run this command to open TCP port 80.

sudo ufw allow http

By default, OpenLiteSpeed web server runs as nobody user and nogroup group. The default document root directory is /usr/local/lsws/Example/html.

Step 3: Install MariaDB Database Server

MariaDB is a drop-in replacement for MySQL. It is developed by former members of MySQL team who are concerned that Oracle might turn MySQL into a closed-source product. Enter the following command to install MariaDB on Ubuntu 20.04/18.04.

sudo apt install mariadb-server mariadb-client

After it’s installed, MariaDB server should be automatically stared. Use systemctl to check its status.

systemctl status mariadb

Output:

 mariadb.service - MariaDB 10.3.29 database server
     Loaded: loaded (/lib/systemd/system/mariadb.service; enabled; vendor preset: enabled)
     Active: active (running) since Fri 2020-04-10 14:19:16 UTC; 18s ago
       Docs: man:mysqld(8)
             https://mariadb.com/kb/en/library/systemd/
   Main PID: 9161 (mysqld)
     Status: "Taking your SQL requests now..."
      Tasks: 31 (limit: 9451)
     Memory: 64.7M
     CGroup: /system.slice/mariadb.service
             └─9161 /usr/sbin/mysqld

If it’s not running, start it with this command:

sudo systemctl start mariadb

To enable MariaDB to automatically start at boot time, run

sudo systemctl enable mariadb

Now run the post installation security script.

sudo mysql_secure_installation

When it asks you to enter MariaDB root password, press Enter key as the root password isn’t set yet. Then enter y to set the root password for MariaDB server.

ubuntu 20.04 install LEMP stack

Next, you can press Enter to answer all remaining questions, which will remove anonymous user, disable remote root login and remove test database. This step is a basic requirement for MariaDB database security. (Notice that Y is capitalized, which means it is the default answer. )

How-to-Install-LEMP-stack-on-Ubuntu-20.04

By default, the MaraiDB package on Ubuntu uses unix_socket to authenticate user login, which basically means you can use username and password of the OS to log into MariaDB console. So you can run the following command to login without providing MariaDB root password.

sudo mariadb -u root

To exit, run

exit;

Check MariaDB server version information.

mariadb --version

As you can see, we have installed MariaDB 10.3.29.

mariadb  Ver 15.1 Distrib 10.3.29-MariaDB, for debian-linux-gnu (x86_64) using readline 5.2

Step 4: Install PHP8.0

When we install OpenLiteSpeed, it automatically installs the lsphp73 package, which is a PHP 7.3 build made for OpenLiteSpeed. We can install PHP8.0 with the following command.

sudo apt install lsphp80 lsphp80-mysql lsphp80-common lsphp80-opcache lsphp80-curl

Check the version number.

/usr/local/lsws/lsphp80/bin/php8.0 -v

Sample output:

PHP 8.0.6 (cli) (built: May  7 2021 15:17:48) ( NTS )
Copyright (c) The PHP Group
Zend Engine v4.0.6, Copyright (c) Zend Technologies
    with Zend OPcache v8.0.6, Copyright (c), by Zend Technologies

Although we installed just 5 PHP8.0 packages, the OpenLiteSpeed PHP build ships with many PHP modules. You can check enabled PHP modules with the following command.

/usr/local/lsws/lsphp80/bin/php8.0 --modules

Step 5: Test PHP

There’s a phpinfo.php file under /usr/local/lsws/Example/html directory, so you can enter server-ip-address/phpinfo.php in the browser address bar to test PHP with OpenLiteSpeed Web server, Replace sever-ip-address with your actual IP.

You should see your server’s PHP information. This means PHP scripts can run properly with OpenLiteSpeed web server. They are connected via the LiteSpeed API (LSAPI).

OpenLiteSpeed PHP LSAPI

Congrats! You have successfully installed OpenLiteSpeed, MariaDB and PHP on Ubuntu 20.04/18.04. You can see that OpenLiteSpeed uses PHP7.3 per default. To change the PHP version, you need to use the admin panel.

Step 5: Configure the Admin Panel

Set a username and password for the admin panel.

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

openlitespeed admin panel username password ubuntu 20.04

Then you can access the admin panel at https://server-ip-address:7080/login.php. By default it’s using a self-signed TLS certificate, so you need to add a security exception in your web browser.

  • In Firefox, click Advanced and click “Accept the risk and Continue
  • In Google Chrome, click Proceed to your-server-ip(unsafe) .

openlitespeed admin panel login

Switching to PHP8.0 in the Admin Panel

To make the default virtual host use PHP8.0, first we need to enable PHP8.0 at the server leve.  Go to Server Configuration -> External App, and click the + button to add a new external app.

openlitespeed server level external app php

Select LiteSpeed SAPI App as the type and click the Next button.

litespeed SAPI app for PHP

Enter the following information:

  • Name: lsphp8.0
  • Address: uds://tmp/lshttpd/lsphp80.sock
  • Max Connections: 10
  • Environment: PHP_LSAPI_CHILDREN=10
    LSAPI_AVOID_FORK=200M
  • Initial Request Timeout (secs): 60
  • Retry Timeout (secs): 0
  • Persistent Connection: Yes
  • Response Buffering: No
  • Command: lsphp80/bin/lsphp
  • Backlog: 100
  • Instances: 1
  • Priority: 0
  • Memory Soft Limit (bytes): 2047M
  • Memory Hard Limit (bytes): 2047M
  • Process Soft Limit: 1400
  • Process Hard Limit: 1500

openlitespeed external app lsphp8.0

Save the settings. Then go to Virtual Hosts -> Example ->  Script Handler tab and click the + button to add a new script handler.

openlistspeed script handler

Enter the following information:

  • Suffixes: php
  • Handler Type: LiteSpeed SAPI
  • Handler Name: lsphp8.0

openlitespeed script handler php8.0

Save the settings. Then click the Graceful Restart button at the upper-left corner for the changes to take effect. Now enter server-ip-address/phpinfo.php in the browser address bar to test PHP with OpenLiteSpeed Web server. You should see that the default virtual host is now using PHP8.0.

openlitespeed multiple PHP versions

Notes

After using OpenLiteSpeed for a while, I tried to switch back to Nginx just for testing. It’s strange that some of the PHP modules are no longer enabled. It’s not clear if it’s because of OpenLiteSpeed. I had to edit /etc/php/7.4/cli/php.ini and /etc/php/7.4/fpm/php.ini to enable the missing modules, including mysqlnd, mysqli, mbstring, gd, json, etc.

On a normal installation of LEMP stack, I don’t have to edit the php.ini file to enable PHP modules, but in this situation, I had to edit this file. An easy way to enabel all necessary modules is to run the following two commands:

cat /etc/php/7.4/mods-available/* | sudo tee -a /etc/php/7.4/fpm/php.ini
cat /etc/php/7.4/mods-available/* | sudo tee -a /etc/php/7.4/cli/php.ini

Closing

I hope this tutorial helped you install LOMP stack on Ubuntu 20.04/18.04 LTS. As always, if you found this post useful, then subscribe to our free newsletter to get more tips and tricks. Take care 🙂

Rate this tutorial
[Total: 5 Average: 5]

9 Responses to “Install OpenLiteSpeed, MariaDB, PHP8.0 on Ubuntu 20.04/18.04 Server

  • Frank Aguirre
    3 years ago

    Muchas gracias por compartir, seria excelente un ejemplo con SSL

  • Gerardo Montivero (gerMdz)
    3 years ago

    Good afternoon. What is the cost of OpenLiteSpeed?
    Can the mail servers of your tutorials be installed with this LOMP stack?
    From now on, thank you very much for your tutorials

  • Gerardo Montivero (gerMdz)
    3 years ago

    As we are used to, Xiao, good tutorial.
    I wanted to know what configurations I should make to have a working mail server, like the ones you have explained in other tutorials.

  • Hello sir, I loved your blog this is awesome. Every post is priceless here…Sir i need some help in something i tried a lot but didn’t got the solution… I want to create a Ahref Group Buying PHP script… for this i started learning php but it seems like it will take a lot time… I have come with some php script which stopped working suddenly… please help me to repair it… i really need your help… Drop a mail or reply to my comment sir…

    • Xiao Guoan (Admin)
      3 years ago

      I don’t know your exact situation. Maybe you need to re-enable the PHP modules with the following commands.

      cat /etc/php/7.4/mods-available/* | sudo tee -a /etc/php/7.4/fpm/php.ini
      
      cat /etc/php/7.4/mods-available/* | sudo tee -a /etc/php/7.4/cli/php.ini
      
      sudo systemctl restart php7.4-fpm
      

      Replace PHP7.4 with your own version of PHP.

  • Thank You sir. Sir, please kindly have a look at the script. It’s a open source script and available on github. Here is the link https://github.com/heiswayi/web-proxy-script

  • Hello!

    Very interesting tutorial. Congratulations.

    What are the server minimum requirements for LOMP?

    thanks in advance.

    • Hi,
      In my experience, LOMP stack will run fine on a basic server configuration with 1 GB RAM and 1 vCPU. For example, a $5 drop Digital Ocean.

Leave a Comment

  • Comments with links are moderated by admin before published.
  • Your email address will not be published.
  • Use <pre> ... </pre> HTML tag to quote the output from your terminal/console.
  • Please use the community (https://community.linuxbabe.com) for questions unrelated to this article.
  • I don't have time to answer every question. Making a donation would incentivize me to spend more time answering questions.

The maximum upload file size: 2 MB. You can upload: image. Links to YouTube, Facebook, Twitter and other services inserted in the comment text will be automatically embedded. Drop file here