PHP Classes

How to Download PHP Application in a Single Archive Using the Package RA PHAR Compiler: Create PHAR archives from files in a directory

Recommend this page to a friend!
  Info   Documentation   View files Files   Install with Composer Install with Composer   Download Download   Reputation   Support forum   Blog    
Last Updated Ratings Unique User Downloads Download Rankings
2025-07-14 (Yesterday) RSS 2.0 feedNot yet rated by the usersTotal: Not yet counted Not yet ranked
Version License PHP version Categories
ra-phar-compiler 1.0MIT/X Consortium ...7PHP 5, Tools, Applications
Description 

Author

This package can create PHAR archives from files in a directory.

It provides an application script that can present a form to the user to request details to build a PHAR archive from a list of files that are in a directory.

The package can generate a PHAR archive using a given stub file provides by the user. The generated archive can be compressed using gzip or bz2 compression algorithms.

Picture of Roberto Aleman
  Performance   Level  
Name: Roberto Aleman <contact>
Classes: 30 packages by
Country: Venezuela Venezuela
Innovation award
Innovation award
Nominee: 19x

Winner: 3x

Instructions

Documentation

RA PHAR Compiler

RA PHAR Compiler | Author: Roberto Aleman | ventics.com

This is a simple, educational web-based PHP script designed to compile a PHP application and its assets into a single executable PHAR (PHP Archive) file. It's ideal for learning about the Phar class in PHP and for quickly packaging small to medium-sized PHP projects for distribution.

Features

  • Web-based Interface: Easy-to-use form for compiling PHAR files.
  • Automatic File Inclusion: Automatically includes all `.php`, `.css`, `.js`, `.png`, `.jpg`, `.jpeg`, `.gif`, `.json`, `.xml`, `.html`, `.htm`, and `.txt` files from the current directory and its subdirectories.
  • Self-Exclusion: The compiler script itself is automatically excluded from the generated PHAR.
  • Configurable Stub: Allows you to specify the main entry point file (stub) for your application within the PHAR.
  • Compression Options: Supports Gzip and Bzip2 compression for the PHAR archive.
  • Basic Validation: Includes checks for valid PHAR file names, existence of the stub file, and write permissions.
  • phar.readonly Check: Notifies the user if `phar.readonly` is enabled in `php.ini`, preventing PHAR creation.

Prerequisites

Before using this compiler, ensure your PHP environment meets the following requirements:

  1. PHP 7.0+: The `Phar` class is a standard PHP extension.
  2. php.ini Configuration: phar.readonly = 0: This setting in your php.inimust be set to 0* to allow the creation of PHAR files. On production servers, this is typically set to `1` for security reasons. extension=bz2 (optional)*: Enable this extension in `php.ini` if you intend to use Bzip2 compression. extension=zlib (optional)*: Ensure this extension is enabled in `php.ini` if you intend to use Gzip compression (often enabled by default).

How to Use

  1. Download/Create: Save the provided `phar_compiler.php` script into the root directory of the PHP application you wish to package.
  2. Access via Web Server: Open the script in your web browser through your local web server (e.g., `http://localhost/your_project_folder/phar_compiler.php`).
  3. Configure Options: PHAR file name:* Provide the desired name for your compiled archive (e.g., `my_application.phar`). It must end with `.phar`. Main file (stub):* Enter the path to your application's main entry point file (e.g., `index.php`). This file must be located in the same directory as the compiler script. Compression Type:* Select 'None', 'Gzip', or 'Bzip2' for the archive's compression.
  4. Compile: Click the "Compile to PHAR" button.
  5. Review Output: A message will display on the page indicating success or detailing any errors encountered during the compilation process.
  6. Locate PHAR: The generated `.phar` file will be found in the same directory where `phar_compiler.php` resides.

Running the Compiled PHAR

To execute your compiled PHAR file from the command line:

php your_application.phar

  Files folder image Files (2)  
File Role Description
Plain text file ra-phar-compiler.php Appl. Main script
Plain text file README.md Doc. README

The PHP Classes site has supported package installation using the Composer tool since 2013, as you may verify by reading this instructions page.
Install with Composer Install with Composer
 Version Control Unique User Downloads  
 0%
Total:0
This week:0