This libary uses the "ssh wrapper" : https://github.com/wiardvanrij/sshwrapper as requirement, (*1)
It provides out of the box functions to retrieve server information. Mostly used for webbased servers on a Linux operating system, (*2)
Requirements
Please read the sshwrapper library, you will need ssh2 php module., (*3)
Installation
Via composer, (*4)
{
"require": {
"wiardvanrij/serverinfo": "^0"
}
}
or, (*5)
composer require wiardvanrij/serverinfo
Usage
again please read the sshwrapper for those features, (*6)
Require the autoloader and include the namespaces, (*7)
<?php
require_once('vendor/autoload.php');
use SshWrapper\SshCore;
use ServerInfo\ServerCore;
Initiate the class with the host and make a connection, (*8)
$ssh = new SshCore('123.123.123.123');
$ssh->connect();
Initiate the serverinfo class and pass the connection, (*9)
$server = new ServerCore($ssh);
Use the functions you desire, (*10)
Returns the hostname of the server as string, (*11)
$hostname = $server->getHostname();
Returns the exact PHP version/service on the server. For instance php7.0 or php7.0-fpm etc., (*12)
$php = $server->getPHPServiceName();
Returns an array of the vhosts including domains, vhost location and aliases sorted by port 80 & 443, (*13)
$data = $server->getVhosts();
Example output:, (*14)
Array
(
[http] => Array
(
[1] => Array
(
[domain] => foo.com
[config] => /etc/apache2/sites-enabled/ssl-foo.com.conf
)
[2] => Array
(
[domain] => bar.com
[config] => /etc/apache2/sites-enabled/ssl-bar.com.conf
[aliases] => Array
(
[0] => foobar.eu
[1] => www.barfoo.eu
)
)
)
[https] => Array
(
[1] => Array
(
[domain] => foo.com
[config] => /etc/apache2/sites-enabled/foo.com.conf
)
[2] => Array
(
[domain] => bar.com
[config] => /etc/apache2/sites-enabled/bar.com.conf
[aliases] => Array
(
[0] => foobar.eu
[1] => www.barfoo.eu
)
)
)
)