The easiest way to get local IP Address in PHP on CentOS is using shell command like "hostname -I". I tried several methods to get it, but most of them returns the wrong answer.

Followings are the example:

<?php

	$ip = shell_exec("hostname -I");
	echo "local IP address={$ip}\n";

?>

Above sample is tested on CentOS 7.