如果输入yum install php-swoole提示No package php-swoole available,则说明当前yum源中没有php-swoole的安装包,需要手动安装swoole。

安装swoole的步骤如下:

  1. 安装epel源:
yum install epel-release
  1. 安装swoole依赖:
yum install gcc gcc-c++ autoconf automake libtool make
  1. 下载swoole源码:
wget https://github.com/swoole/swoole-src/archive/master.zip
  1. 解压源码:
unzip master.zip
cd swoole-src-master
  1. 编译安装:
phpize
./configure
make
make install
  1. 修改php.ini文件,添加swoole扩展:
extension=swoole.so
  1. 重启php-fpm服务:
service php-fpm restart
  1. 编写swoole_http_server代码:
<?php
$http = new Swoole\Http\Server("0.0.0.0", 9501);

$http->on("start", function ($server) {
    echo "Swoole http server is started at http://0.0.0.0:9501\n";
});

$http->on("request", function ($request, $response) {
    $response->header("Content-Type", "text/plain");
    $response->end("Hello World\n");
});

$http->start();
  1. 运行swoole_http_server:
php your_file_name.php
  1. 访问http://ip:9501即可看到Hello World的输出。
centos7怎么搭建swoole_http_server 已经安装了php输入yum install php-swoole提示No package php-swoole available

原文地址: https://www.cveoy.top/t/topic/bunA 著作权归作者所有。请勿转载和采集!

免费AI点我,无需注册和登录