cd /server/php/8.3.0/bin/
#安装pecl
sudo wget http://pear.php.net/go-pear.phar -O go-pear.php
sudo ./php go-pear.php
sudo ./pecl search swoole
sudo ./pecl install swoole
#一路回车
./php --ini
vim /server/php/8.3.0/etc/php.ini
#添加
extension=swoole.so
也可以使用脚本部署
#!/bin/bash
# 切换到指定目录
cd /server/php/8.3.0/bin/
# 安装PECL
sudo wget http://pear.php.net/go-pear.phar -O go-pear.php
sudo php go-pear.php
sudo ./php go-pear.php
# 搜索Swoole扩展
sudo ./pecl search swoole
# 安装Swoole扩展
sudo ./pecl install swoole < /dev/null
# 显示PHP配置文件路径
./php --ini
# 获取PHP配置文件路径
PHP_INI_PATH=$(./php --ini | grep "Loaded Configuration File" | awk -F: '{print $2}' | sed 's/ //g')
# 检查是否已存在Swoole扩展的配置行
if ! grep -q "extension=swoole.so" "$PHP_INI_PATH"; then
# 使用sed在php.ini文件的末尾添加Swoole扩展的配置行
sed -i '$a\extension=swoole.so' "$PHP_INI_PATH"
echo "Swoole扩展已添加到$PHP_INI_PATH"
else
echo "Swoole扩展的配置已存在于$PHP_INI_PATH"
fi
echo "Swoole扩展安装和配置完成。"