Reading Mode

Introduction

Many of you probably saw the ads for optimized hosting for WordPress or Woo Commerce websites. Most of the time they are charging 20$ or more per month, some even only give you 20GB to 60GB space and max 2 to 10 WordPress installations per hosting. Well, that’s bullshit, isn’t it?

Kinsta WordPress Hosting Yearly Cost
Kinsta Pricing in 2022

In this article I will show you how to make your server optimised for WordPress. Lets just get into this.

Server Setup

First thing you will need a Server , this method will work only on VPS or Dedicated servers, which you can easily get from Vultr, Linode or frankly any VPS provider. Make sure they give you access to the VPS or Dedicated server via SSH. Typical starting point is 5$ for the basic VPS , if you are just starting and not expecting more than 100 concurrent site visitors, 5$ per month should be a good. Choose Ubuntu Server as your server os.

We will use Openlightspeed server with PHP,MariaDB for optimal performance and ease of use.

Set up for single WordPress Installation

If you are setting up the server for one WordPress Installation, just copy paste and run the below script from ssh of your server and you are pretty much done , You can navigate to Memcached section.

bash <( curl -k https://raw.githubusercontent.com/litespeedtech/ols1clk/master/ols1clk.sh ) -w

Set up for multiple WordPress Installation

Installing Openlightspeed server

In this step, you will install the OpenLiteSpeed web server after importing the required package repositories to your server. If it is your first time using sudo in the SSH session, you may need to enter the password for your non-root user.

Begin by updating the package manager cache:

sudo apt update && sudo apt upgrade -y

Unlike Apache and Nginx, OpenLiteSpeed hosts its code on its own repository. Add this repository to the apt package manager’s sources list with the following command:

sudo wget -O - https://repo.litespeed.sh | sudo bash

Update the list of repositories to ensure that the newly added repository is scanned by the apt package manager:

sudo apt update

Next, install the openlitespeed package:

sudo apt install openlitespeed

Once the installation is complete, verify that OpenLiteSpeed is installed and working correctly by checking its status with the service command:

sudo systemctl status lsws

if everything is ok then we will need to update our firewall.

sudo ufw allow 7080,80,443,8088/tcp

at this point you can check the example page of your server at

http://your_server_ip:8088

To access the Openlightspeed Web Admin run this script:

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

Once you update username & the password, You can explore webadmin at

http://your_server_ip:7080

Installing MariaDB

With the OpenLiteSpeed server running on Linux, you can now set up the MariaDB Database Server. 

Install the MariaDB server with the following command:

sudo apt install mariadb-server -y

After the installation has finished, complete the initial server setup with the following command:

sudo mysql_secure_installation

Finish the initial MariaDB setup

Installing PHP

The OpenLiteSpeed web server comes bundled with one PHP version, which may not be the latest stable version of PHP. You can use the pre-installed version of PHP, or you can install a specific instance. In this step, you will check the version of your PHP installation, update it if necessary, and install the requisite packages.

To know which version of PHP was pre-installed with your OpenLiteSpeed server, click the button in the Test PHP section of the example website or visit the following URL:

http://your_server_ip:8088/phpinfo.php

If there are new php version available then to install a specific lsphp package, use the following command (replacing 81 with the suffix for your preferred version):

sudo apt install lsphp81 lsphp81-{common,mysql,curl,memcached}

Type Y to confirm the installation.

You have only installed the lsphp package, but you have not configured OpenLiteSpeed to use this version of PHP. The example website will continue to show the default PHP version until you configure it to use the new version. In the next step, you will configure OpenLiteSpeed to use this version of PHP. which we will do now.

Setting up Openlightspeed Server

Via http://your_server_ip:7080, log in to the Admin Panel (using the credentials you just set up) and navigate to the Server Configuration section. Then, click the External App tab.

You will see the following screen:

Openlightspeed Dashboard
Openlightspeed Dashboard

Click the edit button in the Actions column of the first row for LiteSpeed SAPI App, which will open an app with the name lsphp. Scroll to the Command field to change its value to lsphp81/bin/lsphp (following the naming convention in Step 4). After configuring this value, scroll to the LiteSpeed SAPI App heading and click the Save button on the right.

Use the Graceful Restart button in the top right to restart the web server. The Graceful Restart button is highlighted in the upper right of the following screencapture:

Openlightspeed server reset
Openlightspeed server reset

Verify that your server is now using the specified PHP version by visiting the informational page at port 8088:

http://your_server_ip:8088/phpinfo.php

The page will now display the specified version number.

In this step, you configured the credentials for the admin panel and set it to use the desired version of PHP. Next, you will set up Virtual Hosts for the different websites that you plan to host on this web server.

Still in the GUI Admin Panel, navigate to the Virtual Hosts section. On the top right corner of the table that appears, click the plus (+) button to add a new Virtual Host.

You can then add a Virtual Host name of your choice to set up the Virtual Host Root and the path for the configuration file of the Virtual Host, using variables such as $SERVER_ROOT (for referring to the root directory of the OpenLiteSpeed Web Server) or $VH_ROOT (for referring to the root directory of the Virtual Host). Click Yes on Enable Scripts/ExtApps to ensure PHP works on the Virtual Host.

When setting up the Virtual Host, complete the following fields with your desired values (the values shown below are examples):

  • Virtual Host Name: MyWebsite
  • Virtual Host Root: $SERVER_ROOT/MyWebsite/html/
  • Config File: conf/vhosts/MyWebsite/vhconf.conf
  • Enable Scripts/ExtApps: Yes
  • Restrained: Yes

You can replace MyWebsite with the domain name you created during the Prerequisites.

Note: You may receive an error if the configuration file does not exist at the specified path. Click the link mentioned in the error message to create the file automatically.

Yes on Enable Scripts/ExtApps allows you to specify a custom PHP interpreter version in the External Apps section of the configuration. It can be turned off if you do not intend to configure a custom PHP version.

Yes on Restrained prevents the users from accessing files in directories other than the ones contained in the Virtual Host Root directory, even if symbolic links are pointing to files outside the Virtual Host root directory. For security purposes, enable this feature.

Virtual Host Configuration

After completing the configuration, click the Save button on the right side of the Virtual Hosts row.

The Admin Panel may display a prompt to perform a Graceful Restart to apply the changes to the configuration. You can perform a Graceful Restart at this point as it will not affect the configuration steps. You can also wait to perform the Graceful Restart after you complete the changes to the Listener configuration.

After configuring the Virtual Host, you will configure the Listener. Navigate to the Listeners section of the Admin Panel. Click the Default listener, then click the plus (+) button in the top right corner of the Virtual Host Mappings table.

From the dropdown corresponding to Virtual Host, select the Virtual Host Name that you assigned in the Virtual Host Configuration. In the example shown, the selected Virtual Host is MyWebsite.

In the text box for a domain name, enter the fully qualified and registered domain name that you will use to serve the Virtual Host that you configured. In the screencapture below, the sample value is set to mywebsite.com, but update it with the value you have used for your_domain.

Listener Configuration

Note: The default listener is configured to listen on port 8088. The port used for HTTP traffic to your site is 80 and, if SSL/TLS encryption is enabled, then your HTTPS website would be expected to listen on port 443. You will need to change the port in the Address Settings of the Listener Configuration to change the port at which the listener listens.

Click Save on the top right of the Virtual Hosts Mapping row.

It is strongly recommended that you enable TLS security for your website. Under the General settings for the Listener, update the Secure option to Yes and change the port from 8088 to 443 for the Listeners that serve HTTPS pages. 443 is the default port for HTTPS. Save the updated address settings.

Because you generated a certificate and key file from a certificate authority during the prerequisites, you can now add them to your OpenLiteSpeed setup. Add the certificate and key file paths in the SSL section of the Listener’s configuration by clicking the Edit icon in the SSL Private Key & Certificate row.

If you followed the guides mentioned in the prerequisite, the certificate and key files generated by Let’s Encrypt will be at the following locations:

  • Private Key File/etc/letsencrypt/live/your_domain.privkey.pem
  • Certificate File/etc/letsencrypt/live/your_domain.fullchain.pem

For certificates generated by Let’s Encrypt, you must set the Chained Certificate option to Yes, as recommended by the official documentation for configuring Let’s Encrypt SSL on OpenLiteSpeed.

A sample configuration for the TLS certificate and key files in the SSL section of the Listener Configuration is shown below (be sure to update the file paths to match your domain):

TLS Configuration for Listener

If you run into any issues, you can review the guide to Configure OpenLiteSpeed for SSL in the OpenLiteSpeed documentation.

After configuring and saving these settings, click the Graceful Restart button on the top right corner of the screen to apply the changes.

You have now configured a Virtual Host with a Listener and set up TLS encryption for all traffic to your website. After configuring your DNS to map to the public IP address of your server, your website will be accessible at the domain you specify.

Enable HTTP/3 over QUIC

Note: OpenLiteSpeed is one of the first open-source servers to incorporate the HTTP3 protocol over Quick UDP Internet Connections (QUIC) Protocol.

To enable HTTP3/QUIC, you must set up SSL for your domain and configure the certificate and key via the Admin Panel. Return to Step 6 for direction.

If you’d like to use HTTP3, you must also allow UDP traffic to port 443 of your server. To do this, run the command:

sudo ufw allow 443/udp

Setting up LSCache

Once all the above option are done, We will need to install WordPress and LSCache. To install wordpress simply download the zip from WordPress website.

Unzip and upload to your Virtual Host root you just created in the above steps. Open the Virtual host address in your browser and go through the installation.

Once Installation is complete , Log in to the Dashboard and navigate to Plugins Section. Click on Add new plugin and the search for LSCache and install it. Dont activate the plugin at this point.

Cache Module Configuration

Lets head back to your Openlightspeed Dashboard and navigate to modules (Server Configuration -> Modules)

Openlightspeed Modules x88
Openlightspeed Module

Click edit button and modify Modules Parameters as the below code

checkPrivateCache   1
checkPublicCache    1
maxCacheObjSize     10000000
maxStaleAge         200
qsCache             1
reqCookieCache      1
respCookieCache     1
ignoreReqCacheCtrl  1
ignoreRespCacheCtrl 0

enableCache         0
expireInSeconds     3600
enablePrivateCache  0
privateExpireInSeconds 3600

Click Save button and gracefully restart the server.

Setting up Memcached

Run the code below to install Memcached

sudo apt install memcached

Default settings should work fine with most of the servers.

Now lets head back to wordpress and finish LSCache Setup…

Activate LSCAche and navigate to LSCache Settings, On the object section turn on object cache, check if extention and connection status are enabled.

LScache Settings WordPress
LSCache Settings

Thats it, Your server is fully optimized for wordpress now.

Categorized in:

Tagged in: