well, you need to know that there are some different between SAPI's in PHP, when you are running a PHP script in your web browser, you are using the HTTP Server SAPI ( Apache2 or nginx or whatever ), so the returned data in the $_SERVER variable will depends on the headers that the web server itself will throw to PHP, While in the terminal you are running PHP Under CLI SAPI which is serverless so to speak Unless you are using the built-in php server.
Take a look at the $_SERVER manual page :-
$_SERVER
is an array containing information such as headers, paths,
and script locations. The entries in this array are created by the web
server. There is no guarantee that every web server will provide any
of these; servers may omit some, or provide others not listed here.
That said, a large number of these variables are accounted for in the
» CGI/1.1 specification, so you should be able to expect those.
which is mean - again - that the data that will $_SERVER variable will hold will depends on the information that the web server will return/throw .
As a workaround you can check if the script is running under the CLI SAPI, and then set some custom values for the $_SERVER
variable