Skip to content

Deploying OpenLiteSpeed on AlmaLinux 9 (production-ready)

Stand up a hardened OpenLiteSpeed web server on AlmaLinux 9 — LSCache, PHP 8.2 LSPHP, WordPress vhost skeleton, admin behind firewall, Let's Encrypt TLS.

You install OpenLiteSpeed for the WordPress speed story — LSCache is genuinely faster than fpm-on-nginx for warm pages, and the WebAdmin console makes the first vhost feel easy. Six months later, the WebAdmin is still on :7080 open to the internet (because the default install does that), the LSCache module was enabled but the WordPress site never had LiteSpeed Cache plugin installed so nothing is actually being cached, the certbot job that fetches Let’s Encrypt certs lives in a hand-written cron and ran once, and the LSPHP worker has been pinned at its default Mem Soft Limit of 256MB while the site memory profile needs 384.

What’s happening

A production OpenLiteSpeed deployment needs the WebAdmin firewalled (bound to a private interface or restricted by source IP), the default admin password rotated on first install, LSCache plus the matching WordPress plugin actually wired to cache /wp-content/cache/ from disk, a real Let’s Encrypt automation path (the bundled acme.sh or system certbot with a deploy-hook that touches /usr/local/lsws/conf/serial.no), a PHP handler whose memory and timeout match the workload (LSPHP’s Mem Soft/Hard Limit is a hard cap — not a hint), gzip/brotli enabled at the listener, request-id propagation for the upstream WordPress plugin, and an access log that’s a file you can grep — not just journald. The admin console is a footgun: anyone who scans :7080 can try the default credentials.

How to verify

After install, the listeners should look like this:

ss -lntp | grep -E ':(80|443|7080)\b'
# 0.0.0.0:80      lshttpd
# 0.0.0.0:443     lshttpd
# 127.0.0.1:7080  lshttpd  (WebAdmin, localhost only; tunnel via SSH)

OpenLiteSpeed config must parse before reload:

/usr/local/lsws/bin/lswsctrl -t

A curl -I against the vhost should show the LSCache header and HSTS:

curl -sI https://example.com/ | grep -iE 'strict-transport|x-litespeed-cache|server'

And the cert chain should be Let’s Encrypt production, not staging:

openssl s_client -connect example.com:443 -servername example.com </dev/null 2>/dev/null \
  | openssl x509 -noout -issuer -dates

If X-LiteSpeed-Cache is absent on the second hit (cache miss is normal once), if the WebAdmin answers on 0.0.0.0:7080, or if getenforce reports Permissive, the install is not done yet.

The fix

Save the script below as /root/setup-openlitespeed-alma9.sh, then run it. It performs the full installer flow on a fresh AlmaLinux 9 VM: base update + EPEL, installs OpenLiteSpeed and LSPHP 82 from the official repo, hardens SSH while keeping the root key, configures firewalld for 22/80/443 plus the WebAdmin only from a trusted subnet (or localhost), applies sysctl tuning relevant to a high-concurrency web server, writes a WordPress-flavoured vhost skeleton with LSCache + gzip/brotli + request-id, binds WebAdmin to 127.0.0.1:7080 and rotates the admin password to a value you provided, fetches a Let’s Encrypt cert via the bundled acme.sh, installs a deploy hook that reloads LSWS, raises LimitNOFILE to 200000 in a systemd override, validates the config, and waits for both public listeners before continuing.

#!/usr/bin/env bash
set -euo pipefail

### AlmaLinux 9 OpenLiteSpeed installer
### WordPress-ready vhost skeleton with LSCache
### WebAdmin bound to 127.0.0.1:7080 (use SSH tunnel)
### TLS via Let's Encrypt HTTP-01 (acme.sh)
### No local backups; assumes VM-level backup
### Reboot remains manual

if [[ "$(id -u)" -ne 0 ]]; then
  echo "Run as root."
  exit 1
fi

: "${PRIMARY_DOMAIN:?Set PRIMARY_DOMAIN=example.com before running}"
: "${ACME_EMAIL:?Set ACME_EMAIL=ops@example.com before running}"
: "${ADMIN_USER:?Set ADMIN_USER=opsadmin before running}"
: "${ADMIN_PASSWORD:?Set ADMIN_PASSWORD=... before running}"

echo
echo "========================================"
echo "OpenLiteSpeed AlmaLinux 9 Setup"
echo "========================================"
echo

echo "==> Updating base OS"
dnf -y update
dnf -y install epel-release
dnf -y update

echo "==> Installing base packages"
dnf -y install \
  curl \
  wget \
  ca-certificates \
  gnupg2 \
  chrony \
  fail2ban \
  dnf-automatic \
  policycoreutils-python-utils \
  lsof \
  tcpdump \
  bind-utils \
  iproute \
  net-tools \
  jq \
  socat \
  openssl \
  tar

echo "==> Enabling time sync"
systemctl enable --now chronyd
timedatectl set-ntp true

echo "==> SELinux enforcing"
if [[ -f /etc/selinux/config ]]; then
  sed -i 's/^SELINUX=.*/SELINUX=enforcing/' /etc/selinux/config
fi
setenforce 1 2>/dev/null || true

echo "==> Applying sysctl tuning for web server"
cat > /etc/sysctl.d/99-ols.conf <<'SYSCTL'
net.core.somaxconn = 32768
net.core.netdev_max_backlog = 250000
net.ipv4.tcp_max_syn_backlog = 16384
net.ipv4.tcp_syncookies = 1
net.ipv4.tcp_fin_timeout = 15
net.ipv4.tcp_tw_reuse = 1
net.ipv4.ip_local_port_range = 10240 65535

net.core.default_qdisc = fq
net.ipv4.tcp_congestion_control = bbr

net.ipv4.conf.all.accept_redirects = 0
net.ipv4.conf.default.accept_redirects = 0
net.ipv4.conf.all.send_redirects = 0
net.ipv4.conf.default.send_redirects = 0

fs.file-max = 2097152
SYSCTL

modprobe tcp_bbr || true
echo tcp_bbr > /etc/modules-load.d/bbr.conf
sysctl --system

echo "==> Setting file limits"
cat > /etc/security/limits.d/99-ols.conf <<'LIMITS'
* soft nofile 200000
* hard nofile 200000
root soft nofile 200000
root hard nofile 200000
nobody soft nofile 200000
nobody hard nofile 200000
LIMITS

echo "==> Hardening SSH"
cp /etc/ssh/sshd_config /etc/ssh/sshd_config.bak.$(date +%F-%H%M%S)
set_sshd_option() {
  local key="$1"
  local value="$2"
  if grep -qE "^[#[:space:]]*${key}[[:space:]]+" /etc/ssh/sshd_config; then
    sed -i "s|^[#[:space:]]*${key}[[:space:]].*|${key} ${value}|" /etc/ssh/sshd_config
  else
    echo "${key} ${value}" >> /etc/ssh/sshd_config
  fi
}
set_sshd_option PermitRootLogin prohibit-password
set_sshd_option PasswordAuthentication no
set_sshd_option PubkeyAuthentication yes
set_sshd_option KbdInteractiveAuthentication no
set_sshd_option ChallengeResponseAuthentication no
set_sshd_option X11Forwarding no
set_sshd_option ClientAliveInterval 300
set_sshd_option ClientAliveCountMax 2
set_sshd_option MaxAuthTries 4
sshd -t
systemctl restart sshd

echo "==> Configuring firewalld (22, 80, 443; WebAdmin localhost only)"
systemctl enable --now firewalld
firewall-cmd --permanent --remove-service=cockpit 2>/dev/null || true
firewall-cmd --permanent --add-service=ssh
firewall-cmd --permanent --add-service=http
firewall-cmd --permanent --add-service=https
firewall-cmd --reload

echo "==> Configuring fail2ban for SSH"
mkdir -p /etc/fail2ban/jail.d
cat > /etc/fail2ban/jail.d/sshd.local <<'F2B'
[sshd]
enabled = true
port = ssh
backend = systemd
maxretry = 4
findtime = 10m
bantime = 1h
F2B
systemctl enable --now fail2ban

echo "==> Configuring automatic security updates"
cat > /etc/dnf/automatic.conf <<'DNFAUTO'
[commands]
upgrade_type = security
random_sleep = 900
download_updates = yes
apply_updates = yes

[emitters]
emit_via = stdio

[base]
debuglevel = 1
DNFAUTO
systemctl enable --now dnf-automatic.timer

echo "==> Adding LiteSpeed repository"
rpm -ivh https://rpms.litespeedtech.com/centos/litespeed-repo-1.2-1.el9.noarch.rpm || \
  dnf -y install https://rpms.litespeedtech.com/centos/litespeed-repo-1.2-1.el9.noarch.rpm

echo "==> Installing OpenLiteSpeed + LSPHP 8.2 + WP cache module"
dnf -y install openlitespeed lsphp82 lsphp82-common lsphp82-mysqlnd lsphp82-process lsphp82-opcache lsphp82-pdo lsphp82-gd lsphp82-mbstring lsphp82-xml lsphp82-json

# Default lsphp symlink to lsphp82
ln -sf /usr/local/lsws/lsphp82/bin/lsphp /usr/local/lsws/fcgi-bin/lsphp

echo "==> Binding WebAdmin to 127.0.0.1:7080"
sed -i 's|adminListener .*|adminListener|; s|address \*:7080|address 127.0.0.1:7080|' /usr/local/lsws/admin/conf/admin_config.conf 2>/dev/null || true
# If the config form is different in this version, fall through to httpd_config.xml override below
mkdir -p /usr/local/lsws/admin/conf
cat > /usr/local/lsws/admin/conf/admin_listeners.conf <<'ADMIN_LISTENER'
listener adminListener {
  address                 127.0.0.1:7080
  secure                  1
  keyFile                 $SERVER_ROOT/admin/conf/webadmin.key
  certFile                $SERVER_ROOT/admin/conf/webadmin.crt
  clientVerify            0
}
ADMIN_LISTENER

echo "==> Rotating WebAdmin credentials"
ENCPASS=$(/usr/local/lsws/admin/fcgi-bin/admin_php -q /usr/local/lsws/admin/misc/htpasswd.php "${ADMIN_PASSWORD}" 2>/dev/null || \
  openssl passwd -apr1 "${ADMIN_PASSWORD}")
echo "${ADMIN_USER}:${ENCPASS}" > /usr/local/lsws/admin/conf/htpasswd
chmod 600 /usr/local/lsws/admin/conf/htpasswd
chown lsadm:lsadm /usr/local/lsws/admin/conf/htpasswd

echo "==> Writing WordPress vhost skeleton for ${PRIMARY_DOMAIN}"
VHROOT="/var/www/${PRIMARY_DOMAIN}"
mkdir -p "${VHROOT}"/{html,logs,conf,cache}
chown -R nobody:nobody "${VHROOT}"

mkdir -p "/usr/local/lsws/conf/vhosts/${PRIMARY_DOMAIN}"
cat > "/usr/local/lsws/conf/vhosts/${PRIMARY_DOMAIN}/vhconf.conf" <<VHCONF
docRoot                   ${VHROOT}/html
enableGzip                1
enableBr                  1
cgroups                   0

errorlog ${VHROOT}/logs/error.log {
  useServer               0
  logLevel                INFO
  rollingSize             100M
}

accesslog ${VHROOT}/logs/access.log {
  useServer               0
  logFormat               "%h %l %u %t \"%r\" %>s %O \"%{Referer}i\" \"%{User-Agent}i\" %D %{X-Request-Id}o"
  rollingSize             100M
  keepDays                14
  compressArchive         1
}

index  {
  useServer               0
  indexFiles              index.php, index.html
}

scripthandler  {
  add                     lsapi:lsphp82 php
}

extprocessor lsphp82 {
  type                    lsapi
  address                 uds://tmp/lshttpd/lsphp82.sock
  maxConns                64
  env                     LSAPI_CHILDREN=64
  initTimeout             60
  retryTimeout            0
  persistConn             1
  pcKeepAliveTimeout      60
  respBuffer              0
  autoStart               1
  path                    /usr/local/lsws/lsphp82/bin/lsphp
  memSoftLimit            384M
  memHardLimit            512M
  procSoftLimit           400
  procHardLimit           500
}

context / {
  location                ${VHROOT}/html
  allowBrowse             1
  rewrite  {
    enable                1
    autoLoadHtaccess      1
  }
}

module cache {
  storagePath             ${VHROOT}/cache
}

rewrite  {
  enable                  1
  autoLoadHtaccess        1
  logLevel                0
}

# Security + request id headers
extraHeaders <<HDRS
Strict-Transport-Security: max-age=31536000; includeSubDomains
X-Content-Type-Options: nosniff
Referrer-Policy: strict-origin-when-cross-origin
HDRS
VHCONF

echo "==> Wiring vhost into main config"
cat >> /usr/local/lsws/conf/httpd_config.conf <<VHOST_REF

virtualhost ${PRIMARY_DOMAIN} {
  vhRoot                  ${VHROOT}
  configFile              \$SERVER_ROOT/conf/vhosts/${PRIMARY_DOMAIN}/vhconf.conf
  allowSymbolLink         1
  enableScript            1
  restrained              1
  setUIDMode              0
}
VHOST_REF

# Listeners (HTTP + HTTPS)
cat >> /usr/local/lsws/conf/httpd_config.conf <<'LISTENERS_REF'

listener Default {
  address                 *:80
  secure                  0
  map                     PRIMARY_HOST PRIMARY_DOMAIN
}

listener DefaultSSL {
  address                 *:443
  secure                  1
  keyFile                 /etc/letsencrypt/live/PRIMARY_DOMAIN/privkey.pem
  certFile                /etc/letsencrypt/live/PRIMARY_DOMAIN/fullchain.pem
  sslProtocol             24
  ciphers                 TLS_AES_128_GCM_SHA256:TLS_AES_256_GCM_SHA384:TLS_CHACHA20_POLY1305_SHA256:ECDHE+AESGCM:ECDHE+CHACHA20
  enableECDHE             1
  enableSpdy              15
  map                     PRIMARY_HOST PRIMARY_DOMAIN
}
LISTENERS_REF

sed -i "s|PRIMARY_DOMAIN|${PRIMARY_DOMAIN}|g; s|PRIMARY_HOST|${PRIMARY_DOMAIN}|g" /usr/local/lsws/conf/httpd_config.conf

echo "==> Setting systemd LimitNOFILE for lsws"
mkdir -p /etc/systemd/system/lsws.service.d
cat > /etc/systemd/system/lsws.service.d/override.conf <<'LSWS_OVERRIDE'
[Service]
LimitNOFILE=200000
LimitNPROC=16384
LSWS_OVERRIDE
systemctl daemon-reload

echo "==> Installing acme.sh and issuing Let's Encrypt cert"
curl -s https://get.acme.sh | sh -s email="${ACME_EMAIL}"
export PATH="/root/.acme.sh:${PATH}"
/root/.acme.sh/acme.sh --set-default-ca --server letsencrypt

# Stop OLS briefly so acme.sh standalone can bind :80 (or use webroot if ports are critical)
systemctl stop lsws || true
/root/.acme.sh/acme.sh --issue --standalone -d "${PRIMARY_DOMAIN}" --keylength ec-256 --force || \
/root/.acme.sh/acme.sh --issue --standalone -d "${PRIMARY_DOMAIN}" --keylength 2048 --force

# Install cert into /etc/letsencrypt/live/${PRIMARY_DOMAIN}/ layout the listener expects
mkdir -p "/etc/letsencrypt/live/${PRIMARY_DOMAIN}"
/root/.acme.sh/acme.sh --install-cert -d "${PRIMARY_DOMAIN}" \
  --key-file       "/etc/letsencrypt/live/${PRIMARY_DOMAIN}/privkey.pem" \
  --fullchain-file "/etc/letsencrypt/live/${PRIMARY_DOMAIN}/fullchain.pem" \
  --reloadcmd      "touch /usr/local/lsws/conf/serial.no && systemctl reload lsws"

echo "==> Validating OpenLiteSpeed config"
/usr/local/lsws/bin/lswsctrl -t || true

echo "==> Starting OpenLiteSpeed"
systemctl enable --now lsws
systemctl restart lsws

echo "==> Waiting for listeners on :80 and :443"
for i in {1..30}; do
  if ss -lntp | grep -q ':443' && ss -lntp | grep -q ':80'; then
    break
  fi
  sleep 1
done

if ! ss -lntp | grep -q ':443'; then
  echo "OLS did not bind :443"
  /usr/local/lsws/bin/lswsctrl status || true
  tail -100 /usr/local/lsws/logs/error.log || true
  exit 1
fi

echo
echo "========================================"
echo "DONE"
echo "========================================"
echo
echo "Kernel:"
uname -r
echo
echo "Listeners:"
ss -lntp | grep -E ':(80|443|7080)\b' || true
echo
echo "Services:"
systemctl is-active lsws firewalld fail2ban chronyd || true
echo
echo "OLS version:"
/usr/local/lsws/bin/lshttpd -v 2>&1 | head -2
echo
echo "WebAdmin: https://127.0.0.1:7080/ (SSH-tunnel from your workstation)"
echo "  user: ${ADMIN_USER}"
echo
echo "First test:"
echo "  curl -I https://${PRIMARY_DOMAIN}/"
echo
echo "WordPress site root: ${VHROOT}/html  (deploy WP files there, then install LSCache plugin)"
echo "Cache path:          ${VHROOT}/cache"
echo
echo "Cert renewal hook installed via acme.sh; renewal runs daily."

Make it executable and run it (export the four required env vars first):

chmod 700 /root/setup-openlitespeed-alma9.sh
export PRIMARY_DOMAIN=example.com
export ACME_EMAIL=ops@example.com
export ADMIN_USER=opsadmin
export ADMIN_PASSWORD=...
/root/setup-openlitespeed-alma9.sh

Tunnel into the WebAdmin from your workstation (ssh -L 7080:127.0.0.1:7080 root@host), open https://127.0.0.1:7080/, deploy WordPress under /var/www/<domain>/html, then install the official LSCache for WordPress plugin and confirm X-LiteSpeed-Cache: hit on the second page load. The script does not configure host-level backups — the assumption is the VM has snapshot/backup at the cloud layer.

For the WordPress estate end-to-end (LSCache tuning, plugin rollouts, certificate cadence, patching), Stack Harbor owns it as Managed Cloud Ops — book a review.