PHP 8 cheatsheet

PHP 8: Command line

10 common PHP 8 tasks.

Check the PHP version

Print the version and build details.

php -v

Start a development server

Serve the current folder at http://localhost:8000. For development only.

php -S localhost:8000

Serve a public folder with a router script

Serve a document root, sending unknown paths to a front controller.

php -S localhost:8000 -t public public/index.php

Run a script

Run a PHP file from the command line.

php script.php

Run a one-line command

Run PHP code without a file.

php -r "echo PHP_VERSION, PHP_EOL;"

Check a file for syntax errors

Check syntax without running the file.

php -l file.php

List loaded extensions

Show compiled-in extensions such as pdo_mysql and mbstring.

php -m

Find the php.ini file

Show which configuration files are loaded.

php --ini

Read a configuration value

Print the value of a single configuration setting.

php -r "echo ini_get('memory_limit'), PHP_EOL;"

Open the interactive shell

Start an interactive prompt. Exit with Ctrl+D.

php -a

Was this page helpful?