After installing PHP or an entire LAMP server on Ubuntu Linux, there are a few ways you can check to see what version you’re running at any time. This can help you stay up to date and develop web applications that adhere to newer coding standards and conventions, since PHP is still being developed.
In this guide, we’ll show you multiple ways to check the version of PHP on Ubuntu. Feel free to pick whichever method is most convenient for your situation.
In this tutorial you will learn:
- How to check PHP version on Ubuntu
|Requirements, Conventions or Software Version Used
|Privileged access to your Linux system as root or via the
# – requires given linux commands to be executed with root privileges either directly as a root user or by use of
$ – requires given linux commands to be executed as a regular non-privileged user
Check PHP version
- We’ll start off with the quickest method. Open a command line terminal and type the following command.
$ php -version PHP 7.4.3 (cli) (built: May 26 2020 12:24:22) ( NTS ) Copyright (c) The PHP Group Zend Engine v3.4.0, Copyright (c) Zend Technologies with Zend OPcache v7.4.3, Copyright (c), by Zend Technologies
- What if we want a little more in depth information? You can start a PHP interactive shell (again, from the command line) and use the
phpinfofunction. This will return a ton of information, but will show the PHP version at the top.
$ php -a Interactive mode enabled php > phpinfo(); phpinfo() PHP Version => 7.4.3 ... php > exit
- Lastly, we could use the
phpinfofunction again, but inside of a php file. The perk of this method is that all the information will be formatted nicely for us and viewable inside a browser. We have a full guide on how to create a phpinfo.php page, but it basically just involves saving a PHP file with the following line of code and then accessing it from your browser.
<?php phpinfo(); ?>
In this tutorial, we saw three different methods for checking the PHP version on Ubuntu. Some methods are quicker, and some supply additional configuration information. Using one or more of the methods here should give you all the information you need about your PHP install.