How to Install and Configure OpenLiteSpeed with PHP 7.4 on CentOS 8

OpenLiteSpeed is an open-source HTTP server developed by LiteSpeed Technologies. It is a high-performance and lightweight HTTP server with a web-based GUI for administration.

OpenLiteSpeed can handle more than a hundred thousand concurrent connections with low resource consumption (CPU and RAM) and supports many operating systems such as Linux, Mac OS, FreeBSD, and SunOS. The server can be used to run web page scripts written in PHP, Ruby, Perl, and Java.

In this tutorial, we will show you how to install OpenLiteSpeed with the MariaDB database and the current PHP 7.4 on the current CentOS 8 server.

Prerequisites

For this guide, we will be using the latest CentOS 8 server with 2GB of RAM, 25GB free disk space, and 2 CPUs.

What we will do:

  • Install OpenLiteSpeed
  • Install PHP 7.4 OpenLiteSpeed Version
  • Install MariaDB Database
  • Setup OpenLiteSpeed Admin
  • Configure OpenLiteSpeed with PHP 7.4
  • Running OpenLiteSpeed on Port 80
  • Testing

Step 1 - Install OpenLiteSpeed

First, we will add the openliteSpeed repository and install the OpenLiteSpeed web server from it.

Add the OpenLiteSpeed repository for CentOS 8 using the command below.

rpm -Uvh http://rpms.litespeedtech.com/centos/litespeed-repo-1.1-1.el8.noarch.rpm

After that, check all available repository on the CentOS system.

dnf repolist

And you will get the result as below.

Check repositories with dnf

As a result, you've added the OpenLiteSpeed repository to the CentOS 8 system.

Now install the OpenLiteSpeed package using the dnf command below.

sudo dnf install openlitespeed

Once the installation is complete, start the OpenLiteSpeed service and add it to the system boot.

systemctl start lsws
systemctl enable lsws

Now check the openlitespeed service.

systemctl status lsws

OpenLitespeed is up and running on the CentOS 8 system.

Start OpenLitespeed on CentOS

As a result, you've installed the openlitespeed web server to the CentOS 8 server.

Step 2 - Install PHP 7.4

After installing the openlitespeed web server, we will install the latest PHP 7.4 for the openlitespeed called 'LSPHP' or (LSAPI and PHP).

Before installing PHP 7.4 packages, add the EPEL repository to the system.

sudo dnf install epel-release

After that, install LSPHP packages from the official OpenLitespeed repository using the following command.

sudo dnf install lsphp74 lsphp74-mysqlnd lsphp74-process lsphp74-mbstring lsphp74-mcrypt lsphp74-gd lsphp74-opcache lsphp74-bcmath lsphp74-pdo lsphp74-common lsphp74-xml

Once the installation is complete, check the PHP sock file using the netstat command below.

netstat -pl | grep lsphp

And the PHP 7.4 for OpenLitespeed is up and running.

Check lsphp

As a result, you've installed PHP 7.4 packages for openlitespeed web server.

Step 3 - Install MariaDB

In this step, we will install the MariaDB server and set up its root password.

Install the MariaDB server using the dnf command below.

sudo dnf install mariadb mariadb-server

Once the installation is complete, start the MariaDB service and add it to the boot time.

systecmtl start mariadb
systemctl enable mariadb

Now the MariaDB service is up and running.

Next, we will set up the root password for the database server. And we will use the 'mysql_secure_installation' command-line tool for it.

Installing MariaDB

Run the 'mysql_secure_instalaltion' command below.

mysql_secure_installation

Now type the root password and type 'Y' for the rest of all configuration.

Set a root password? [Y/n] Y
Remove anonymous users? [Y/n] Y
Remove test database and access to it? [Y/n] Y
Reload privilege tables now? [Y/n] Y

And the configuration MariaDB root password is completed.

Now log in to the MySQL shell using the root user as below.

mysql -u root -p
Type Your Root Password:

Once you've logged in, check the user on the MariaDB system using the following query.

select User, Password, Host from mysql.user;

And you will get the result as below.

Set MySQL root password

As a result, you've successfully installed the MariaDB database server and set up the root password authentication for it.

Step 4 - Setup Admin Authentication

OpenLiteSpeed provides a web-based dashboard for managing its configuration.

In this step, we will open port '7080' on the firewalld rules and set up the user and password authentication for the OpenLiteSpeed dashboard.

By default, the openlitespeed dashboard is running on port '7080'. And we will add the port '7080' to the firewalld.

Add port '7080' to the firewalld rules and reload the service using the 'firewall-cmd' command below.

firewall-cmd --add-port=7080/tcp --permanent
firewall-cmd --reload

And you've added the OpenLitespeed dashboard port '7080' to the CentOS firewalld.

Next, we will set up the OpenLitespeed dashboard authentication.

Go to the '/usr/local/lsws/admin/misc' directory and run the 'admpass.sh' script.

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

Type your admin user and password, and you've set up the authentication for the OpenLitespeed admin dashboard.

Protect OpenLitespeed admin dashboard

Now open your web browser and type the server IP address followed by the port '7080' on the address bar.

https://10.5.5.25:7080/

Log in with your user and password.

Login to OpenLitespeed

Once the user and password are correct, you will get the OpenLitespeed admin dashboard as below.

OpenLitespeed admin dashboard

As a result, you've successfully setup the openlitespeed admin authentication.

Step 5 - Configure OpenLiteSpeed with PHP 7.4

In this step, we will set up the PHP 7.4 for the OpenLiteSpeed using the web-based administration.

On the OpenLiteSpeed dashboard, click the 'Server Configuration' menu on the left and click the 'External App' tab.

Configure OpenLiteSpeed with PHP 7.4

To add the new PHP 7.4 configuration, click the add '+' button on the right.

For the type, choose the 'LiteSpeed SAPI App' and click the 'Next' button.

LiteSpeed SAPI App

Now type details configuration as below.

Name: lsphp74
Address: uds://tmp/lshttpd/lsphp.sock
Notes: lsphp74 for OpenLiteSpeed
Max Connections: 35
Initial Request Timeout (secs): 60
Retry Timeout (secs): 0
Command: $SERVER_ROOT/lsphp74/bin/lsphp

And click the 'Save' button, and the PHP 7.4 configuration has been added.

PHP 7.4 configuration

Next, we will change the default PHP for OpenLiteSpeed to the PHP 7.4 version.

On the 'Server Configuration' menu, click the 'Script Handler' tab.

Script Handler

Now click the 'Edit' button on the action section.

On the 'Handler Name', choose the 'lsphp74' that we just added and click the 'Save' button.

lsphp74

And as a result, you've added and enabled the PHP 7.4 configuration for OpenLiteSpeed.

PHP 7.4 configuration for OpenLiteSpeed

Step 6 - Running OpenLiteSpeed on Port 80

By default, the OpenLiteSpeed is running on default port '8088'. To run the OpenLiteSpeed on default http port '80', we can use the administration dashboard to change the configuration.

In this step, we will add the HTTP and HTTPS service to the firewalld services list and set up the OpenLitespeed to run on the http port '80'.

Add the HTTP and https services to the firewalld using the following command.

firewall-cmd --add-service=http --permanent
firewall-cmd --add-service=https --permanent

Now reload the firewalld.

firewall-cmd --reload

And you've added the HTTP and HTTPS services to the firewalld.

Configure Firewalld

Next, back to the OpenLitespeed admin dashboard on your web browser and click the 'Listener' menu on the left.

OpenLitespeed Listeners

On the 'Default' listeners, click the 'view' button.

On the 'Address Settings' section, click the 'edit' button on the right side.

Address Settings

Now change the port to the default HTTP port '80' and click the 'Save' button.

Configure http port

And the default OpenLiteSpeed port has been changed to default HTTP port '80'.

Now click the restart button and the OpenLiteSpeed service will be restarted.

Restart Server after changing the configuration

As a result, the OpenLiteSpeed is now running on default HTTP port '80'.

Step 7 - Testing

Open your web browser and type the server IP address on the address bar.

http://10.5.5.25/

And you will get the default index page of OpenLiteSpeed.

OpenLitespeed installed successfully

Next, we will test the PHP configuration and make sure it works.

On the 'Test PHP' section, click the button 'click here'.

And you will get the phpinfo page as below.

PHP info on OpenLitespeed

As a result, you've installed the OpenLiteSpeed web server with the MariaDB database and PHP 7.4 on CentOS 8 Server.

Reference

Share this page:

5 Comment(s)