B2GraphiX B2GraphiX - 3 months ago 19
PHP Question

Get the web server version in php

I would like the version of a web server (Nginx, MySQL, MariaDB, ...) in PHP.

I know the function for Apache:

apache_get_version()
.
There are many
phpinfo()
which returns all values but how to exploit?

You would have an idea or it is not possible for the moment?

Answer

A simple shell_exec would do the trick (assuming you're on a unix based server). Just don't put any user data into the command, and be aware that this approach may not work in shared hosting environments:

$nginxVersion = shell_exec('nginx -v 2>&1');
$mysqlVersion = shell_exec('mysql --version');

Note that nginx sends version output to stderr, so you need to pipe it to stdout to capture it.

Comments