How to Install OpenLiteSpeed, PHP 7.2, MariaDB on Ubuntu 18.04?

How to Install OpenLiteSpeed, PHP 7.2, MariaDB on Ubuntu 18.04?

If you just installed the VPS then it will be better if we run the update check and upgrade it before we start to install any web server or application into our server.

ubuntu-18-04-status-update

sudo apt-get update
sudo apt-get upgrade

Install OpenLiteSpeed Web Server

We could get the latest version of ‘OpenLiteSpeed’ web server by downloading it through wget command. Please follow below command to download ‘OpenLiteSpeed’ into your VPS.

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

After downloading completed, now you could install the openlitespeed (OLS) webserver using apt-install command like below example:

apt-get install openlitespeed

When the installation completed, you could now start and see the status of openlitespeed service using the syntax ‘systemctl’, please refer below example for complete syntax command:

systemctl start lsws

systemctl status lsws

if you would like to re-confirm that OpenLiteSpeed is running or now then you could use below command to verify it:

netstat -antelope | grep openlitespeed

open-port-for-openlitespeed

As above picture, we could see if OpenLiteSpeed has two open ports which by default was required to access the web server. These ports are 8080 as default HTTP port and 7080 as accessing administrator dashboard page.
We could enable and update firewall setting to increase the security in our OLS web server. You could easily add both ports ‘8088’ and ‘7080’ on the firewall using below command:
ufw allow ssh
ufw allow http
ufw allow https
ufw allow 8088/tcp
ufw allow 7080/tcp
sudo ufw enable
sudo ufw reload

Then, you could try to access the administrator dashboard by browsing it using chrome/firefox/internet explorer or any your favorite browser. Type your IP address https://your-vps-ip-address:7080

non-secure-access-of-openlite-dashboard

Your browser page will look like the above picture, that warning above could be ignored for now since we don’t have any SSL certificate installed yet on our server. Don’t worry! Click ‘Process to your-vps-ip-address (unsafe)’ to open your OLS dashboard page.

Don’t be happy yet, we still not finish for our task to make the OpenLiteSpeed webserver to be ready for your WordPress site. We will come back to OpenLiteSpeed dashboard when we will configure for the domain and its settings.

Install PHP 7.2 for OpenLiteSpeed Web Server

OpenLiteSpeed requires a custom package of PHP that called ‘lsphp’ to enable PHP works on OpenLiteSpeed webserver. To begin installing PHP 7.2 for OpenLiteSpeed and its related module that might be required for our application or WordPress, You could follow below command syntax:

sudo apt install lsphp72 lsphp72-curl lsphp72-imap lsphp72-mysql lsphp72-intl lsphp72-pgsql lsphp72-sqlite3 lsphp72-tidy lsphp72-snmp

If you still require more module that was not installed by above command, then you could found all PHP 7.2 modules by running below command:

apt-cache search lsphp72

Then you could install any module that you required by the commandapt install.

Install MariaDB

On this tutorial article, we will choose MariaDB over MySQL due MariaDB offers better performance and other things that we will discuss it in this article. If you’re interested why we need to choose MariaDB over MySql maybe you could read this article: “10 reasons to migrate to MariaDB (if still using MySQL).

You could run below command to start installing MariaDB into your VPS:

sudo apt install mariadb-server

After MariaDB completely installed in your server, then you should secure your database like give a password for ‘root’ user, remove anonymous users, disallowing root login remotely and delete any test table. This well helps your site from hacking attacks that might happen in the future. To start hardening your MariaDB installation then you could run below command:

sudo mysql_secure_installation

 There’s a caveat with root password setting in MariaDB which by default allows ‘root’ user to login into MariaDB without giving any password. And, this might be required to fix it if you planning to install 3rd party application that required a password entry for ‘root’ user access like ‘PHPMyAdmin’.

 To disable the authentication plugins and forcing the ‘root’ user to enter the password everytime access the MariaDB we could run below steps:

1. You need to login into MariaDB as ‘root’ user

sudo mysql -u root

2. You need to disable the ‘authentication’ plugins by run below MySQL command:

use mysql;
update user set plugin='' where User='root';
flush privileges;
exit

3. Restart the MariaDB Service.

sudo systemctl restart mysql

4. Test to login into MariaDB using ‘root’ user. You require to fill the password that you setup initially whey you secure/hardening your MariaDB installation.

sudo mysql -u root -p

 Configure Your OpenLiteSpeed (OLS) Web Server

Your OLS webserver is ready to deploy any your web application like PHP website, WordPress, Joomla, etc. But, since you did not bind your web server to any domain name then you could only access the webserver directly using your VPS IP Address.

Of course, using the IP address for accessing your website or web application was not practicable. People will difficult to remember your IP address if then wanted using your web-apps or website and of course you could not get benefit from SEO.

To bind your webserver into one domain name or multiple domains name, similar like Apache or Nginx, you need to configure virtual host configuration in your OLS web server. You could start to configure your OLS Webserver by login into Web control panel. The default username and password will be username is “admin” and password is “123456”.

login-to-openlitespeed-dashboard

As a best practice, you should change the default of ‘admin’ user’s password. To change the ‘admin’ user’s password, you could go to “WebAdmin Settings” then select “Users” tab. Select the ‘edit’ icon button in the row of ‘admin’ users to change the password. Type your old password “12345” and enter your new password. Don’t forget to save your changes by clicking the “Save” icon button in the right top of the “WebAdmin Console User” window.

change-user-password-in-OLS-dashboard

Configure ‘Server Configuration’

After you change the password, the second steps that you should do is configure the ‘Server Configuration’. You could start reconfigure your server by select “Server Configuration” in shortcut menu of your OpenLiteSpeed’s dashboard. Select your “External App” tab and follow below configuration:

Parameter Settings
Name lsphp72
Address uds://tmp/lshttpd/lsphp.sock
Max Connection 35
Environment

PHP_LSAPI_MAX_REQUEST=500

PHP_LSAPI_CHILDREN=35

Command

$SERVER_ROOT/lsphp72/bin/lsphp

openlitespeed-with-php7.2-server-configuration

After you complete the ‘External App’ configuration then set the configuration in ‘Script Handlers’ tab. Please follow below configuration:

Parameter Setting
Suffixes php
Handler Type LiteSpeed SAPI
Handler Name lsphp72

scri[t-handlers-in-server-configuration

You could save the configuration and do ‘Graceful Restart’ on your OpenLiteSpeed web server dashboard.

Configure Virtual Host for Your Domain

To complete the OLS web server configuration, select ‘Virtual Hosts’ from the menu of left dashboard. There’s a default configuration which called “Example” when you first install the OLS webserver. You could edit the ‘Example’ configuration or create new virtual host configuration. In our case, we just re-configure the ‘Example’ config to our domain name.

Select ‘edit’ icon button on the ‘Example’ row and follow below configuration for your setting:

Parameter Setting Example
‘Basic’ Tab
Virtual Host Name your-domain-name.tld neufunn.com
Virtual Host Root $SERVER_ROOT/your-domain-name/ $SERVER_ROOT/neufunn.com/
Config File $SERVER_ROOT/conf/vhosts/your-domain-name/vhconf.conf $SERVER_ROOT/conf/vhosts/ neufunn.com/vhconf.conf
‘General’ Tab
Document Root $VH_ROOT/html-files-location/ $VH_ROOT/html/
Domain Name your-domain-name.ltd neufunn.com
Use Server Index Files No  
Index Files index.php  
Auto Index No  
‘Log’ Tab
Use Server’s Log No  
File Name $SERVER_ROOT/your-domain-name/directory-location/File-Name.ext $SERVER_ROOT/neufunn.com/logs /errors.log
Log Level Error  
Rolling Size (bytes) 10M  
Log Control Own Log File  
File Name $SERVER_ROOT/your-domain-name/directory-location/File-Name.ext $SERVER_ROOT/neufunn.com/logs /access.log
Log Headers Referrer, UserAgent, Host  
Keep Days 90  

 After you complete the ‘Virtual Host’ configuration then you need to set up the Listeners configuration. Map your virtual host to your-domain-name.ltd in this configuration page. Please see below the screenshot for your example.

OpenLiteSpeed-Listeners-Setting

Save your configuration. On your linux/ubuntu console, please run below command to create the needed directories as your already define on above steps.

mkdir /usr/local/lsws/neufunn.com
mkdir /usr/local/lsws/neufunn.com/logs
/usr/local/lsws/neufunn.com/html

After directories have created, then do ‘Graceful Restart’ on your OpenLiteSpeed web servers.

You could try to create a test page like phpinfo to test if your configuration was correct. You could follow below steps to create it:

sudo nano /usr/local/lsws/neufunn.com/html/phpinfo.php

on text editor then we could write:

<?php

phpinfo();

?>

And then exit and save the file. You could open you browser and type your domain and phpinfo.php which in this example is http://www.neufunn.com/phpinfo.php

Your OpenLiteSpeed webserver is ready for your next web project. 

Leave a Comment

Malcare WordPress Security