swoft安装与入门

A.安装

a.composer安装

1
2
3
composer create-project swoft/swoft swoft
cd swoft
composer install --no-dev # 不安装 dev 依赖会更快一些

b.手动安装

1
2
3
4
5
git clone https://github.com/swoft-cloud/swoft
cd swoft
composer install --no-dev # 不安装 dev 依赖会更快一些
cp .env.example .env
vim .env # 根据需要调整启动参数

c.Docker方式安装

1
docker run -p 80:80 swoft/swoft

d.Docker-Compose 安装

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
git clone https://github.com/swoft-cloud/swoft
cd swoft
修改docker-compose.yml
########################################
version: '3'
services:
    swoft:
        container_name: swoft
        image: swoft/swoft
        ports:
            - "80:80"
        #volumes:
        #   - ./:/var/www/swoft
        stdin_open: true0
        tty: true
        command: /bin/bash
########################################
docker-compose up -d

B.安装依赖

1
2
3
composer install --no-dev # 不安装 dev 依赖会更快一些
cp .env.example .env
vim .env # 根据需要调整启动参数

C.启动

a.HTTP 服务器

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
// 启动服务,根据 .env 配置决定是否是守护进程
php bin/swoft start
// 守护进程启动,覆盖 .env 守护进程(DAEMONIZE)的配置
php bin/swoft start -d
// 重启
php bin/swoft restart
// 重新加载
php bin/swoft reload
// 关闭服务
php bin/swoft stop

b.WebSocket服务器

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
// 启动服务,根据 .env 配置决定是否是守护进程
php bin/swoft ws:start
// 守护进程启动,覆盖 .env 守护进程(DAEMONIZE)的配置
php bin/swoft ws:start -d
// 重启
php bin/swoft ws:restart
// 重新加载
php bin/swoft ws:reload
// 关闭服务
php bin/swoft ws:stop
### c.RPC 服务器
// 启动服务,根据 .env 配置决定是否是守护进程
php bin/swoft rpc:start
// 守护进程启动,覆盖 .env 守护进程(DAEMONIZE)的配置
php bin/swoft rpc:start -d
// 重启
php bin/swoft rpc:restart
// 重新加载
php bin/swoft rpc:reload
// 关闭服务
php bin/swoft rpc:stop