Binary Packaging

Webman supports packaging the project into a binary file, allowing Webman to run on Linux systems without a PHP environment.

Note
The packaged file currently only supports running on x86_64 architecture Linux systems and does not support Windows or Mac systems.
You need to disable the phar configuration option in php.ini, setting phar.readonly = 0.

Install Command Line Tool

composer require webman/console

Packaging

Run the command

php webman build:bin

You can also specify which PHP version to package with, for example

php webman build:bin 8.1

After packaging, a webman.bin file will be generated in the build directory.

Startup

Upload webman.bin to the Linux server, and execute ./webman.bin start or ./webman.bin start -d to start.

Principle

  • First, the local Webman project is packaged into a phar file.
  • Then, the php8.x.micro.sfx is downloaded to the local machine.
  • The php8.x.micro.sfx and the phar file are concatenated into a binary file.

Precautions

  • It is strongly recommended that the local PHP version is consistent with the packaged version; for example, if the local version is PHP 8.1, package it with PHP 8.1 to avoid compatibility issues.
  • The packaging will download the source code of PHP 8, but will not install it locally, hence will not affect the local PHP environment.
  • webman.bin currently only supports running on x86_64 architecture Linux systems and does not support running on Mac systems.
  • The packaged project does not support reload; to update the code, you need to restart.
  • By default, the env file is not packaged (controlled by exclude_files in config/plugin/webman/console/app.php), so the env file should be placed in the same directory as webman.bin during startup.
  • During runtime, a runtime directory will be generated in the directory where webman.bin is located to store log files.
  • Currently, webman.bin does not read external php.ini files. If you need to customize php.ini, please set it in the custom_ini field in the /config/plugin/webman/console/app.php file.
  • Some files may not need to be packaged; you can set exclusions in config/plugin/webman/console/app.php to avoid the packaged file being too large.
  • Binary packaging does not support using Swoole coroutines.
  • Do not store user-uploaded files in the binary package, as manipulating user-uploaded files with the phar:// protocol is very dangerous (phar deserialization vulnerability). User-uploaded files must be stored separately on disk outside of the package.
  • If your business requires uploading files to the public directory, you need to isolate the public directory and place it in the same directory as webman.bin. In this case, configure config/app.php as follows and repackage.
    'public_path' => base_path(false) . DIRECTORY_SEPARATOR . 'public',

Download Static PHP Separately

Sometimes you just don't want to deploy a PHP environment but only need an executable PHP file. Click here to download Static PHP Download.

Tip
If you need to specify a php.ini file for static PHP, use the following command php -c /your/path/php.ini start.php start -d.

Supported Extensions

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.

Project Source

https://github.com/crazywhalecc/static-php-cli
https://github.com/walkor/static-php-cli