Find Out PHP Version installed On Unix / Linux Server

last updated in Categories , , ,

How do I find out php version under Linux operating systems? How do I find out php version under Unix like systems? How to find out what version of PHP is installed on my server?

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

$ php --version

OR

$ php-cgi --version

OR

kbd>php7.0 --version

OR

$ php5-cgi --version

OR

$ php5 --version
Sample output

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

Here is another output indicating that I am using PHP 7.x:
$ php -v
Sample outputs:

PHP 7.0.18-0ubuntu0.16.04.1 (cli) ( NTS )
Copyright (c) 1997-2017 The PHP Group
Zend Engine v3.0.0, Copyright (c) 1998-2017 Zend Technologies
    with Zend OPcache v7.0.18-0ubuntu0.16.04.1, Copyright (c) 1999-2017, by Zend Technologies

I do not have SSH based access to my hosting server

If you can not login to your server using ssh command. Create a php script as follows (myversion.php):

<?php
// program to tell php version using ftp client
phpinfo();
?>

Upload the above file using ftp/sftp client and type the url:
http://your-domain-name-here/myversion.php
OR
http://your-domain-name-here/path/to/myversion.php
Sample outputs:

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

Using package manager

Type the following command on RHEL / Red Hat / CentOS / Fedora Linux based system to find out php version:
$ yum info php
Sample outputs:

Loaded plugins: auto-update-debuginfo, protectbase, rhnplugin
0 packages excluded due to repository protections
Installed Packages
Name        : php
Arch        : x86_64
Version     : 5.3.3
Release     : 14.el6_3
Size        : 3.5 M
Repo        : installed
From repo   : rhel-x86_64-server-6
Summary     : PHP scripting language for creating dynamic web sites
URL         : http://www.php.net/
License     : PHP
Description : PHP is an HTML-embedded scripting language. PHP attempts to make it
            : easy for developers to write dynamically generated webpages. 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 which adds support for the PHP
            : language to Apache HTTP Server.

OR just list packages:
$ 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:

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                             0.9.32.1-1                         advanced protection module for php5

Another output from Ubuntu Linux server:
$ dpkg --list | grep php
Sample outputs:

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

Posted by: Vivek Gite

The author is the creator of nixCraft and a seasoned sysadmin, DevOps engineer, and a trainer for the Linux operating system/Unix shell scripting. Get the latest tutorials on SysAdmin, Linux/Unix and open source topics via RSS/XML feed or weekly email newsletter.

2 comment

  1. Hello,

    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.

  2. Hello
    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?

    Have a question? Post it on our forum!