LinuxCommandLibrary

php

PHP command-line interpreter

TLDR

Run a PHP script
$ php [script.php]
copy
Execute PHP code inline
$ php -r 'echo "Hello\n";'
copy
Start the built-in web server
$ php -S localhost:8000
copy
Start the built-in server with a document root
$ php -S localhost:8000 -t [/path/to/docroot]
copy
Enter interactive mode (REPL)
$ php -a
copy
Check a script for syntax errors without executing
$ php -l [script.php]
copy
Show phpinfo() output
$ php -i
copy
Show loaded modules
$ php -m
copy
Run with a specific php.ini
$ php -c [/path/to/php.ini] [script.php]
copy

SYNOPSIS

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

DESCRIPTION

php is the command-line interface to the PHP interpreter. It can execute PHP scripts, run inline code, lint files for syntax errors, and start a built-in development web server. PHP supports procedural, object-oriented, and functional programming paradigms.
The built-in web server (`-S`) is intended for development only and should not be used in production. It serves files from the current directory or a specified document root.

PARAMETERS

FILE

PHP script to execute.
-r CODE
Execute PHP code without script tags.
-S ADDR:PORT
Start the built-in development web server.
-t DOCROOT
Document root for the built-in web server.
-a
Run interactively (REPL mode).
-l
Syntax check only (lint), does not execute.
-i
Output phpinfo() configuration details.
-m
Show compiled-in modules.
-v
Show version information.
-c PATH
Use a specific php.ini file or directory.
-n
Run without a php.ini file.
-d DIRECTIVE=VALUE
Set a php.ini directive at runtime.
-e
Generate extended information for debuggers/profilers.
-f FILE
Parse and execute the given file (explicit form).
-w
Output source with comments and whitespace stripped.
-B CODE
Run code before processing stdin (with -R/-F).
-R CODE
Run code for every input line from stdin.
-F FILE
Parse and execute file for every input line from stdin.

CAVEATS

Configuration is controlled by php.ini; the loaded file location varies by system (use `php --ini` to find it). Extension availability depends on compile-time options and installed packages. The built-in web server is single-threaded and not suitable for production use.

HISTORY

PHP was created by Rasmus Lerdorf in 1994, originally as a set of CGI binaries for tracking visits to his web resume. It evolved into a full server-side scripting language. PHP 5 introduced a mature object model, and PHP 7 (2015) brought major performance improvements. PHP 8 (2020) added JIT compilation, named arguments, and attributes.

SEE ALSO

> TERMINAL_GEAR

Curated for the Linux community

Copied to clipboard