Checking what PHP version I'm running on Linux?

105

12

I'm running Centos 5 and I need to know what version of PHP I'm running, is there a command for this which I can run?

Elitmiar

Posted 2009-08-24T09:03:27.257

Reputation: 2 396

Answers

182

Try running the following at the command line.

To just get the version information:

php -v

Or to get a lot of info:

php -i

It should give you all information you need about the php install.

Paxxi

Posted 2009-08-24T09:03:27.257

Reputation: 6 952

@AkshayRaje Exactly. Most people who ask “What PHP version am I using?” are usually referring to the Apache/Nginx PHP module and not the PHP CLI stuff. The PHP CLI info has 100% nothing to do with the PHP module used by Apache/Nginx. – JakeGould – 2016-02-23T12:06:59.237

And php-cli maybe not installed in the system – Furkat U. – 2017-03-06T07:02:15.783

17+1 php -v was a lot faster – hyperslug – 2009-08-24T09:10:06.167

5Thx, this worked :-) php -i | grep 'PHP Version' gave me the answer – Elitmiar – 2009-08-24T09:12:55.223

4Just be cautious that the CLI version of PHP (checked from command line) can be different from the one served by your webserver (shown by phpinfo()) – Akshay Raje – 2014-06-04T11:14:21.257

19

You can make an index.php file with

<?php phpinfo() ?>

hyperslug

Posted 2009-08-24T09:03:27.257

Reputation: 12 882

First, this is the answer. Most people who ask “What PHP version am I using?” are usually referring to the Apache/Nginx PHP module and not the PHP CLI stuff. The PHP CLI info has 100% nothing to do with the PHP module used by Apache/Nginx. But @Arjan also, many systems administrators disable the “X-Powered-By” header servers send out as part of security hardening. While it seems convenient for developers, headers like that put you on the “sucker list” for botnet attacks. If you run a server and the main way you are determining PHP version is via “X-Powered-By” your process is very flawed. – JakeGould – 2016-02-23T12:06:13.450

this should be the correct answer – Nico – 2016-12-21T10:22:08.520

7this has the advantage of working on servers you don't have ssh access to, though personally I've always preferred <?php ?>, just for the futureproofing :P – Phoshi – 2009-08-24T10:56:11.443

Ah, right, I have a habit of using ASP tags. – hyperslug – 2009-08-24T21:26:58.667

2

On any PHP website one can often see the version in the X-Powered-By header in each PHP generated HTTP response. When you don't have SSH access, then sometimes http://phpshell.sourceforge.net/ can be used. (Though with much care, like one needs to check if a folder is writable before running a tar command.)

– Arjan – 2009-09-14T16:21:12.783

12

An answer was accepted, but another option on RPM systems (RHEL, Centos, Fedora, etc.) is to use the following:

rpm -q php

And while I'm at it, the general method for using RPM to find info on a package for any rpm-installed program or file is similar to this (for awk):

  1. Find the full path to the file if not known, such as for an executable in $PATH:

    type -path awk

  2. Find the name, including version, of the package containing the file:

    rpm -qf /usr/bin/awk

  3. If desired, query for info from that package:

    rpm -qi gawk

It's a bit trickier for packages installed and used by Apache since they may not be on $PATH, but you can start with something like:

rpm -qa | egrep -i 'php|awk'

NVRAM

Posted 2009-08-24T09:03:27.257

Reputation: 778

3

Use

more /etc/php.ini

This will show you:

  1. Apache Version
  2. PHP Versions
  3. PHP Functions
  4. Various options regarding PHP

Pankaj

Posted 2009-08-24T09:03:27.257

Reputation: 31