Linux "php" Command Line Options and Examples
PHP Command Line Interface 'CLI'

PHP is a widely-used general-purpose scripting language that is especially suited for Web development and can be embedded into HTML. This is the command line interface that enables you to do the following: You can parse and execute files by using parameter -f followed by the name of the file to be executed.


Usage:

php [options] [ -f ] file [[--] args...]




Command Line Options:

--bindpath
address:port|port
php --bindpath ...
-b
Bind Path for external FASTCGI Server mode (CGI only).
php -b ...
-C
Do not chdir to the script's directory (CGI only).
php -C ...
-q
Quiet-mode. Suppress HTTP header output (CGI only).
php -q ...
-T
count Measure execution time of script repeated count times (CGI only).
php -T ...
-c
path|file Look for php.ini file in the directory path or use the specified file
php -c ...
-n
No php.ini file will be used
php -n ...
-d
foo[=bar] Define INI entry foo with value bar
php -d ...
-e
Generate extended information for debugger/profiler
php -e ...
-f
file Parse and execute file
php -f ...
-i
PHP information and configuration
php -i ...
-l
Syntax check only (lint)
php -l ...
-m
Show compiled in modules
php -m ...
-r
code Run PHP code without using script tags '<?..?>'
php -r ...
-B
begin_code Run PHP begin_code before processing input lines
php -B ...
-R
code Run PHP code for every input line
php -R ...
-F
file Parse and execute file for every input line
php -F ...
-E
end_code Run PHP end_code after processing all input lines
php -E ...
-s
Output HTML syntax highlighted source
php -s ...
-S
addr:port Start built-in web server on the given local address and port
php -S ...
-t
docroot Specify the document root to be used by the built-in web server
php -t ...
-w
Output source with stripped comments and whitespace
php -w ...
-z
args... Arguments passed to script. Use '--' args when first argument starts with '-' or script is readfrom stdin
php -z ...
--rf
name Shows information about function name
php --rf ...
--rc
name Shows information about class name
php --rc ...
--re
name Shows information about extension name
php --re ...
--rz
name Shows information about Zend extension name
php --rz ...
--ri
name Shows configuration for extension name
php --ri ...
--ini
FILES/etc/php/@PHP_MAJOR_VERSION@.@PHP_MINOR_VERSION@/cli/php.iniThe configuration file for the CLI version of PHP./etc/php/@PHP_MAJOR_VERSION@.@PHP_MINOR_VERSION@/cgi/php.iniThe configuration file for the CGI version of PHP./etc/php/@PHP_MAJOR_VERSION@.@PHP_MINOR_VERSION@/apache2/php.iniThe configuration file for the version of PHP that apache2 uses.EXAMPLESphp -r 'echo "Hello World\n";'This command simply writes the text "Hello World" to standard out.php -r 'print_r(gd_info());'This shows the configuration of your gd extension. You can use this to easily check which image formatsyou can use. If you have any dynamic modules you may want to use the same ini file that php uses whenexecuted from your webserver. There are more extensions which have such a function. For dba use:php -r 'print_r(dba_handlers(1));'php -R 'echo strip_tags($argn)."\n";'This PHP command strips off the HTML tags line by line and outputs the result. To see how it works youcan first look at the following PHP command ´php -d html_errors=1 -i´ which uses PHP to output HTML for‐matted configuration information. If you then combine those two ´php ...|php ...´ you'll see what hap‐pens.php -E 'echo "Lines: $argi\n";'Using this PHP command you can count the lines being input.php -R '@$l+=count(file($argn));' -E 'echo "Lines:$l\n";'In this example PHP expects each input line being a file. It counts all lines of the files specified byeach input line and shows the summarized result. You may combine this with tools like find and changethe php scriptlet.php -R 'echo "$argn\n"; fgets(STDIN);'Since you have access to STDIN from within -B -R -F and -E you can skip certain input lines with yourcode. But note that in such cases $argi only counts the lines being processed by php itself. Having readthis you will guess what the above program does: skipping every second input line.TIPSYou can use a shebang line to automatically invoke php from scripts. Only the CLI version of PHP will ignoresuch a first line as shown below:#!/bin/php<?php// your script?>
php --ini ...