Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

how to find the version numbers of built in modules in php from the CLI

Tags:

Basically i am new to php, and i just installed php on my machine. so we can know entire information of the php configuration by creating a php file and writing the below code in it

<?php 
  phpinfo();
?>

And i opened this through browser and can able to see all the configuration information

But is there any way to know the version of php default modules from linux terminal(I am using fedora by the way :) )

So what all i mean to ask is whether is there any way to find the version number of all the modules or individual modules from terminal through some php commands ?

For example there is a command php -me which displays all the php modules that comes by default when php is installed like below

[PHP modules]
mysql
mysqli
openssl
pcntl
pcre
PDO
pdo_mysql
pdo_sqlite
Phar
readline
Reflection
session
shmop
....
.....

but in the same way i want to find the version number of the individual module too from the terminal, how can we find it ?

like image 626
Shiva Krishna Bavandla Avatar asked Feb 08 '13 14:02

Shiva Krishna Bavandla


People also ask

Which command is used to see the PHP version installed?

Typing php -v now shows the PHP version installed on your Windows system. This article aimed to explain the common ways to check the PHP version on your server or local machine. The methods covered in this tutorial include running PHP code and using the command-line interface.

How can I check my PHP version?

Another way to check PHP version is PHPinfo() function, commonly used to check the current state of PHP configuration. It can also be used for debugging purposes as it contains all EGPCS (Environment, GET, POST, Cookie, Server) data. phpinfo();

How do I list installed extensions in PHP?

The general command we will be using is php -m. This command will give you the full list of installed PHP modules/extensions. This command will give you an output similar to the following information. If you're looking for one particular item from the list, we can use a pipe with the grep command like so.


2 Answers

To see the version for one particular module, you can use the command php --ri <module> | grep Version.

For example:

php --ri mongo | grep Version

Returns:

Version => 1.6.5
like image 63
Will Avatar answered Oct 04 '22 13:10

Will


This should do the trick:

php -r 'foreach (get_loaded_extensions() as $extension) echo "$extension: " . phpversion($extension) . "\n";'

More readable version (for code usage):

$extensions = get_loaded_extensions();
foreach ($extensions as $extension) {
    echo "$extension: " . phpversion($extension) . "\n";
}
like image 22
Gerald Schneider Avatar answered Oct 04 '22 14:10

Gerald Schneider