ติดตั้ง OpenLiteSpeed บน VPS เว็บเซิร์ฟเวอร์เร็วกว่า Nginx
OpenLiteSpeed (OLS) คือ open-source version ของ LiteSpeed Enterprise — เว็บเซิร์ฟเวอร์ที่ benchmark แสดงให้เห็นว่า เร็วกว่า Nginx ถึง 40x สำหรับ WordPress ที่ใช้ LiteSpeed Cache รองรับ HTTP/2, HTTP/3 (QUIC), PHP-LiteSpeed ที่เร็วกว่า PHP-FPM, SSL อัตโนมัติผ่าน Let's Encrypt และมี WebAdmin Console สำหรับจัดการผ่าน browser โดยไม่ต้องแก้ config file บทความนี้สอนติดตั้ง OLS, ตั้ง Virtual Host และ WordPress พร้อม LiteSpeed Cache
เปรียบเทียบ OpenLiteSpeed กับ Nginx/Apache
- PHP performance: LSPHP (PHP handler ของ OLS) เร็วกว่า PHP-FPM เพราะ persistent connection กับ PHP process
- Static file: เทียบเท่า Nginx — ดีกว่า Apache มาก
- WordPress: ร่วมกับ LiteSpeed Cache plugin เร็วกว่า Nginx+FastCGI Cache ชัดเจน
- ข้อเสีย: ecosystem เล็กกว่า Nginx, module น้อยกว่า, หา tutorial ได้น้อยกว่า
- เหมาะกับ: VPS ที่รัน WordPress หรือ PHP app และต้องการ performance สูงสุด
ติดตั้ง OpenLiteSpeed บน Ubuntu 22.04
# เพิ่ม LiteSpeed repository
wget -O - https://repo.litespeed.sh | bash
# ติดตั้ง OpenLiteSpeed
apt install -y openlitespeed
# ติดตั้ง PHP 8.3 (LSPHP)
apt install -y lsphp83 lsphp83-common lsphp83-mysql lsphp83-curl lsphp83-json lsphp83-opcache lsphp83-mbstring lsphp83-xml lsphp83-zip lsphp83-imagick
# เริ่ม service
systemctl enable lsws
systemctl start lsws
# ตรวจสอบ port ที่ใช้
# WebAdmin console: port 7080
# HTTP: port 8088 (default, ต้องเปลี่ยนเป็น 80)
ss -tlnp | grep -E '7080|8088'
ตั้ง Admin Password และ WebAdmin Console
# ตั้ง WebAdmin password
/usr/local/lsws/admin/misc/admpass.sh
# ตั้ง firewall เพื่อเข้า WebAdmin ชั่วคราว
ufw allow 7080/tcp
# เปิด WebAdmin: https://YOUR_VPS_IP:7080
# ยืนยัน SSL warning (self-signed cert)
# ล็อกอินด้วย admin และ password ที่ตั้งไว้
# เปลี่ยน HTTP listener จาก port 8088 เป็น 80:
# Listeners → View → Default → Edit → Address: 80
# หลังตั้งแล้วปิด port 7080 เมื่อไม่ใช้
# ufw delete allow 7080/tcp
สร้าง Virtual Host สำหรับ Domain
# สร้าง directory structure
mkdir -p /var/www/example.com/{html,logs,conf}
# ผ่าน WebAdmin Console:
# Virtual Hosts → Add → กรอกรายละเอียด
# Virtual Host Name: example.com
# Virtual Host Root: /var/www/example.com/
# Config File: /var/www/example.com/conf/vhconf.conf
# หรือสร้าง config ตรง (สำหรับ advanced)
cat > /var/www/example.com/conf/vhconf.conf << 'EOF'
docRoot /var/www/example.com/html
enableGzip 1
enableBr 1
errorlog /var/www/example.com/logs/error.log {
useServer 0
logLevel ERROR
rollingSize 10M
}
accesslog /var/www/example.com/logs/access.log {
useServer 0
rollingSize 10M
}
index {
useServer 0
indexFiles index.php, index.html
}
scripthandler {
add lsapi:lsphp83 php
}
rewrite {
enable 1
rules <<
ติดตั้ง WordPress พร้อม LiteSpeed Cache
# ติดตั้ง MariaDB
apt install -y mariadb-server
mysql_secure_installation
# สร้าง database
mysql -u root -p -e "CREATE DATABASE wordpress;
CREATE USER 'wpuser'@'localhost' IDENTIFIED BY 'SECURE_PASS';
GRANT ALL PRIVILEGES ON wordpress.* TO 'wpuser'@'localhost';
FLUSH PRIVILEGES;"
# ดาวน์โหลด WordPress
cd /var/www/example.com/html
curl -sO https://wordpress.org/latest.tar.gz
tar xzf latest.tar.gz --strip-components=1
rm latest.tar.gz
chown -R nobody:nogroup /var/www/example.com/html
# ใน WordPress admin ติดตั้ง plugin:
# "LiteSpeed Cache" — เป็น official plugin ที่ทำงานร่วมกับ OLS ได้ดีที่สุด
# ไป LiteSpeed Cache → Cache → Enable Cache
# ตั้ง Crawler ใน LiteSpeed Cache เพื่อ warm cache อัตโนมัติ
ตั้ง SSL ด้วย Let's Encrypt
# ผ่าน WebAdmin Console:
# Listeners → HTTPS → Edit → SSL tab
# ใช้ built-in ACME client ของ OLS:
# ผ่าน command line
/usr/local/lsws/admin/misc/acmesh.sh -t example.com
# หรือติดตั้ง certbot แล้ว configure manual
apt install -y certbot
certbot certonly --webroot -w /var/www/example.com/html -d example.com -d www.example.com
# config SSL ใน OLS listener:
# Cert File: /etc/letsencrypt/live/example.com/fullchain.pem
# Key File: /etc/letsencrypt/live/example.com/privkey.pem
ตรวจสอบว่า OpenLiteSpeed ทำงานถูกต้อง
# ดูสถานะ service
systemctl status lsws
# ตรวจ error log
tail -50 /usr/local/lsws/logs/error.log
# ตรวจ PHP ทำงานได้
echo "" > /var/www/example.com/html/info.php
curl -s http://YOUR_VPS_IP/info.php | grep -i "litespeed"
rm /var/www/example.com/html/info.php
# เช็ก HTTP/2 support
curl -sI --http2 https://example.com | grep -i "HTTP"
# เช็ก Header ว่าใช้ OpenLiteSpeed
curl -sI https://example.com | grep -i "x-powered-by\|server"
# ตรวจ Worker process
ps aux | grep lshttpd | head -10
systemctl restart lsws เมื่อแก้ config ผ่าน file ตรง แต่ถ้าแก้ผ่าน WebAdmin ให้กด "Graceful Restart" ในหน้า Dashboard — ต่าง restart แบบ graceful จะไม่ drop connection ที่กำลัง serve อยู่แก้ปัญหาที่พบบ่อย
Error: "508 Resource Limit Reached"
PHP process ถึงขีดจำกัดที่ตั้งไว้ — เพิ่ม worker limit
# WebAdmin Console: External App → lsphp83 → Edit
# Max Connections: เพิ่มจาก 35 เป็น 100
# Initial Request Timeout: 60
# หรือแก้ config ตรงใน /usr/local/lsws/conf/httpd_config.xml
# ค้นหา แล้วเพิ่มค่า
WordPress 404 สำหรับ URL ที่มี slug
Rewrite rules ไม่ถูกต้องใน Virtual Host config
# ตรวจสอบ rewrite ใน vhconf.conf ต้องมี:
rewrite {
enable 1
rules <<
Error: "Permission denied" เมื่อ PHP เขียนไฟล์
OLS รัน PHP ด้วย user nobody โดย default
# แก้ owner ของ web root
chown -R nobody:nogroup /var/www/example.com/html
# สำหรับ WordPress uploads
chmod 755 /var/www/example.com/html/wp-content/uploads
WebAdmin Console เข้าไม่ได้หลังปิด port 7080
ต้องเปิด port ชั่วคราวเพื่อเข้า console
ufw allow from YOUR_IP to any port 7080
# เข้า console ทำงานเสร็จแล้วปิด
ufw delete allow from YOUR_IP to any port 7080
คำถามที่พบบ่อย
OpenLiteSpeed ต่างจาก LiteSpeed Enterprise อย่างไร?
OpenLiteSpeed เป็น free และ open-source แต่ไม่มี HTTP/3 แบบเต็มรูปแบบ, ไม่มี WAF ในตัว และ performance ต่ำกว่าเล็กน้อยในบาง benchmark LiteSpeed Enterprise มีทุก feature ครบ แต่มีค่าใบอนุญาต อย่างไรก็ตาม OLS เหมาะสำหรับ VPS ส่วนตัวที่ไม่ต้องการ enterprise feature
OpenLiteSpeed รองรับ .htaccess ได้ไหม?
รองรับ .htaccess บางส่วน — RewriteEngine, Redirect, ErrorDocument และ Options ส่วนใหญ่ใช้ได้ แต่ Module-specific directives เช่น mod_security หรือ mod_headers บางตัวไม่รองรับ ถ้า app ใช้ .htaccess มาก ควรทดสอบก่อน migrate
ย้ายจาก Nginx/Apache มา OpenLiteSpeed ยากไหม?
ขึ้นกับ app — WordPress ย้ายง่ายมาก เพียงเปลี่ยน document root และตั้ง rewrite rules PHP app อื่นๆ ต้องแปลง Nginx config เป็น OLS format ซึ่ง syntax ต่างกัน เครื่องมือ converter มีอยู่บนเว็บ แต่ควรทดสอบใน staging ก่อนเสมอ