I've an Apache virtual host that appears such as this:

<VirtualHost *:80>
    ServerName host1.example.com
    ServerAlias host2.example.com
    DocumentRoot /srv/web/host1.example.com/pub
</VirtualHost>

I've the next file:

/srv/web/host1.example.com/pub/test.php

I'm asking for the next URL (notice that i'm while using ServerAlias, not the ServerName:

http://host2.example.com/test.php

Let me have test.php output the ServerName variable in some way (host1.example.com). Can there be any method of doing that?

Apparently, whenever you access a VirtualHost with the alias, there's no trace from the original SERVER_NAME most of the $_SERVER variables.

The only real concept that involves thoughts are setting an atmosphere variable:

SetEnv MY_HOST host1.example.com

this will set the need for $_SERVER["MY_HOST"] towards the correct host title. No guarantees though, I have not attempted this used.