I use phpinfo() to deternine which OS installed on remote server. It is Linux. Is there any way to determine the flavor of Linux using php?
-
I have explicitly said that I know the OS now I want to know the flavor. The link you posted only gives info about the OS. – Iqbal Malik Oct 03 '13 at 05:36
-
See @duskwuff answer, it is indeed a duplicate. – Oct 03 '13 at 05:44
-
1Use this to find OS version. echo exec("cat /etc/*-release"); – Praveen D Oct 03 '13 at 05:48
-
@david. Just edited my question – Iqbal Malik Oct 03 '13 at 05:49
-
Like that link says, use `php_uname()` with the mode parameter defined or any of these fine examples people have laid out for you. My flag remains even with the edit. – Oct 03 '13 at 05:55
-
@david. From documentation, It says about php_uname(), This is the same string you see at the very top of the phpinfo() output. I have already told you that I used phpinfo() but it is not returning flavor. – Iqbal Malik Oct 03 '13 at 06:02
-
@IqbalMalik I see, take a look at my answer then. – Oct 03 '13 at 07:54
-
I believe that [this](http://stackoverflow.com/questions/1482260/how-to-get-the-os-on-which-php-is-running) is what you are looking for: – Tomasz Kapłoński Oct 03 '13 at 05:28
3 Answers
Ubuntu flavors are all the same operating system — the only difference between them is in the set of packages installed by default. Since packages can be installed and removed later on, there's no way to reliably tell the difference.
(Most of the differences between Ubuntu flavors are in the default desktop environment and applications, which wouldn't really be of much interest on a server anyway. Indeed, most servers are likely to be not be using a "flavored" install at all.)
Try reading from /etc/os-release
, eg
php > $test = parse_ini_file('/etc/os-release');
php > print_r($test);
Array
(
[NAME] => Ubuntu
[VERSION] => 12.04.3 LTS, Precise Pangolin
[ID] => ubuntu
[ID_LIKE] => debian
[PRETTY_NAME] => Ubuntu precise (12.04.3 LTS)
[VERSION_ID] => 12.04
)

- 157,677
- 23
- 242
- 245
PHP should be able to read from /etc/issue
or /proc/version
, these will work on many flavors of Linux and should yield a very precise picture of your server. This is was run on a Vagrant Ububtu box:
<?php
$issue = file_get_contents('/etc/issue');
// Ubuntu 12.04 LTS \n \l
$version = file_get_contents('/proc/version');
// Linux version 3.2.0-23-generic-pae (buildd@palmer) (gcc version 4.6.3 (Ubuntu/Linaro 4.6.3-1ubuntu4) ) #36-Ubuntu SMP Tue Apr 10 22:19:09 UTC 2012
But this isn't just limited to Ubuntu, here are results from a basic shared server account:
file_get_contents('/etc/issue');
// CloudLinux Server release 5.9 (Sergey Oleynikov)
// Kernel \r on an \m
file_get_contents('/proc/version');
// Linux version 2.6.18-408.8.2.el5.lve0.8.61.3 (mockbuild@koji.cloudlinux.com) (gcc version 4.1.2 20080704 (Red Hat 4.1.2-52)) #1 SMP Wed Jul 11 06:49:35 EDT 2012

- 19,579
- 7
- 67
- 84