Forrest logo
back to context overview

php

Articles in our magazine for php:

PHP and the Command Line: the perfect match

PHP happens mostly in the IDE and with the command line you come into contact less often. Nevertheless, there are many helpful commands.

List of commands for php:

  • php:ai:35a17 Returns the current PHP version
    $ php -v
    try on your machine
    explain this command
  • php:ai:9b080 Retrieve ext-mongodb version
    $ php -i | grep mongo -C 2 | head -n 1 | awk -F ' ' '{print $3}'
    try on your machine
    explain this command
  • php:ai:9fbda Get the version of an installed PHP extension
    $ php -i | grep ${extension_name} | grep 'Version'
    try on your machine
    explain this command
  • php:code-beautifier-and-fixer:install:dev Install "PHP Code Beautifier and Fixer" from a Composer package as a dev dependency
    $ composer require --dev squizlabs/php_codesniffer
    try on your machine
    explain this command
  • php:code-beautifier-and-fixer:run Run PHP Code Beautifier and Fixer
    $ php vendor/bin/phpcbf
    try on your machine
    explain this command
  • php:code:run Run PHP code (Notes: Don't use tags; escape double quotes with backslash).
    $ php -r "${code}"
    try on your machine
    explain this command
  • php:config:show Show the PHP configuration for the CLI version
    $ php -i
    try on your machine
  • php:extensions:list Get a list of installed PHP extensions.
    $ php -m
    try on your machine
    explain this command
  • php:function:information Display information about a specific function.
    $ php --rf ${function_name}
    try on your machine
    explain this command
  • php:ini:which Show the location of the php.ini file (CLI)
    $ php -i | grep php\.ini
    try on your machine
  • php:install Install PHP.
    $ apt-get install php
    try on your machine
    explain this command
  • php:lint Check for syntax errors in php files (linting)
    $ php -l ${filename}
    try on your machine
  • php:phar:decompress Decompress a phar file to a given directory
    $ php -r '$phar = new Phar("${phar_file}"); $phar->extractTo("${directory_to_decompress_to}");'
    try on your machine
  • php:run:interactively Run PHP interactively.
    $ php -a
    try on your machine
    explain this command
  • php:script:run Run a PHP CLI script
    $ php ${filename}
    try on your machine
  • php:script:run:memory_limit Run a PHP CLI script with a defined memory limit
    $ php -d memory_limit=${limit_in_megabyte}M ${filename}
    try on your machine
    explain this command
  • php:server:start Starting the built-in web server
    $ php -S localhost:8000
    try on your machine
    explain this command
  • php:version:install Install a given PHP version.
    $ sudo apt install software-properties-common
    $ sudo add-apt-repository ppa:ondrej/php
    $ sudo apt update
    $ sudo apt install php${version}
    try on your machine
    explain this command
back to context overview