PHP Cheatsheet - PHP & Composer Command Reference

This reference is for developers writing PHP apps and the people who deploy and operate them, running everything from single scripts to Laravel projects. It covers executing code on the CLI, the built-in dev server, Composer dependency and autoload management, extension/ini checks, and the php -l lint gate. Unlike a generic PHP command dump, entries are grouped by the workflow you actually repeat when scaffolding, debugging, and shipping a PHP application. After reading, you should be able to boot a Composer-based project locally, keep its autoload in sync, and gate merges on a lint pass.

Languages·36 commands·Last updated 2026-07-21
phpcomposercli

CLI Run 8

php script.php
Run a PHP script
php -a
Enter interactive shell
php -S localhost:8000
Start the built-in dev server
php -S localhost:8000 -t public/
Set the document root
php -l script.php
Lint (syntax check)
php -r "echo phpinfo();"
Run a one-liner
php -i
Print phpinfo()
php -m
List loaded extensions

Composer Dependency 10

composer init
Initialize composer.json
composer install
Install deps from lock file
composer update
Update deps and refresh lock
composer require vendor/package
Add a new dependency
composer remove vendor/package
Remove a dependency
composer dump-autoload
Regenerate autoload
composer dump-autoload -o
Optimize autoload (prod)
composer show
List installed packages
composer outdated
Check for outdated packages
composer self-update
Self-update Composer

Extensions & Config 6

php --ini
Show loaded ini file paths
php -d memory_limit=256M script.php
Set memory_limit temporarily
php -d display_errors=1 script.php
Enable error display
pecl install extension
Install a PECL extension
pecl uninstall extension
Uninstall an extension
php -r "echo PHP_VERSION;"
Print PHP version

Laravel Commands 8

php artisan serve
Start Laravel dev server
php artisan migrate
Run database migrations
php artisan migrate:fresh
Fresh: rollback all and re-migrate
php artisan make:model Post -mcr
Make model+migration+controller
php artisan route:list
List all routes
php artisan config:cache
Cache config (prod)
php artisan queue:work
Start the queue worker
php artisan tinker
Enter the REPL (tinker)

Profiling 4

php -d xdebug.mode=profile script.php
Xdebug profiling
php -d opcache.enable_cli=1 script.php
Enable OPcache on CLI
strace -p <pid>
Trace PHP syscalls (strace)
php -r "echo memory_get_peak_usage();"
Peak memory usage

Tips

  • In production always run composer dump-autoload -o to optimize performance.
  • php -S is for development only; use Nginx + PHP-FPM in production.
  • In Laravel production, cache config, routes and views: config:cache, route:cache, view:cache.

Official References

Each command links to its official documentation below, so you can verify the latest usage and read deeper.

Maintained by LaoHand

Publicly updated on Jul 21, 2026, continuously proofread against official docs.

Contact Us

Wrong command or description? Send us corrections, business inquiries or product feedback by email.

Contact Us