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
Checking PHP version on Ubuntu Linux
Checking PHP version on Ubuntu Linux
Software Requirements and Linux Command Line Conventions
Category Requirements, Conventions or Software Version Used
System Ubuntu Linux
Software PHP
Other Privileged access to your Linux system as root or via the sudo command.
Conventions # - requires given linux commands to be executed with root privileges either directly as a root user or by use of sudo command
$ - requires given linux commands to be executed as a regular non-privileged user

Check PHP version


SUBSCRIBE TO NEWSLETTER
Subscribe to Linux Career NEWSLETTER and receive latest Linux news, jobs, career advice and tutorials.


  1. 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
    
  2. 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 phpinfo function. 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
    
  3. Lastly, we could use the phpinfo function 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(); ?>
    


phpinfo PHP page accessed from web browser
phpinfo PHP page accessed from web browser

Conclusion

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.

FIND LATEST LINUX JOBS on LinuxCareers.com
Submit your RESUME, create a JOB ALERT or subscribe to RSS feed.
LINUX CAREER NEWSLETTER
Subscribe to NEWSLETTER and receive latest news, jobs, career advice and tutorials.
DO YOU NEED ADDITIONAL HELP?
Get extra help by visiting our LINUX FORUM or simply use comments below.

You may also be interested in:



Comments and Discussions