← all projects

phar-web

PHP proof of concept that packages a website as a single portable phar executable
repo cli php php-phar proof-of-concept web-server MIT

Archived. Maintained tools now do what this project explored:

  • FrankenPHP embeds a PHP app and its web server in one static binary.
  • static-php-cli with phpmicro turns a phar into an executable that runs without PHP installed.
  • Box builds, compresses and signs phars.
  • NativePHP packages a Laravel app as a desktop app.
  • PHP Desktop bundles PHP with a Chromium window.

How to create a phar archive that's a portable PHP executable that can be served as a website and/or a commandline application.

Requirements

  1. humbug/box. This is used to manage phar file creation. a. If you have phive installed, install box by running phive install.
  2. (optional)Taskfile. This is used as a task runner. Alternatively read the .Taskfile and execute the contents manually, it's bash.

Anatomy

.
├── bootstrap.php
├── build
│   └── index.phar
├── dist
│   └── index-*.zip
└── src
    └── index.php

Building the phar

# 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