How to detect in PHP, if it is running on Apache, Nginx or some other webserver?

29,138

Short answer is that its impossible to deterministically identify what webserver is in use. The closest you'll get is the value of $_SERVER["SERVER_SOFTWARE"].

It is possible to get a fairly good idea what software is running at a [particular URL by application fingerprinting but that's very very complicated - and it'll only tell you what's terminating the HTTP connection - it may be a proxy.

What you see in phpinfo() will not show the web server for [fast]cgi and it'll only show what the adminstrator chooses to make available on other systems.

Also its critical for my application to detect combos and proxies presence.

I have no idea what you mean by 'combos'. As for proxies....there is no way to tell that either.

Perhaps if you explained why you need this information and what value it has to you then we might be able to make a more informed guess as to an answer which might suit your needs.

C.

Share:
29,138

Related videos on Youtube

rahul286
Author by

rahul286

A geek (wordpress & nginx), blogger (tech) & entrepreneur (rtCamp) Currently leading EasyEngine Project - a CLI tool to manage WordPress-Nginx sites & more!

Updated on September 17, 2022

Comments

  • rahul286
    rahul286 over 1 year

    First I know this variable : _SERVER["SERVER_SOFTWARE"]

    In one of my application, I want to check from PHP script which webserver it is running on. Basically it will be a wordpress plugin which will help Bloggers tweak some configure.

    I have created separate process for Apache & Nginx and was also thinking about releasing code as 2 different wordpress plugins.

    Then I just got curious to know if there is a FULLPROOF way in PHP to detect webservers flawlessly.

    Please consider all cases :: Apache, Nginx, Apache + Nginx, PHP as Apache module, PHP using fastcgi, php-fpm, lighttpd, IIS, etc.

    Also its critical for my application to detect combos and proxies presence.

    Thanks,

    -Rahul

  • rahul286
    rahul286 almost 14 years
    By cambo I simply mean - some users choose Nginx as front-end web server and then use Apache to run PHP. One case is that they want to run cpanel and nginx together. Now in my application, in one section, I want to guide users for some complex rewrite rule based on webserver. In above apache+nginx case, which web-server my PHP script will detect? I
  • rahul286
    rahul286 almost 14 years
    thanks for your answer and help. I know via headers cannot be trusted and that is the reason I am seeking some help.