php – A Command-Line Interface for the PHP Language

The php command is a command-line interface for the PHP scripting language. It allows users to run PHP scripts and execute PHP code directly from the command line. This can be useful for debugging, testing, and automation purposes.


To use the php command, simply open a terminal or command prompt and type php followed by the name of the PHP file you wish to run. For example:

php script.php

This will execute the PHP script named script.php in the current directory.

The php command can also be used to execute PHP code directly from the command line. To do this, use the -r option followed by the PHP code you wish to execute. For example:

php -r 'echo "Hello, world!";'

This will output Hello, world! to the console.

Another useful feature of the php command is the ability to run PHP scripts as a background process by using the & symbol at the end of the command. For example:

php script.php &

This will run the script.php script in the background, allowing you to continue using the terminal for other tasks.


The php command has a number of options that can be used to customize its behavior. The following table lists all available options:

Option Description
-a Run interactively
-B Run PHP code before processing input lines
-C Do not chdir to the script’s directory
-c <path> Use the specified php.ini file
-d <key>[=<value>] Set a configuration option
-E Run PHP code after processing input lines
-f <file> Parse and execute the specified file
-h Display help and exit
-i Show configuration information
-l Syntax check only
-n No configuration file will be used
-r <code> Run PHP code without using script tags
-s Output HTML syntax highlighted source
-v Display version information and exit
-w Output source with stripped comments and whitespace
-z <file> Load Zend extension

Troubleshooting Tips

If you encounter issues with the php command, here are a few troubleshooting tips:

  • Make sure that PHP is installed on your system and that the php command is in your system’s PATH.
  • Check that the PHP script you are trying to run is in the correct directory and has the correct file permissions.
  • If you are encountering syntax errors, use the -l option to perform a syntax check on the script.
  • If you are encountering issues with configuration options, use the -i option to display information about your PHP configuration.


  • The php command can be used on both Linux and Windows systems.
  • The php command can also be used with web servers such as Apache to serve PHP web pages.