docs/en/phar.md
composer require hyperf/phar
php bin/hyperf.php phar:build
php bin/hyperf.php phar:build --name=your_project.phar
php bin/hyperf.php phar:build --phar-version=1.0.1
php bin/hyperf.php phar:build --bin=bin/hyperf.php
php bin/hyperf.php phar:build --path=BASE_PATH
Requires hyperf/phar version >= v2.1.7
The following command can allow the phar package to read the .env file in the same directory, so that phar can be distributed to various environments
php bin/hyperf.php phar:build -M .env
php your_project.phar start
After packaging, it runs in the form of phar package, which is different from running in source code mode. The runtime directory in the phar package is not writable.
So we need to override some writable directory locations.
Modify as appropriate according to the actual situation
Modify server.php configuration.
<?php
return [
'settings' => [
'pid_file' => '/tmp/runtime/hyperf.pid',
],
];
Modify logger.php configuration
<?php
return [
'default' => [
'handler' => [
'class' => Monolog\Handler\StreamHandler::class,
'constructor' => [
'stream' => '/tmp/runtime/logs/hyperf.log',
'level' => Monolog\Logger::INFO,
],
],
],
];
The Phar packager will automatically set scan_cacheable to true in config.php configuration.
Of course, it is also possible to actively modify this configuration to true.