PHAR(1)
π phar(1) β the PHP Archive CLI, explained by your favorite unix girlie
okay so bestie, you know how a whole entire PHP app is like so many files? yeah. this tool is the glow-up that smooshes all of them into one single file. it's called a "phar" (PHP Archive) and it's literally made for easy distribution and installation. periodt. π
this page lives in the User Commands section of the manual (section 1, iykyk), and the tool answers to both phar and phar.phar. slay.
β¨ NAME β¨
phar, phar.phar β the PHAR (PHP archive) command line tool π¦
πΈ SYNOPSIS πΈ
phar <command> [options] ...
π DESCRIPTION π
the PHAR file format is the whole vibe: it lets you put entire PHP applications into a single file called a "phar" (PHP Archive) so distribution and installation are easy-peasy. π«Ά
with the phar command you can create, update or extract PHP archives. main character energy honestly.
here's the full command roster, no gatekeeping:
add compress delete extract help help-list info list meta-del meta-get meta-set pack sign stub-get stub-set tree version
π§ add command
adds entries to a PHAR package. like dropping new fits into the closet. π
required arguments:
-ffile β specifies the phar file to work on....β any number of input files and directories. if-iis in use then ONLY files matching the given regular expression get packed. if-xis given then files matching that regular expression are NOT being packed. π
optional arguments:
-aalias β provide an alias name for the phar file.-calgo β compression algorithm (see COMPRESSION below, bestie).-iregex β specifies a regular expression for input files.-llevel β number of preceding subdirectories to strip from file entries.-xregex β regular expression for input files to exclude.
π compress command
compresses or uncompresses all files, or just one selected entry.
required arguments:
-calgo β compression algorithm (see COMPRESSION).-ffile β specifies the phar file to work on.
optional arguments:
-eentry β name of entry to work on (must include the PHAR internal directory name if there is any).
π delete command
deletes an entry from a PHAR archive. bye boo π
required arguments:
-eentry β name of entry to work on (must include the PHAR internal directory name if any).-ffile β specifies the phar file to work on.
π extract command
extracts a PHAR package into a directory. unpacking, but make it cute.
required arguments:
-ffile β specifies the phar file to work on.
optional arguments:
-iregex β specifies a regular expression for input files.-xregex β regular expression for input files to exclude....β directory to extract to (defaults to'.').
π help command
shows this help, or help for a selected command.
optional arguments:
...β optional command to retrieve help for.
π help-list command
lists available commands. that's it, that's the whole job.
π₯ info command
gets information about a PHAR package.
by using -k it's possible to return a single value. ngl, super handy.
required arguments:
-ffile β specifies the phar file to work on.
optional arguments:
-kindex β subscription index to work on.
β list command
lists the contents of a PHAR archive.
required arguments:
-ffile β specifies the phar file to work on.
optional arguments:
-iregex β specifies a regular expression for input files.-xregex β regular expression for input files to exclude.
π¦ meta-del command
deletes meta information of a PHAR entry or a PHAR package.
if -k is given then the metadata is expected to be an array and the given index is the one being deleted.
if something was deleted the return value is 0; otherwise it's 1.
required arguments:
-ffile β specifies the phar file to work on.
optional arguments:
-eentry β name of entry to work on (must include the PHAR internal directory name if any).-kindex β subscription index to work on.
π meta-get command
gets meta information of a PHAR entry or a PHAR package in serialized form. if no output file is specified for meta data then stdout is being used.
you can also specify a particular index using -k. in that case the metadata is expected to be an array and the value of the given index is returned using echo rather than using serialize. if that index does not exist, or no meta data is present, then the return value is 1. π
required arguments:
-ffile β specifies the phar file to work on.
optional arguments:
-eentry β name of entry to work on (must include the PHAR internal directory name if any).-kindex β subscription index to work on.
πΈ meta-set command
sets meta data of a PHAR entry or a PHAR package using serialized input. if no input file is specified for meta data then stdin is being used.
you can also specify a particular index using -k. in that case the metadata is expected to be an array and the value of the given index is being set. if the metadata is not present or is empty, a new array will be created. if the metadata is present and is a flat value, then the return value is 1. also, when using -k the input is taken directly rather than being serialized.
required arguments:
-ffile β specifies the phar file to work on.-mmeta β meta data to store with entry (serialized php data).
optional arguments:
-eentry β name of entry to work on (must include the PHAR internal directory name if any).-kindex β subscription index to work on.
π pack command
packs files into a PHAR archive. this is the big one, bestie.
when using -s stub, then the stub file is being excluded from the list of input files/dirs. to create an archive that contains PEAR class PHP_Archive, point the -p argument to PHP/Archive.php.
required arguments:
-ffile β specifies the phar file to work on....β any number of input files and directories. if-iis in use then ONLY files matching the given regular expression are being packed. if-xis given then files matching that regular expression are NOT being packed.
optional arguments:
-aalias β provide an alias name for the phar file.-bbang β hash-bang line to start the archive (e.g.#!/usr/bin/php). the hash mark itself#!and the newline character are optional.-calgo β compression algorithm (see COMPRESSION).-hhash β selects the hash algorithm (see HASH).-iregex β specifies a regular expression for input files.-llevel β number of preceding subdirectories to strip from file entries.-ploader β location of PHP_Archive class file (pear list-files PHP_Archive). you can use'0'or'1'to locate it automatically using the mentionedpearcommand. when using'0'the command does not error out when the class file cannot be located. this switch also adds some code around the stub so that classPHP_Archivegets registered asphar://stream wrapper if necessary. and finally, this switch will add the filephar.incfrom this package and load it to ensure classPharis present. π€―-sstub β select the stub file.-xregex β regular expression for input files to exclude.-ykey β private key for OpenSSL signing.
π sign command
sets the signature hash algorithm.
required arguments:
-ffile β specifies the phar file to work on.-hhash β selects the hash algorithm (see HASH).
optional arguments:
-ykey β private key for OpenSSL signing.
π stub-get command
gets the stub of a PHAR file. if no output file is specified as stub then stdout is being used.
required arguments:
-ffile β specifies the phar file to work on.
optional arguments:
-sstub β select the stub file.
π§ stub-set command
sets the stub of a PHAR file. if no input file is specified as stub then stdin is being used.
required arguments:
-ffile β specifies the phar file to work on.
optional arguments:
-bbang β hash-bang line to start the archive (e.g.#!/usr/bin/php). the hash mark itself#!and the newline character are optional.-ploader β location of PHP_Archive class file (pear list-files PHP_Archive). you can use'0'or'1'to locate it automatically using the mentionedpearcommand. when using'0'the command does not error out when the class file cannot be located. this switch also adds some code around the stub so that classPHP_Archivegets registered asphar://stream wrapper if necessary. and finally, this switch will add the filephar.incfrom this package and load it to ensure classPharis present.-sstub β select the stub file.
π³ tree command
gets a directory tree for a PHAR archive. aesthetic.
required arguments:
-ffile β specifies the phar file to work on.
optional arguments:
-iregex β specifies a regular expression for input files.-xregex β regular expression for input files to exclude.
π¦ version command
gets information about the PHAR environment and the tool version. the vibe check, basically.
π COMPRESSION π
the algorithms, bestie:
0β no compressionnoneβ no compressionautoβ automatically select compression algorithmgzβ GZip compressiongzipβ GZip compressionbz2β BZip2 compressionbzip2β BZip2 compression
π HASH π
the hash algorithms:
md5β MD5sha1β SHA1sha256β SHA256sha512β SHA512opensslβ OpenSSL using SHA-1openssl_sha256β OpenSSL using SHA-256openssl_sha512β OpenSSL using SHA-512
π SEE ALSO π
for a more or less complete description of PHAR, look here: http://php.net/phar π«Ά
π BUGS π
you can view the list of known bugs, or report any new bug you found, at: https://github.com/php/php-src/issues
fr fr, if something's cursed, tell the maintainers β they actually want to know. π
π AUTHORS π
The PHP Group: Thies C. Arntzen, Stig Bakken, Andi Gutmans, Rasmus Lerdorf, Sam Ruby, Sascha Schumann, Zeev Suraski, Jim Winstead, Andrei Zmievski.
work for the PHP archive was done by Gregory Beaver, Marcus Boerger.
a list of active developers can be found here: http://www.php.net/credits.php
and last but not least, PHP was developed with the help of a huge amount of contributors all around the world. ππ that's genuinely so sweet.
β VERSION INFORMATION β
this manpage describes phar, version 8.3.36.
π COPYRIGHT π
Copyright Β© The PHP Group
this source file is subject to version 3.01 of the PHP license, that is bundled with this package in the file LICENSE, and is available through the world-wide-web at the following url: https://www.php.net/license/3_01.txt
if you did not receive a copy of the PHP license and are unable to obtain it through the world-wide-web, please send a note to license@php.net so we can mail you a copy immediately.
and that's the whole page, bestie β brought to you by The PHP Group, dated 2024, under the manual slot PHAR(1). go forth and pack some archives πβ¨π
π¦ where this page comes from
- alpine 3.24: php83-doc 8.3.36-r0 Β· PHP-3.01 BSD-3-Clause LGPL-2.0-or-later MIT Zend-2.0
- π girlified by deepseek-ai/DeepSeek-V4.1-Flash-1017 on : a language model's rewrite of the original, under its terms