PharTools is a powerful PHP command-line tool to manage phar (PHP-Archive) files. It allows to create, extract, edit and view phar archives. It also includes a simple API to implement PharTools features on your own scripts.
Features:
- Create phar archives
- Extract phar archives
- Add, rename, delete, list files inside phar archives
- Get informations about phar archives (such as filesize, metadata, stub, etc...)
- Converts zip or tar archives to phar archives
- Converts phar archives to zip or tar archives
- Supports GZip and BZip2 compression types (BZip2 needs the php_bz2 extension which is already included on the Windows installer)
NOTE: to create phar files you need to set php.readonly to 0 in php.ini configuration
- At least PHP 5.3.0
- Optional: php_bz2 extension (to implement BZip2 compression support)
You can download the PharTools packages at this page. You will find three download options:
All platforms:
PharTools_vx.x.zip (script only)
Windows:
PharTools_vx.x_win_installer.exe (preconfigured script + precompiled PHP binaries)
PharTools_vx.x_win_portable.zip (preconfigured script + precompiled PHP binaries, no installer)
Please note that precompiled PHP binaries included in the portable and installer pacakages are provided with minimal extensions and configuration
PharTools installation on Windows is very simple. You have three choices:
- download the installer
- download the Windows portable package
- download the all-platforms zip package and configure PharTools manually
If choose the third option, you must simply edit the %PHP_PATH%
variable in phartools.cmd
file by setting a valid PHP executables path.
NOTE: if you install PharTools on Windows directories (like Program Files, Program Files (x86), ...) you may need administrator privileges in order to run the script correctly.
To install PharTools on Linux, download the all-platforms zip package. Then run:
$ ./phartools.sh
It should automatically install the PHP package (if missing) in order to run PharTools correctly or run PharTools directly. If you have problems while installing the PHP package, try to install it manually from your Linux distro package manager (i.e. apt-get).
You can run PharTools also on macOS. PharTools installation on macOS is very easy: you just need to download the all-platforms zip package. No PHP installation is required because PHP is already bundled with macOS since Mac OS X 10.0.0.
$ phartools -h
Usage:
-a <phar_archive> <files> Add files to a phar archive
-c <phar_archive> <files> [options] Create a phar archive
-d <phar_archive> <file> Delete a file from a phar archive
-e <phar_archive> [extract_path] Extract a phar archive
-h Show this help screen
-i <phar_archive> Show info about a phar archive
-l <phar_archive> List the content of a phar archive
-r <phar_archive> <oldname> <newname> Rename a file inside a phar archive
-a2p <archive> [compression] Convert a zip or tar archive to a phar archive
-p2a <phar_archive> [options] Convert a phar archive to a zip or tar archive
Adds files to a phar archive.
$ phartools -a <phar_archive> <files>
Parameters:
<phar_archive> is the destination phar archive
<files> are the files you want to add (wildcards are allowed)
Creates a phar archive.
$ phartools -c <phar_archive> <files> [options]
Parameters:
<phar_archive> is the name of the resulting phar archive
<files> are the source files to add inside the phar archive (wildcards are allowed)
[options] are optional switches:
-zgzip|-zbzip2 Compress the phar file using gzip or bzip2 compression
-m<metadata> Add metadata to the phar file (metadata format must be like 'key=>value,key2=>value2')
-s<stub> Set stub string for the phar
-r<regex> Include only files matching the regular expression
Deletes a file from a phar archive.
$ phartools -d <phar_archive> <file>
Parameters:
<phar_archive> is the destination phar archive
<file> is the file or the directory you want to delete
Extracts a phar archive.
$ phartools -e <phar_archive> [extract_path]
Parameters:
<phar_archive> is the destination phar archive
[extract_path] is an optional parameter specifying the path on which the phar archive contents will be extracted
Shows informations about a phar archive.
$ phartools -i <phar_archive>
Parameters:
<phar_archive> is the destination phar archive
Lists the content of a phar archive.
$ phartools -l <phar_archive>
Parameters:
<phar_archive> is the destination phar archive
Renames a file inside a phar archive.
$ phartools -r <phar_archive> <oldname> <newname>
Parameters:
<phar_archive> is the destination phar archive
<oldname> is the name of the file to rename
<newfile> is the new filename
Converts a zip or tar archive to a phar archive.
$ phartools -a2p <archive> [compression]
Parameters:
<archive> is the zip or tar archive to convert
[compression] is an optional parameter specifying compression:
gzip Compress the phar archive using gzip compression
bzip2 Compress the phar archive using bzip2 compression
Converts a phar archive to a zip or tar archive.
$ phartools -p2a <phar_archive> [options]
Parameters:
<phar_archive> is the destination phar archive
[options] are optional switches:
-zgzip|-zbzip2 Compress the resulting archive file using gzip or bzip2 compression (zip archives do not support compression)
-ozip|-otar Set the output archive format (zip or tar archive)
PharTools provides also an API to simplify the usage of phar archives:
include "path/to/phartools.php";
PharTools::<api_function>();
PharTools command-line interface
PharTools file list example
PharTools command-line interface
PharTools file list example
PharTools command-line interface
PharTools file list example
If you want you can support this project with a small donation by clicking ๐ต here. Your generosity will help us paying web hosting, domains, buying programs (such as IDEs, debuggers, etc...) and new hardware to improve software development. Thank you ๐
If you want to contribute to this project please follow the Contribution Guidelines.