Cấu hình “chuẩn an toàn” cho
VPS 2 vCPU – 2 GB RAM chạy
CyberPanel + OpenLiteSpeed + PHP 8.2. Mục tiêu: hết “possible dead lock”, giảm swap, giữ site mượt ổn định.
1) OpenLiteSpeed → External App (lsphp)
WebAdmin (port 7080) → Server Configuration → External App → lsphp - Name: lsphp
- Address: uds://tmp/lshttpd/lsphp.sock (giữ UDS)
- Max Connections: 12
- Environment:
PHP_LSAPI_CHILDREN=4
PHP_LSAPI_MAX_REQUESTS=300
Bỏ dòng LSAPI_AVOID_FORK=512M nếu đang có.
- Initial Request Timeout: 90
- Retry Timeout: 0
- Persistent Connection: Yes
- Connection Keep-Alive Timeout: 3
- Response Buffering: No
- Start By Server: Yes (Through CGI Daemon)
- Command: lsphp82/bin/lsphp
- Back Log: 20
- Instances: 2
Tổng worker ≈ 2×4 = 8, đủ cho 2 GB.
- Run On Start Up: Not Set (hoặc Yes cũng được)
- Max Idle Time: 30
- Priority: 0
- Memory Soft/Hard Limit: 256M / 384M
- Process Soft/Hard Limit: giữ mặc định (không phải nút thắt)
Lưu → Actions → Graceful Restart.
2) OpenLiteSpeed → Tuning
Server Configuration → Tuning - PHP suEXEC Max Conn: 12 (khớp Max Connections)
- Connection Timeout: 120
- Max Connections (server): để mặc định hoặc ≥ 1000 (không phải bottleneck)
- Log Level: ERROR (giảm spam NOTICE)
3) PHP 8.2 (lsphp) – php.ini
Đường dẫn thường:
/usr/local/lsws/lsphp82/etc/php/8.2/litespeed/php.ini (tuỳ bản cài)
; --- Memory / execution ---
memory_limit = 128M; nếu thiếu mới nâng 160M
max_execution_time = 60
max_input_time = 60
post_max_size = 32M
upload_max_filesize = 32M
default_socket_timeout = 30
; --- Opcache (bắt buộc bật) ---
opcache.enable=1
opcache.enable_cli=0
opcache.memory_consumption=128
opcache.interned_strings_buffer=16
opcache.max_accelerated_files=65000
opcache.validate_timestamps=1
opcache.revalidate_freq=2
opcache.jit=0
; --- MySQL client timeouts ---
mysqlnd.net_read_timeout=30
Sau khi sửa: systemctl restart lsws (hoặc Graceful Restart trong WebAdmin).
4) MySQL/MariaDB (cơ bản, hợp 2 GB)
File /etc/mysql/mariadb.conf.d/60-server.cnf (hoặc tương đương):
[mysqld]
innodb_buffer_pool_size=512M
innodb_log_file_size=128M
innodb_flush_log_at_trx_commit=1
innodb_flush_method=O_DIRECT
max_connections=80
table_open_cache=1024
query_cache_size=0
query_cache_type=0
# Slow log để bắt truy vấn nặng
slow_query_log=1
long_query_time=1
log_slow_verbosity=query_plan
sudo systemctl restart mariadb || sudo systemctl restart mysql
5) Kernel: giảm dùng swap
echo 'vm.swappiness=10' | sudo tee /etc/sysctl.d/99-swappiness.conf
sudo sysctl -p /etc/sysctl.d/99-swappiness.conf
Nếu vẫn swap nhiều, cân nhắc giảm Max Connections xuống 10.
6) Log: xoay & nén (logrotate)
Tạo /etc/logrotate.d/openlitespeed:
/usr/local/lsws/logs/*.log {
daily
rotate 7
compress
missingok
notifempty
create 640 root root
sharedscripts
postrotate
/bin/systemctl reload lsws > /dev/null 2>&1 || true
endscript
}
7) LSCache / Cache header (khuyến nghị)
- Bật LSCache plugin nếu dùng WordPress/Laravel.
- Với các API tĩnh kiểu avatar đã xử lý xong, thêm header cache:
header('Cache-Control: public, max-age=86400, s-maxage=86400');
8) Giảm tải bot Facebook (cực hiệu quả)
Ở tầng sớm nhất (bootstrap/index.php hoặc middleware đầu), trả
OG nhẹ cho UA facebookexternalhit:
Code:
if (isset($_SERVER['HTTP_USER_AGENT']) && stripos($_SERVER['HTTP_USER_AGENT'], 'facebookexternalhit') !== false) { header('Content-Type: text/html; charset=UTF-8'); echo '<!doctype html><html><head> <meta property="og:title" content="Riokupon" /> <meta property="og:description" content="Login & deals" /> <meta property="og:image" content="https://img.riokupon.com/og/cover.jpg" /> </head><body>OK</body></html>'; exit;
}
- Ảnh OG nén < 300 KB, 1200×630.
- Tránh mọi gọi API/DB nặng khi UA là FB crawler.
9) Kiểm tra & giám sát nhanh
# Số tiến trình PHP & RAM/tiến trình
ps -o pid,rss,cmd -C lsphp | sort -nrk2 | head
# Bộ nhớ & swap
free -m
vmstat 1 5
# Test UA thường & FB
curl -I
https://riokupon.com/ curl -I -A "facebookexternalhit/1.1"
https://riokupon.com/ # Slow queries (sau vài phút bật slow log)
sudo grep -A3 -B1 -n "Query_time" /var/lib/mysql/*slow*.log 2>/dev/null | head -n 50
Gợi ý mức tải phù hợp
- Với site PHP trung bình, cấu hình trên chịu tốt 50–150 req/min tùy mức cache.
- Nếu traffic tăng: nâng RAM lên 4 GB trước khi tăng Max Connections/CHILDREN.
Sau khi áp dụng, lỗi “No request delivery notification… possible dead lock” sẽ dừng vì lsphp không còn bị “đẩy vào swap” và timeout bắt tay.