How to Turn Any PHP Script into a Cross‑Platform Executable with PHPacker
PHPacker lets you bundle any PHP script or PHAR into a single, cross‑platform executable; this guide shows how to install it via Composer, create a sample script, run the build command for various platforms, and customize output with options such as destination, PHP version, and ini files.
Introduction
PHPacker is a tool that packages any PHP script or PHAR file into a standalone, cross‑platform executable, simplifying distribution by handling all the complexities of bundling PHP with the application.
Installation
composer require phpacker/phpacker --devQuick Start
Create a simple PHP script, for example app.php:
<?php
/**
* @desc app.php description
* @author Tinywan (ShaoBo Wan)
*/
declare(strict_types=1);
echo 'Hello 开源技术小栈' . PHP_EOL;Build an executable from the script with a single command: vendor/bin/phpacker build --src=./app.php The tool will prompt you to select a target platform. After the build finishes you will find binaries for the chosen platforms, for example:
# Linux
build/linux/linux-arm
Hello 开源技术小栈
# Windows
build/windows/windows-x64.exe
Hello 开源技术小栈Basic Build Commands
If you run the build command without additional arguments, PHPacker interactively asks for basic information. The same options can be supplied directly as parameters:
# Build for a specific platform and architecture
phpacker build mac arm --src=./app.phar
# Build for all supported platforms
phpacker build all --src=./app.phar
# Build with a custom output directory
phpacker build --src=./app.phar --dest=./custom-build-path
# Build with a specific PHP configuration file
phpacker build --src=./app.phar --ini=./custom-php.ini
# Prompt INI definitions interactively
phpacker build --src=./app.phar --ini
# Build with a specific PHP version
phpacker build --src=./app.phar --php=8.3Signed-in readers can open the original source through BestHub's protected redirect.
This article has been distilled and summarized from source material, then republished for learning and reference. If you believe it infringes your rights, please contactand we will review it promptly.
Open Source Tech Hub
Sharing cutting-edge internet technologies and practical AI resources.
How this landed with the community
Was this worth your time?
0 Comments
Thoughtful readers leave field notes, pushback, and hard-won operational detail here.
