START
快速开始
装依赖、编译、启动,并确认第一个路由能返回内容。
1. 安装依赖
Paozhu 需要 C++20 编译器、CMake、Asio、OpenSSL、Zlib 与 Brotli。SQLite 和 Redis 是可选能力,按构建开关启用。
terminalbash
# macOS
brew install asio cmake openssl zlib brotli
# Ubuntu / Debian
sudo apt-get install cmake
sudo apt-get install -y brotli libbrotli-dev zlib1g-dev
sudo apt-get install openssl libssl-dev
# Rocky / AlmaLinux
sudo dnf -y upgrade
sudo dnf install gcc g++ cmake libasan
sudo dnf install brotli brotli-devel openssl openssl-devel2. 获取源码并清理脚手架
仓库自带完整示例与 CMS 控制器。mini_project.sh 会只保留 testhello.cpp 和 serverwatch.cpp,适合作为新项目起点。
terminalbash
git clone https://github.com/hggq/paozhu.git myproject
cd myproject
sh mini_project.sh
# keep only testhello.cpp + serverwatch.cpp as a clean starting point3. 编译
CMake 未指定构建类型时默认是 Debug;生产环境请显式使用 -DCMAKE_BUILD_TYPE=Release。可执行文件输出到项目根目录的 bin/。
terminalbash
unzip asio.zip
mkdir build && cd build
cmake .. -DCMAKE_BUILD_TYPE=Release
make -j8
cd ..
# run from the project root
./bin/paozhu conf/server.conf4. 认识目录
project treetext
paozhu/
├── bin/paozhu # built executable
├── conf/ # server.conf / orm.conf / acme.conf / *.sql
├── controller/
│ ├── src/ # business controllers, scanned for annotations
│ └── include/ # header stubs generated at configure time
├── models/ # thin business model wrappers
├── orm/ # generated field metadata + SQL operation layer
├── view/ viewsrc/ # templates and compiled views
├── www/default/ # static site root (wwwpath)
├── log/ temp/ # logs and temporary files
├── startup/ # main_dev / main_daemon / main_docker
└── common/autocontrolmethod.hpp # generated route table5. 启动并验证
从项目根目录启动。启动参数可以是 conf/server.conf,也可以是 conf/ 目录。默认监听 80 与 443 端口;本地端口被占用时改 httpport / httpsport 或用 hosts 绑定域名。
terminalbash
curl -I http://127.0.0.1/hello
curl -I http://127.0.0.1/plaintext
# If port 80 is busy:
lsof -i :80
sudo ss -tlnp | grep 80
# change conf/server.conf when the port is busy:
# httpport = 8080