2020-12-01 23:13:24 +08:00
|
|
|
|
# Lumen-IM
|
2020-11-02 22:45:37 +08:00
|
|
|
|
|
2020-11-03 17:12:57 +08:00
|
|
|
|
## 1、简介
|
2020-11-02 22:45:37 +08:00
|
|
|
|
|
2020-11-03 17:12:57 +08:00
|
|
|
|
这是一个使用Hyperf框架的开发的IM后端应用程序。此项目是 [LumenIM-Serve](https://github.com/gzydong/LumenIM-Serve) 的重构版本。
|
2020-11-02 22:45:37 +08:00
|
|
|
|
|
2021-07-12 22:31:37 +08:00
|
|
|
|
Lumen-IM 是一个网页版在线即时聊天项目,前端使用 Element-ui + Vue ,后端使用 PHP + Swoole 进行开发。项目后端采用 Hyperf 框架。
|
2020-12-01 23:13:24 +08:00
|
|
|
|
|
2021-07-12 22:31:37 +08:00
|
|
|
|
- 基于 Swoole WebSocket 服务做消息即时推送
|
2020-12-01 23:13:24 +08:00
|
|
|
|
- 支持私聊及群聊
|
|
|
|
|
- 支持聊天消息类型有文本、代码块、图片及其它类型文件,并支持文件下载
|
2021-08-10 21:21:26 +08:00
|
|
|
|
- 支持聊天消息撤回、删除或批量删除、转发消息(逐条转发、合并转发)及群投票功能
|
2020-12-01 23:13:24 +08:00
|
|
|
|
- 支持编写个人笔记、支持笔记分享(好友或群)
|
|
|
|
|
|
2021-07-12 22:31:37 +08:00
|
|
|
|
## 2、项目DEMO
|
|
|
|
|
|
2020-11-03 17:12:57 +08:00
|
|
|
|
- 地址: [http://im.gzydong.club](http://im.gzydong.club)
|
|
|
|
|
- 账号: 18798272054 或 18798272055
|
|
|
|
|
- 密码: admin123
|
2020-11-02 22:45:37 +08:00
|
|
|
|
|
2020-11-03 17:12:57 +08:00
|
|
|
|
## 3、环境要求
|
2021-07-12 22:31:37 +08:00
|
|
|
|
|
2021-08-27 23:50:40 +08:00
|
|
|
|
- PHP >= 7.3
|
2021-07-12 22:31:37 +08:00
|
|
|
|
- MySQL >= 5.7
|
|
|
|
|
- Redis >= 5.0
|
2021-09-11 15:53:23 +08:00
|
|
|
|
- Swoole >= 4.5
|
2021-07-12 22:31:37 +08:00
|
|
|
|
- OpenSSL
|
|
|
|
|
- JSON
|
|
|
|
|
- PDO
|
2020-11-02 22:45:37 +08:00
|
|
|
|
|
2020-12-19 21:04:59 +08:00
|
|
|
|
## 4、相关文档
|
2021-07-12 22:31:37 +08:00
|
|
|
|
|
2021-09-11 15:53:23 +08:00
|
|
|
|
[Hyperf 框架](https://hyperf.wiki/2.1/#/README)
|
2020-12-19 21:04:59 +08:00
|
|
|
|
|
2021-07-12 22:31:37 +08:00
|
|
|
|
## 5、项目安装
|
|
|
|
|
|
2020-12-19 21:29:16 +08:00
|
|
|
|
1. 下载源码包
|
2021-08-09 20:58:13 +08:00
|
|
|
|
2. 安装框架依赖包执行 `composer install` 命令 [项目根目录下执行]
|
2021-07-08 19:09:06 +08:00
|
|
|
|
2. 拷贝项目根目录下 .env.example 文件为 .env 并正确配置相关参数(mysql、redis)
|
2021-08-01 19:57:41 +08:00
|
|
|
|
3. 执行项目安装命令(安装数据库及测试数据) `php bin/hyperf.php system:install`
|
2020-12-19 21:04:59 +08:00
|
|
|
|
4. 启动运行项目 `php bin/hyperf.php start`
|
|
|
|
|
|
2021-07-12 22:31:37 +08:00
|
|
|
|
注 :[项目运行之前请确保 MySQL、Redis 及 Nginx 服务]
|
|
|
|
|
|
2020-12-19 21:29:16 +08:00
|
|
|
|
## Nginx 相关配置(代理 swoole 服务)
|
2020-12-19 21:04:59 +08:00
|
|
|
|
|
|
|
|
|
##### 配置 Http 服务
|
2021-07-12 22:31:37 +08:00
|
|
|
|
|
2020-12-19 21:04:59 +08:00
|
|
|
|
```
|
2021-09-11 15:53:23 +08:00
|
|
|
|
upstream hyperf_http {
|
2020-12-19 21:04:59 +08:00
|
|
|
|
# Hyperf HTTP Server 的 IP 及 端口
|
|
|
|
|
server 127.0.0.1:9503;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
server {
|
|
|
|
|
# 监听端口
|
|
|
|
|
listen 80;
|
|
|
|
|
# 绑定的域名,填写您的域名
|
|
|
|
|
server_name im-serve.xxx.com;
|
|
|
|
|
|
|
|
|
|
location / {
|
|
|
|
|
client_max_body_size 20m;
|
|
|
|
|
# 将客户端的 Host 和 IP 信息一并转发到对应节点
|
|
|
|
|
proxy_set_header Host $http_host;
|
|
|
|
|
proxy_set_header X-Real-IP $remote_addr;
|
|
|
|
|
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
|
|
|
|
|
|
|
|
|
|
# 转发Cookie,设置 SameSite
|
|
|
|
|
proxy_cookie_path / "/; secure; HttpOnly; SameSite=strict";
|
|
|
|
|
|
|
|
|
|
# 执行代理访问真实服务器
|
2021-09-11 15:53:23 +08:00
|
|
|
|
proxy_pass http://hyperf_http;
|
2020-12-19 21:04:59 +08:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
```
|
|
|
|
|
|
|
|
|
|
##### 配置 WebSocket 服务
|
2021-07-12 22:31:37 +08:00
|
|
|
|
|
2020-12-19 21:04:59 +08:00
|
|
|
|
```
|
|
|
|
|
# 至少需要一个 Hyperf 节点,多个配置多行
|
|
|
|
|
upstream hyperf_websocket {
|
|
|
|
|
server 127.0.0.1:9504;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
server {
|
|
|
|
|
listen 80;
|
|
|
|
|
server_name im-socket.xxx.com;
|
|
|
|
|
|
|
|
|
|
location / {
|
|
|
|
|
# WebSocket Header
|
|
|
|
|
proxy_http_version 1.1;
|
|
|
|
|
proxy_set_header Upgrade websocket;
|
|
|
|
|
proxy_set_header Connection "Upgrade";
|
|
|
|
|
|
|
|
|
|
# 将客户端的 Host 和 IP 信息一并转发到对应节点
|
|
|
|
|
proxy_set_header X-Real-IP $remote_addr;
|
|
|
|
|
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
|
|
|
|
|
proxy_set_header Host $http_host;
|
|
|
|
|
|
|
|
|
|
# 客户端与服务端无交互 60s 后自动断开连接,请根据实际业务场景设置
|
|
|
|
|
proxy_read_timeout 60s ;
|
|
|
|
|
|
|
|
|
|
# 执行代理访问真实服务器
|
|
|
|
|
proxy_pass http://hyperf_websocket;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
```
|
|
|
|
|
|
|
|
|
|
##### 配置图片域名
|
2021-07-12 22:31:37 +08:00
|
|
|
|
|
2020-12-19 21:04:59 +08:00
|
|
|
|
```
|
|
|
|
|
server {
|
|
|
|
|
listen 80;
|
|
|
|
|
server_name im-img.xxx.xxx;
|
|
|
|
|
index index.html;
|
|
|
|
|
|
|
|
|
|
# 默认禁止访问
|
|
|
|
|
location / {
|
|
|
|
|
deny all;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
# 只允许 访问 images 文件夹下的文件
|
|
|
|
|
location ^~ /media/{
|
|
|
|
|
# 设置目录别名(确保是项目上传文件目录)
|
|
|
|
|
# 例如 upload_dir = /www/data/lumenim
|
|
|
|
|
# 此时应配置 alias /www/data/lumenim/media/
|
|
|
|
|
|
|
|
|
|
alias /www/data/lumenim/media/;
|
|
|
|
|
|
|
|
|
|
# 设置缓存时间(3天)
|
|
|
|
|
expires 3d;
|
|
|
|
|
|
|
|
|
|
# 关闭访问日志
|
|
|
|
|
access_log off;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
```
|
|
|
|
|
|
|
|
|
|
### 注意事项
|
2021-07-12 22:31:37 +08:00
|
|
|
|
|
2021-07-08 19:09:06 +08:00
|
|
|
|
1. 请确保 PHP 安装 openssl、redis 扩展
|
2020-12-19 21:04:59 +08:00
|
|
|
|
2. 请确保 Swoole 扩展开启 openssl 扩展
|
2021-07-12 22:31:37 +08:00
|
|
|
|
|
2020-12-19 21:04:59 +08:00
|
|
|
|
```
|
|
|
|
|
[root@iZuf6cs69fbc86cwpu9iv3Z vhost]# php --ri swoole
|
|
|
|
|
swoole
|
|
|
|
|
Swoole => enabled
|
|
|
|
|
Author => Swoole Team <team@swoole.com>
|
|
|
|
|
Version => 4.5.9
|
|
|
|
|
...
|
|
|
|
|
openssl => OpenSSL 1.0.2k-fips 26 Jan 2017 (请确保此处开启)
|
2021-09-11 15:53:23 +08:00
|
|
|
|
```
|