Houze 文档 / 简介 / 部署框架

简介

部署框架

部署分三件事:把文件放上去、装好运行环境、让进程常驻。前两件是一次性的,第三件决定服务能不能扛住。

1. 上传代码

rsync -av --exclude=runtime ./ user@host:/www/houze/
ssh user@host "cd /www/houze && chmod -R 755 runtime public && chown -R www:www runtime"

runtime/ 必须可写(日志、模板缓存、pid),public/ 需要可写仅当你要用静态化功能。

2. 装运行环境

cd /www/houze
chmod +x web.sh && ./web.sh      # 下载 swoole-cli
./public/dist/swoole-cli-*-linux/bin/swoole-cli -v

不想用脚本也行:装 PHP 8.1+ 与 swoole 扩展(pecl install swoole),效果一样,只是版本得自己对。

3. 改配置

// config/server.php
'host' => '0.0.0.0',
'port' => 8848,

// config/mysql.php(用到数据库才改)
'host' => '127.0.0.1',
'user' => 'blog',
'password' => '******',
'database' => 'blog',

4. 常驻运行

框架自带 -d 守护参数,但它只管「脱离终端」,进程崩了不会自己回来。生产建议再套一层进程管理器:

# /etc/systemd/system/houze.service
[Unit]
Description=houze http service
After=network.target redis.service

[Service]
Type=simple
WorkingDirectory=/www/houze
ExecStart=/www/houze/public/dist/swoole-cli-linux/bin/swoole-cli index start http
Restart=always
RestartSec=3
User=www

[Install]
WantedBy=multi-user.target
systemctl daemon-reload && systemctl enable --now houze

5. 前面挂一层

框架直接对外也能跑,但 80/443、HTTPS 证书、多站点还是交给 Nginx 更省事:

server {
    listen 80;
    server_name example.com;

    location / {
        proxy_pass http://127.0.0.1:8848;
        proxy_http_version 1.1;
        proxy_set_header Host $host;
        proxy_set_header X-Real-IP $remote_addr;
        proxy_set_header Upgrade $http_upgrade;   # WebSocket 需要
        proxy_set_header Connection "upgrade";
    }
}

上线检查清单

  • config/app.php 的 de_bug 必须是 false;
  • config/reload.php 的 status 必须是 false(生产热重载会误重启);
  • config/admin.php 改掉默认账号密码;
  • runtime/ 不能被 Web 直接访问(本来就在 public/ 之外,确认 Nginx 没把根指错);
  • Redis 设密码,且只监听内网。

最后更新:2026-12-02 · 本文档对应 Houze v2.5.9,如有出入以框架源码为准。