$linuxjunkies
>

php(1)

PHP command-line interface for executing PHP scripts and running an interactive shell.

UbuntuDebianFedoraArch

Synopsis

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

Description

PHP is a server-side scripting language commonly used for web development, but the command-line interface allows you to execute PHP scripts directly from the terminal without a web server. You can run standalone scripts, process files, or interact with PHP in an interactive shell mode.

The CLI version includes all core PHP functionality and can access databases, read/write files, and execute system commands. It's useful for batch processing, cron jobs, command-line tools, and testing PHP code.

Common options

FlagWhat it does
-f fileParse and execute the named file (default behavior, often omitted)
-r codeExecute the given PHP code without opening a file; useful for one-liners
-iDisplay PHP information (phpinfo), equivalent to phpinfo() function
-vShow PHP version and build information
-mShow loaded extensions and modules
-l fileSyntax check only; do not execute (lint mode)
-d option=valueSet an ini directive; can be used multiple times
-S addr:portStart a local development server on given address and port
-aEnter interactive PHP shell (REPL mode)
-t docrootSpecify document root for built-in server
-wOutput source with all comments and whitespace stripped
--iniShow loaded configuration files and directives

Examples

Execute a PHP script file directly from the command line

php script.php

Execute PHP code directly without creating a file

php -r 'echo "Hello, World!\n";'

Start a built-in web server for development on port 8000

php -S localhost:8000

Check PHP file syntax without executing it

php -l config.php

Execute script with temporary ini override to show errors

php -d display_errors=1 script.php

Start interactive PHP shell (REPL) for testing code snippets

php -a

Display PHP info and filter for the active configuration file path

php -i | grep 'Loaded Configuration File'

List all loaded modules and check if PDO extension is installed

php -m | grep pdo