二進制打包
webman支持將項目打包成一個二進制文件,這使得webman無需php環(huán)境也能在linux系統(tǒng)運行起來。
注意
打包后的文件目前只支持運行在x86_64架構(gòu)的linux系統(tǒng)上,不支持windows和mac系統(tǒng)
需要關(guān)閉php.ini
的phar配置選項,既設(shè)置phar.readonly = 0
安裝命令行工具
composer require webman/console ^1.2.24
打包
運行命令
php webman build:bin
同時可以指定以哪個php版本打包,例如
php webman build:bin 8.1
打包后會在bulid目錄生成一個webman.bin
文件
啟動
將webman.bin上傳至linux服務(wù)器,執(zhí)行 ./webman.bin start
或 ./webman.bin start -d
即可啟動。
原理
- 首先將本地webman項目打包成一個phar文件
- 然后遠(yuǎn)程下載php8.x.micro.sfx到本地
- 將php8.x.micro.sfx和phar文件拼接為一個二進制文件
注意事項
- 本地php版本>=7.2都可以執(zhí)行打包命令,但是只能打包成php8的二進制文件
- 強烈建議本地php版本和打包版本一致,例如本地是php8.1,打包也用php8.1,避免出現(xiàn)兼容問題
- 打包會下載php8的源碼,但是并不會本地安裝,不會影響本地php環(huán)境
- webman.bin目前只支持在x86_64架構(gòu)的linux系統(tǒng)運行,不支持在mac系統(tǒng)運行
- 打包后的項目不支持reload,更新代碼需要restart重啟
- 默認(rèn)不打包env文件(
config/plugin/webman/console/app.php
中exclude_files控制),所以啟動時env文件應(yīng)該放置與webman.bin相同目錄下 - 運行過程中會在webman.bin所在目錄生成runtime目錄,用于存放日志文件
- 目前webman.bin不會讀取外部php.ini文件,如需要自定義php.ini,請在
/config/plugin/webman/console/app.php
文件custom_ini中設(shè)置 - 有些文件不需要打包,可以設(shè)置
config/plugin/webman/console/app.php
排除掉,避免打包后的文件過大 - 切勿將用戶上傳的文件存儲在二進制包中,因為以
phar://
協(xié)議操作用戶上傳的文件是非常危險的(phar反序列化漏洞)。用戶上傳的文件必須單獨存儲在包之外的磁盤中。 - 如果你的業(yè)務(wù)需要上傳文件到public目錄,需要將public目錄獨立出來放在webman.bin所在目錄,這時候需要配置
config/app.php
如下并重新打包。'public_path' => base_path(false) . DIRECTORY_SEPARATOR . 'public',
單獨下載靜態(tài)PHP
有時候你只是不想部署PHP環(huán)境,只需要一個PHP可執(zhí)行文件,點擊請點擊這里下載靜態(tài)php下載
提示
如需給靜態(tài)php指定php.ini文件,請使用以下命令php -c /your/path/php.ini start.php start -d
支持的擴展
Core, date, libxml, openssl, pcre, sqlite3, zlib, amqp, apcu, bcmath, calendar, ctype, curl, dba, dom, sockets, event, hash, fileinfo, filter, gd, gettext, json, iconv, SPL, session, standard, mbstring, igbinary, imagick, exif, mongodb, msgpack, mysqlnd, mysqli, pcntl, PDO, pdo_mysql, pdo_pgsql, pdo_sqlite, pdo_sqlsrv, pgsql, Phar, posix, readline, redis, Reflection, shmop, SimpleXML, soap, sodium, sqlsrv, sysvmsg, sysvsem, sysvshm, tokenizer, xlswriter, xml, xmlreader, xmlwriter, xsl, zip, memcache, Zend OPcache
項目出處
https://github.com/crazywhalecc/static-php-cli
https://github.com/walkor/static-php-cli