How to Check and print PHP version installed On Linux / Unix Server

You can check the version of PHP installed on a Linux or Unix server by using the following methods:

  1. From the command line: You can run the following command in your terminal or shell to display the version of PHP installed on the server:
    $ php -v
    PHP 7.3.22-1+ubuntu18.04.1+deb.sury.org+1 (cli)
    Copyright (c) 1997-2021 The PHP Group
    Zend Engine v3.3.22, Copyright (c) 1998-2021 Zend Technologies
    with Zend OPcache v7.3.22-1+ubuntu18.04.1+deb.sury.org+1, Copyright (c) 1999-2021, by Zend Technologies
  2. From a PHP script: You can create a simple PHP script to display the version of PHP installed on the server. To do this, create a file named php_version.php with the following contents:
    <?php
    echo 'Current PHP version: ' . phpversion();
    ?>

    Then run the script using the following command:

    $ php php_version.php
    Current PHP version: 7.3.22-1+ubuntu18.04.1+deb.sury.org+1

These methods will allow you to easily determine the version of PHP installed on your Linux or Unix server.

Leave a Comment