
PHP commands: A PHP CLI reference for version checks, syntax validation, extension diagnostics and quick local development. This guide explains what each command does, its syntax, practical examples, useful options, and common mistakes. Commands are shown for typical installations; flags can vary across operating-system and tool versions.
Before you start
Open a terminal appropriate for the operating system shown in the examples. Check that the required tool is installed and that you are running it with the permissions needed for your task. Replace sample names, paths, hostnames and IDs with values from your own environment.
Syntax at a glance
Square brackets usually indicate optional arguments, while uppercase words such as FILE, HOST and PACKAGE are placeholders that you replace. Keep quotes around paths or text that contains spaces. Commands should be tested on a safe sample before being used in production.
Quick command reference
| Command | What it does | Example | Useful options |
|---|---|---|---|
php -v | Show CLI PHP version | php -v | php --ini reports loaded configuration files |
php -l | Check PHP syntax without executing the script | php -l admin.php | Run the lint on every changed PHP file before deployment |
php -S | Start PHP’s built-in development server | php -S 127.0.0.1:8000 | -t DIRECTORY selects a document root |
php -m | List loaded PHP extensions | php -m | grep -i curl | --ri EXTENSION shows extension details |
php -r | Execute a short PHP expression | php -r "echo PHP_VERSION, PHP_EOL;" | Keep shell quoting in mind; avoid evaluating untrusted input |
Command syntax and examples explained
1. php -v
Purpose: Show CLI PHP version.
Syntax
php -vExample
php -vOptions and notes: php --ini reports loaded configuration files.
CLI PHP can differ from the PHP-FPM version serving a website.
2. php -l
Purpose: Check PHP syntax without executing the script.
Syntax
php -l FILE.phpExample
php -l admin.phpOptions and notes: Run the lint on every changed PHP file before deployment.
Lint detects parse errors, not runtime bugs or unsafe logic.
3. php -S
Purpose: Start PHP’s built-in development server.
Syntax
php -S HOST:PORTExample
php -S 127.0.0.1:8000Options and notes: -t DIRECTORY selects a document root.
Use only for development; it is not a production web-server replacement.
4. php -m
Purpose: List loaded PHP extensions.
Syntax
php -mExample
php -m | grep -i curlOptions and notes: --ri EXTENSION shows extension details.
Missing extensions can break database, image or HTTP features.
5. php -r
Purpose: Execute a short PHP expression.
Syntax
php -r CODEExample
php -r "echo PHP_VERSION, PHP_EOL;"Options and notes: Keep shell quoting in mind; avoid evaluating untrusted input.
This is useful for quick diagnostics but is not a substitute for a test script.
Common mistakes and troubleshooting
- Command not found: confirm the tool is installed and available on your PATH; open a new terminal after changing PATH.
- Permission denied: verify the current account, file permissions and target path. Use administrator/root privileges only when genuinely required.
- Unexpected output: check the command version, quoting, current directory and exact arguments. Consult the local help or manual for options supported by your build.
- Destructive operations: preview the target and keep a backup before deleting data, rewriting history, flashing a partition or changing system configuration.
Safety tips
Review every command before running it, especially commands that delete files, change permissions, flash firmware, alter a database or expose a network service. For network scanning and remote administration, work only on devices and systems you own or are authorized to test. Keep credentials, private keys, access tokens and log files private.
Frequently asked questions
Do these commands work on every system?
Not always. Some commands are specific to Windows, Linux, Android, a particular package manager or an installed tool version. Use the syntax shown for your platform and check local help when a flag is unavailable.
Can I copy and run every example exactly?
Use the examples as templates. Replace placeholders such as filenames, package IDs, hostnames and paths with your own values, and verify the effect before executing a command that changes data or system state.
Conclusion
Use this reference as a starting point, then confirm flags in the tool’s official help or manual for your installed version. A clear understanding of syntax, options and side effects makes command-line work more reliable.