Check installed PHP version

Here are some ways that you can check the installed version of PHP in your system;

  1. Run php -v from the command line.
    $ php -v
    PHP 7.0.19 (cli) (built: Jun 21 2017 07:13:57) ( NTS )
    Copyright (c) 1997-2017 The PHP Group
    Zend Engine v3.0.0, Copyright (c) 1998-2017 Zend Technologies
  2. Run php -i from the command line.
    $ php -i | grep "PHP Version"
    PHP Version => 7.0.19
    PHP Version => 7.0.19
  3. Print PHP_VERSION_ID from PHP script.
    <?php 
    echo PHP_VERSION_ID;
    //Sample output: 70019
    ?>
  4. Print phpversion() output from PHP script.
    <?php 
    echo phpversion();
    //Sample output: 7.0.19
    ?>
  5. View from phpinfo() output
    <?php 
    phpinfo();
    ?>

  6. Query your package manager where the PHP packages are installed from. Here's a list of some common package managers and the corresponding commands;
Platform Location
homebrew brew list --versions php
Debian/Ubuntu
RedHat/CentOS

Sign up for Object Oriented PHP & MVC and many other great courses on Udemy to learn more.

Object Oriented PHP & MVC

Build a custom object oriented PHP MVC framework and then build an application with it!

Written by Mohd Shakir Zakaria.

Last updated on 2019-02-12.