How to create a phar archive that's a portable PHP executable that can be served as a website and/or a commandline application.
- humbug/box. This is used to manage phar file creation.
a. If you have phive installed, install box by running
phive install
. - (optional)Taskfile. This is used as a task runner. Alternatively read the .Taskfile and execute the contents manually, it's bash.
.
├── bootstrap.php
├── build
│ └── index.phar
├── dist
│ └── index-*.zip
└── src
└── index.php
- The
src
directory contains the source files of the PHP project. - Box compiles a
build/index.phar
, which is included by thebootstrap.php
file. - The dist task creates a timestamped
dist/index-*.zip
file which can be uncompressed on the production server or ran from a Docker container.
# Compile in the build/ directory for inspection
t compile
# Compile and run via the commandline:
t crun
# Compile and serve
t cserve
# Create a zip file for distribution
t dist