I know I'm super late regarding this topic but there's this easy to use library where you can easily get the version numbers of Worpress, PHP, Apache, and MySQL, all-in-one.
It is called the Wordpress Environment (W18T) library
<?php
include_once 'W18T.class.php';
$environment = new W18T();
echo $environment;
?>
Output
{
"platform": {
"name": "WordPress",
"version": "4.9.1"
},
"interpreter": {
"name": "PHP",
"version": "7.2.0"
},
"web_server": {
"name": "Apache",
"version": "2.4.16"
},
"database_server": {
"name": "MySQL",
"version": "5.7.20"
},
"operating_system": {
"name": "Darwin",
"version": "17.0.0"
}
}
I hope it helps.