phar打包

phar是PHP里类似于JAR的一种打包文件,你可以利用phar将你的webman项目打包成单个phar文件,方便部署。

这里非常感谢 fuzqing 的PR.

注意
需要关闭php.ini的phar配置选项,既设置 phar.readonly = 0

安装命令行工具

composer require webman/console

配置设置

打开 config/plugin/webman/console/app.php 文件,设置 'exclude_pattern' => '#^(?!.*(composer.json|/.github/|/.idea/|/.git/|/.setting/|/runtime/|/vendor-bin/|/build/|vendor/webman/admin))(.*)$#',用户打包时排除一些无用的目录及文件,避免打包体积过大

打包

在webman项目根目录执行命令 php webman phar:pack
会在bulid目录生成一个webman.phar文件。

打包相关配置在 config/plugin/webman/console/app.php

启动停止相关命令

启动
php webman.phar startphp webman.phar start -d

停止
php webman.phar stop

查看状态
php webman.phar status

查看连接状态
php webman.phar connections

重启
php webman.phar restartphp webman.phar restart -d

说明

  • 运行webman.phar后会在webman.phar所在目录生成runtime目录,用于存放日志等临时文件。

  • 如果你的项目里使用了.env文件,需要将.env文件放在webman.phar所在目录。

  • 如果你的业务需要上传文件到public目录,也需要将public目录独立出来放在webman.phar所在目录,这时候需要配置config/app.php

    'public_path' => base_path(false) . DIRECTORY_SEPARATOR . 'public',

    业务可以使用助手函数public_path()找到实际的public目录位置。

  • webman.phar不支持在windows下开启自定义进程

编辑于2024-03-13 17:42:49 完善本页 +发起讨论
赞助商
QQ交流群 865805921