2023-04-25 09:32:59 +08:00
# Phar packager
2022-02-16 02:13:55 +08:00
2023-04-25 09:32:59 +08:00
## Installation
2022-02-16 02:13:55 +08:00
```bash
composer require hyperf/phar
```
2023-04-25 09:32:59 +08:00
## Usage
2022-02-16 02:13:55 +08:00
2023-04-25 09:32:59 +08:00
- Packed by default
2022-02-16 02:13:55 +08:00
```shell
php bin/hyperf.php phar:build
```
2023-04-25 09:32:59 +08:00
- Set the package name
2022-02-16 02:13:55 +08:00
```shell
php bin/hyperf.php phar:build --name=your_project.phar
```
2023-04-25 09:32:59 +08:00
- Set the package version
2022-02-16 02:13:55 +08:00
```shell
php bin/hyperf.php phar:build --phar-version=1.0.1
```
2023-04-25 09:32:59 +08:00
- Set the startup file
2022-02-16 02:13:55 +08:00
```shell
php bin/hyperf.php phar:build --bin=bin/hyperf.php
```
2023-04-25 09:32:59 +08:00
- Set the packaging directory
2022-02-16 02:13:55 +08:00
```shell
php bin/hyperf.php phar:build --path=BASE_PATH
```
2023-04-25 09:32:59 +08:00
- Map external files
2022-02-16 02:13:55 +08:00
2023-04-25 09:32:59 +08:00
> Requires hyperf/phar version >= v2.1.7
2022-02-16 02:13:55 +08:00
2023-04-25 09:32:59 +08:00
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
2022-02-16 02:13:55 +08:00
```shell
php bin/hyperf.php phar:build -M .env
```
2023-04-25 09:32:59 +08:00
## run
2022-02-16 02:13:55 +08:00
```shell
php your_project.phar start
```
2023-04-25 09:32:59 +08:00
## Precautions
2022-02-16 02:13:55 +08:00
2023-04-25 09:32:59 +08:00
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.
2022-02-16 02:13:55 +08:00
2023-04-25 09:32:59 +08:00
> Modify as appropriate according to the actual situation
2022-02-16 02:13:55 +08:00
- pid_file
2023-04-25 09:32:59 +08:00
Modify `server.php` configuration.
2022-02-16 02:13:55 +08:00
```php
< ?php
return [
2023-04-25 09:32:59 +08:00
'settings' => [
'pid_file' => '/tmp/runtime/hyperf.pid',
],
2022-02-16 02:13:55 +08:00
];
```
- logger
2023-04-25 09:32:59 +08:00
Modify `logger.php` configuration
2022-02-16 02:13:55 +08:00
```php
< ?php
return [
2023-04-25 09:32:59 +08:00
'default' => [
'handler' => [
'class' => Monolog\Handler\StreamHandler::class,
'constructor' => [
'stream' => '/tmp/runtime/logs/hyperf.log',
'level' => Monolog\Logger::INFO,
],
],
],
2022-02-16 02:13:55 +08:00
];
```
- scan_cacheable
2023-04-25 09:32:59 +08:00
The Phar packager will automatically set `scan_cacheable` to `true` in `config.php` configuration.
2022-02-16 02:13:55 +08:00
2023-04-25 09:32:59 +08:00
Of course, it is also possible to actively modify this configuration to `true` .