How to Check Current PHP Version in Ubuntu?

To check the current PHP version on Ubuntu, you can use the command-line interface. Open a terminal and use one of the following methods:

  1. Using php command:
    Open a terminal and type:
   php -v

This will display the PHP version installed on your system.

  1. Using phpinfo():
    Create a PHP file (for example, phpinfo.php) in your web server’s document root or any accessible directory. Add the following code to the file:
   <?php
   phpinfo();
   ?>

Save the file, and then access it through a web browser (e.g., http://localhost/phpinfo.php). It will display detailed information about your PHP installation, including the PHP version.

  1. Using dpkg (for PHP installed via package manager):
    If you installed PHP using the package manager (apt), you can check the installed PHP version with the following command:
   dpkg -l | grep php

This will display a list of installed PHP packages along with their versions.

These methods will show you the current PHP version installed on your Ubuntu system.