前言
因为本系列主要解读zanphp源码, 所以环境采用作者自己搭建的适用 zan 系列的 docker 环境。
- https://github.com/cjeruen/zan-docker
环境相关说明
本系列基础目录都在 ~/zan-code 目录下进行
如有变更 自行 切换目录
安装 docker 与 composer
不多介绍
下载 zan-docker
git clone https://github.com/cjeruen/zan-docker.git
下载 zan-installer
git clone https://github.com/youzan/zan-installer.git
安装 zan-installer 依赖
cd zan-installer && composer install
当前所在 目录 ~/zan-code/zan-installer
生成项目
生成 http 项目
php ./zan
生成 tcp 项目
php ./zan
生成 websocket 项目
php ./zan
查看生成的三个项目
移动项目到 zan-docker
mv ~/zan-code/zan-installer/http-demo ~/zan-code/zan-docker/opt/http-demo
mv ~/zan-code/zan-installer/tcp-demo ~/zan-code/zan-docker/opt/tcp-demo
mv ~/zan-code/zan-installer/websocket-demo ~/zan-code/zan-docker/opt/websocket-demo
修改配置文件
参考配置: https://github.com/cjeruen/za...
http-demo配置
// ~/zan-code/zan-docker/opt/http-demo/resource/config/test/connection/mysql.php
'host' => '127.0.0.1', // 改为 'host' => 'mysql_zan'
'user' => 'root', // 改为 'user' => 'root'
'password' => '123456', // 改为 'password' => 'root'
// ~/zan-code/zan-docker/opt/http-demo/resource/config/test/connection/redis.php
'host' => '127.0.0.1', // 改为 'host' => 'redis_zan',
// ~/zan-code/zan-docker/opt/http-demo/resource/config/test/connection/tcp.php
'host' => '127.0.0.1', // 改为 'host' => 'cat_zan',
// ~/zan-code/zan-docker/opt/http-demo/resource/config/test/monitor/trace.php
"run" => false, // 改为 "run" => true,
// ~/zan-code/zan-docker/opt/http-demo/resource/config/test/server.php
'session' => [
'run' => false, // 改为 'run' => true,
'store_key' => 'demo.session.session',
],
// ~/zan-code/zan-docker/opt/http-demo/resource/config/test/registry.php
"app_names" => [
// "tcp-demo" // 去掉注释 改为 "tcp-demo"
],
"host" => "127.0.0.1", // 改为 "host" => "etcd_zan",
tcp-demo配置
// ~/zan-code/zan-docker/opt/tcp-demo/resource/config/test/connection/mysql.php
'host' => '127.0.0.1', // 改为 'host' => 'mysql_zan'
'user' => 'root', // 改为 'user' => 'root'
'password' => '123456', // 改为 'password' => 'root'
// ~/zan-code/zan-docker/opt/tcp-demo/resource/config/test/connection/redis.php
'host' => '127.0.0.1', // 改为 'host' => 'redis_zan',
// ~/zan-code/zan-docker/opt/tcp-demo/resource/config/test/connection/tcp.php
'host' => '127.0.0.1', // 改为 'host' => 'cat_zan',
// ~/zan-code/zan-docker/opt/tcp-demo/resource/config/test/monitor/trace.php
"run" => false, // 改为 "run" => true,
// ~/zan-code/zan-docker/opt/tcp-demo/resource/config/test/registry.php
"enable" => false, // 改为 "enable" =>
"host" => "127.0.0.1", // 改为 "host" => "etcd_zan",
构建 zan-docker
cd ~/zan-code/zan-docker && docker-compose build
启动 docker
docker-compose up -d
创建数据库
连接 cat_zan 数据库 (mysql -hmysql_zan -uroot -p)
创建数据库 cat
导入数据表 ~/zan-code/zan-docker/cat/zan/src/Cat.sql
查看演示
- http://localhost:8030/index/index/index
- http://localhost:8030/index/index/json
- http://localhost:8030/index/index/showTpl
- http://localhost:8030/index/index/dbOperation
- http://localhost:8030/index/index/redisOperation
- http://localhost:8030/index/index/httpRemoteService
- http://localhost:8030/index/index/novaRemoteService
- http://localhost:2281/cat
总结
环境安装就到此为止了。后面源码读起来