安装 PHP
OpenLiteSpeed 使用 lsphp(LiteSpeed PHP)作为默认的 PHP 处理器。lsphp 是针对 LiteSpeed 原生 LSAPI 协议优化的 PHP 构建版本,性能显著优于 PHP-FPM 或标准 FastCGI。
添加 LiteSpeed 仓库
Section titled “添加 LiteSpeed 仓库”RHEL / AlmaLinux / Rocky Linux
Section titled “RHEL / AlmaLinux / Rocky Linux”rpm -Uvh https://rpms.litespeedtech.com/centos/litespeed-repo-1.3-1.el9.noarch.rpm对于 EL8 系统,将 el9 替换为 el8。
Debian / Ubuntu
Section titled “Debian / Ubuntu”wget -O - https://repo.litespeed.sh | sudo bash安装 lsphp
Section titled “安装 lsphp”LiteSpeed 仓库提供以下 PHP 版本:
| 包名前缀 | PHP 版本 | 状态 |
|---|---|---|
lsphp74 | 7.4.x | 仅安全修复 |
lsphp80 | 8.0.x | 已停止维护 |
lsphp81 | 8.1.x | 仅安全修复 |
lsphp82 | 8.2.x | 活跃支持 |
lsphp83 | 8.3.x | 活跃支持 |
lsphp84 | 8.4.x | 活跃支持(推荐) |
安装 PHP 8.4 及常用扩展
Section titled “安装 PHP 8.4 及常用扩展”RHEL / AlmaLinux / Rocky:
dnf install lsphp84 lsphp84-mysqlnd lsphp84-xml lsphp84-gd \ lsphp84-mbstring lsphp84-opcache lsphp84-curl lsphp84-json \ lsphp84-zip lsphp84-bcmath lsphp84-intlDebian / Ubuntu:
apt install lsphp84 lsphp84-mysql lsphp84-xml lsphp84-gd \ lsphp84-mbstring lsphp84-opcache lsphp84-curl \ lsphp84-zip lsphp84-bcmath lsphp84-intl列出所有可用扩展
Section titled “列出所有可用扩展”# RHEL 系dnf list lsphp84-*
# Debian 系apt-cache search lsphp84将 lsphp 链接到 OLS
Section titled “将 lsphp 链接到 OLS”OLS 在 /usr/local/lsws/fcgi-bin/lsphp 路径查找 PHP 二进制文件。创建指向已安装版本的符号链接:
ln -sf /usr/local/lsws/lsphp84/bin/lsphp /usr/local/lsws/fcgi-bin/lsphp以后如需切换 PHP 版本,更新此符号链接指向不同的 lsphp 二进制文件(例如 lsphp83)即可。
/usr/local/lsws/lsphp84/bin/lsphp -v预期输出:
PHP 8.4.x (litespeed) ...注意 (litespeed) SAPI 标识 — 这确认已编译了 LSAPI 支持。
多 PHP 版本
Section titled “多 PHP 版本”您可以同时安装多个 lsphp 版本,并将它们分配给不同的虚拟主机。安装每个版本:
dnf install lsphp83 lsphp84然后在 httpd_config.conf 中为每个版本配置单独的外部应用程序,指向正确的二进制路径:
extprocessor lsphp83 { type lsapi address uds://tmp/lshttpd/lsphp83.sock maxConns 10 env PHP_LSAPI_CHILDREN=10 initTimeout 60 retryTimeout 0 respBuffer 0 autoStart 1 path /usr/local/lsws/lsphp83/bin/lsphp backlog 100 instances 1}PHP 配置
Section titled “PHP 配置”每个 lsphp 版本的 php.ini 位于:
/usr/local/lsws/lsphp84/etc/php/8.4/litespeed/php.ini修改 php.ini 后,重启 OLS 以使更改生效:
systemctl restart lsws- PHP LSAPI — 了解 LSAPI 的工作原理并进行调优
- PHP 环境变量 — 配置 PHP 工作进程
- PHP-FPM 集成 — 使用 PHP-FPM 作为替代方案