How do I find out PHP version under Linux operating systems? What command do I need to type to show the PHP version under Unix-like systems? How to find out what PHP version is installed on my server when I can now login using the ssh command and check the PHP version?

PHP is a server-side programming language often used with Apache or Nginx server. Popular apps like WordPress, MediaWiki, and other need PHP. Let us see, how to check and print PHP version installed on your Linux or Unix server.
Tutorial details
Difficulty level Easy
Root privileges No
Requirements PHP
Est. reading time 5 minutes

Checking and printing PHP version installed on your Linux and Unix server

To find out php version installed on the server type any one of the following commands on your server.

  1. Open the terminal prompt and then type the following commands.
  2. Login to the server using the ssh command. For example: ssh user@linux-unix-server
  3. Display PHP version, run: php --version OR php-cgi --version
  4. To print PHP 7 version, type: php7 --version OR php7-cgi --version
  5. Find latest PHP 8 version, type: php8 --version OR php8-cgi --version

Let us see all commands and examples in details.

How to check the PHP version using the CLI

The most reliable way to print PHP version from the Linux and Unix command line is to type the following command:
$ php --version
Outputs from my SUSE Enterprise/OpenSUSE Linux server:

PHP 7.4.6 (cli) ( NTS )
Copyright (c) The PHP Group
Zend Engine v3.4.0, Copyright (c) Zend Technologies
    with Zend OPcache v7.4.6, Copyright (c), by Zend Technologies

Here is another output indicating that I am using PHP 5.x:
$ php -v
Note that I used -v instead of long --version:

PHP 5.3.3 (cgi-fcgi) (built: Jun 25 2012 04:38:39)
Copyright (c) 1997-2010 The PHP Group
Zend Engine v2.3.0, Copyright (c) 1998-2010 Zend Technologies
    with Suhosin v0.9.32.1, Copyright (c) 2007-2010, by SektionEins GmbH

Getting PHP information from the CLI

Pass the -i to your php binary. For instance:
php -i
php -i | more
# see if PHP pdo module loaded or not #
php -i | grep pdo

PHP Version => 7.4.3
System => Linux nixcraft-wks01 5.4.0-62-generic #70-Ubuntu SMP Tue Jan 12 12:45:47 UTC 2021 x86_64
Build Date => Oct  6 2020 15:47:56
Server API => Command Line Interface
Virtual Directory Support => disabled
Configuration File (php.ini) Path => /etc/php/7.4/cli
Loaded Configuration File => /etc/php/7.4/cli/php.ini
Scan this dir for additional .ini files => /etc/php/7.4/cli/conf.d
Additional .ini files parsed => /etc/php/7.4/cli/conf.d/10-opcache.ini,
PHP API => 20190902
PHP Extension => 20190902
Zend Extension => 320190902
Zend Extension Build => API320190902,NTS
PHP Extension Build => API20190902,NTS
Debug Build => no
Thread Safety => disabled
Zend Signal Handling => enabled
Zend Memory Manager => enabled
Zend Multibyte Support => disabled
IPv6 Support => enabled
DTrace Support => available, disabled
Registered PHP Streams => https, ftps, compress.zlib, php, file, glob, data, http, ftp, phar
Registered Stream Socket Transports => tcp, udp, unix, udg, ssl, tls, tlsv1.0, tlsv1.1, tlsv1.2, tlsv1.3
Registered Stream Filters => zlib.*, string.rot13, string.toupper, string.tolower, string.strip_tags, convert.*, consumed, dechunk, convert.iconv.*
This program makes use of the Zend Scripting Language Engine:
Zend Engine v3.4.0, Copyright (c) Zend Technologies
    with Zend OPcache v7.4.3, Copyright (c), by Zend Technologies

Determining PHP version with phpinfo()

Sometimes we don’t have shell access to a production web server. In such cases, the most reliable way to find the PHP version is to use the phpinfo(). Create a php script as follows (myversion.php) on your desktop:

// program to tell php version using ftp/sftp client

Upload the above file using ftp/sftp client and type the url:

Fig.01: What version of PHP am I running on my Unix / Linux / Windows server?

Make sure you delete the file once you discovered the PHP version. You can also hide PHP version. Another option is to use the phpversion() function to display only the PHP server version using a web browser. The code is:
  <title>PHP version</title>
<h1>PHP version</h1>
 <?php  echo 'Current PHP version on this box: ' . phpversion(); ?>

Using package manager to find out PHP version on Linux

Type the following dnf command/yum command on RHEL / Red Hat / CentOS / Fedora Linux based system to find out php version:
$ yum info php
My CentOS 8 Linux server running PHP version 7.4.14:

Last metadata expiration check: 1:21:08 ago on Thu Jan 14 07:02:15 2021.
Available Packages
Name         : php
Version      : 7.4.14
Release      : 1.el8.remi
Architecture : x86_64
Size         : 3.0 M
Source       : php-7.4.14-1.el8.remi.src.rpm
Repository   : remi-modular
Summary      : PHP scripting language for creating dynamic web sites
URL          :
License      : PHP and Zend and BSD and MIT and ASL 1.0 and NCSA
Description  : PHP is an HTML-embedded scripting language. PHP attempts to make it
             : easy for developers to write dynamically generated web pages. PHP also
             : offers built-in database integration for several commercial and
             : non-commercial database management systems, so writing a
             : database-enabled webpage with PHP is fairly simple. The most common
             : use of PHP coding is probably as a replacement for CGI scripts.
             : The php package contains the module (often referred to as mod_php)
             : which adds support for the PHP language to Apache HTTP Server.

We can list packages as follows using the rpm command:
$ rpm -qa | grep php

If you are using Debian / Ubuntu Linux based system, type the following command to find out php version:
$ dpkg --list | grep php
Sample outputs indicating PHP installed for Apache called mod_php5 version 5.3.3:

ii  libapache2-mod-php5                      5.3.3-7+squeeze14                  server-side, HTML-embedded scripting language (Apache 2 module)
ii  php5                                     5.3.3-7+squeeze14                  server-side, HTML-embedded scripting language (metapackage)
ii  php5-cgi                                 5.3.3-7+squeeze14                  server-side, HTML-embedded scripting language (CGI binary)
ii  php5-cli                                 5.3.3-7+squeeze14                  command-line interpreter for the php5 scripting language
ii  php5-common                              5.3.3-7+squeeze14                  Common files for packages built from the php5 source
ii  php5-gd                                  5.3.3-7+squeeze14                  GD module for php5
ii  php5-mysql                               5.3.3-7+squeeze14                  MySQL module for php5
ii  php5-suhosin                                            advanced protection module for php5

Let us try one more time:
$ dpkg --list | grep php
Another output from Ubuntu Linux server showing PHP version 7.x installed for Nginx using fmp (FastCGI Process Manager) mode:

ii  php-common                       1:35ubuntu6                                all          Common files for PHP packages
ii  php-igbinary                     1.2.1-10-ge0e66b9+1.2.1-2                  amd64        igbinary PHP serializer
ii  php-memcached                    2.2.0-51-ge573a6e+2.2.0-2build2            amd64        memcached extension module for PHP5, uses libmemcached
ii  php-msgpack                      2.0.1+0.5.7-1                              amd64        PHP extension for interfacing with MessagePack
ii  php-pear                         1:1.10.1+submodules+notgz-6                all          PEAR Base System
ii  php7.0                           7.0.18-0ubuntu0.16.04.1                    all          server-side, HTML-embedded scripting language (metapackage)
ii  php7.0-cli                       7.0.18-0ubuntu0.16.04.1                    amd64        command-line interpreter for the PHP scripting language
ii  php7.0-common                    7.0.18-0ubuntu0.16.04.1                    amd64        documentation, examples and common module for PHP
ii  php7.0-curl                      7.0.18-0ubuntu0.16.04.1                    amd64        CURL module for PHP
ii  php7.0-fpm                       7.0.18-0ubuntu0.16.04.1                    amd64        server-side, HTML-embedded scripting language (FPM-CGI binary)
ii  php7.0-gd                        7.0.18-0ubuntu0.16.04.1                    amd64        GD module for PHP
ii  php7.0-json                      7.0.18-0ubuntu0.16.04.1                    amd64        JSON module for PHP
ii  php7.0-mysql                     7.0.18-0ubuntu0.16.04.1                    amd64        MySQL module for PHP
ii  php7.0-opcache                   7.0.18-0ubuntu0.16.04.1                    amd64        Zend OpCache module for PHP
ii  php7.0-readline                  7.0.18-0ubuntu0.16.04.1                    amd64        readline module for PHP
ii  php7.0-xml                       7.0.18-0ubuntu0.16.04.1                    amd64        DOM, SimpleXML, WDDX, XML, and XSL module for PHP
ii  php7.0-xmlrpc                    7.0.18-0ubuntu0.16.04.1                    amd64        XMLRPC-EPI module for PHP
ii  php7.0-zip                       7.0.18-0ubuntu0.16.04.1                    amd64        Zip module for PHP

Installing latest stable PHP

See the following docs as per your OS:

Summing up

Finding out the version of the PHP on your Linux or Unix server is a simple task. In this quick tutorial, I explained various methods about how to find the version of PHP. Please note that you may see multiple PHP versions on the server, such as PHP 5.x, 7.x, and 8.x. See PHP documentation for more info and our 25 PHP security best practices for sys admins post.

🐧 Get the latest tutorials on Linux, Open Source & DevOps via RSS feed or Weekly email newsletter.

🐧 4 comments so far... add one

CategoryList of Unix and Linux commands
Disk space analyzersdf ncdu pydf
File Managementcat cp mkdir tree
FirewallAlpine Awall CentOS 8 OpenSUSE RHEL 8 Ubuntu 16.04 Ubuntu 18.04 Ubuntu 20.04
Network UtilitiesNetHogs dig host ip nmap
OpenVPNCentOS 7 CentOS 8 Debian 10 Debian 8/9 Ubuntu 18.04 Ubuntu 20.04
Package Managerapk apt
Processes Managementbg chroot cron disown fg jobs killall kill pidof pstree pwdx time
Searchinggrep whereis which
User Informationgroups id lastcomm last lid/libuser-lid logname members users whoami who w
WireGuard VPNAlpine CentOS 8 Debian 10 Firewall Ubuntu 20.04
4 comments… add one
  • Larry Mar 13, 2012 @ 6:37

    Show a list of php extensions:

    foreach (get_loaded_extensions() as $i => $e) {
       echo $e .' => '. phpversion($e). '<br/>';

  • LARIS Dec 18, 2013 @ 15:27


    Firstly, I’d like to thank you for this post.
    Secondly, I’ll be thankful if you can tell me how can I know which Ajax version (or librairy) my php server is using ?

    For info, I’m using ClearOS with PHP 5.1.6 and I’m not able to use Ajax fonctions on this server, tried on xampp server on windows and it’s working fine.

    Many Thanks for your help.

  • jubha Aug 11, 2015 @ 3:32

    i tried all of the above codes but nothing has displayed about php. so i imagine it is not installed in my vps ubuntu 14.04
    but apache is installed and working. How can i install php?

  • Mikko Rantalainen Apr 23, 2021 @ 14:19

    Note that even if you have shell access to server, you may still want to run phpinfo() through the web server (that is, reading results with a browser from the production web site).

    It’s possible to install different PHP version for the shell than the version actually running within your web server.

Leave a Reply

Your email address will not be published.

Use HTML <pre>...</pre> for code samples. Still have questions? Post it on our forum