If I try phpinfo()
I see that System is:
Linux php56-web-68 4.4.0-142-generic #168-Ubuntu
But I have no idea what Ubuntu version is it? Is it 14.04 or 16.04 or something else?
Is there a way I can get this information just using standard PHP?
Another alternative is to use cat /etc/lsb-release
command and feed it into PHP's shell_exec
.
shell_exec
should yield similar to this:
DISTRIB_ID=Ubuntu
DISTRIB_RELEASE=18.04
DISTRIB_CODENAME=bionic
DISTRIB_DESCRIPTION="Ubuntu 18.04.1 LTS"
After that, just use parse_ini_string
to parse the output, in turn returns an array.
Here's a one liner:
echo parse_ini_string(shell_exec('cat /etc/lsb-release'))['DISTRIB_RELEASE'];
Sidenote: Just tested on my ec2 instance, it yields 18.04
A better version than the previous answer above suggested by @jenesaisquoi:
echo shell_exec('lsb_release -sr'); // 18.04
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With