2

Running a script on the command line:

php testfile.php

The file contains the following:

echo print_r($_SERVER, true);

I've noticed it has JAVA_HOME and PATH variables in the terminal output. I've tried adding my own variables to the /etc/environment (Linux) assuming it was using such variables but they don't appear.

So where are these variables defined and can I add my own?

user3168961
  • 375
  • 1
  • 10

2 Answers2

0

According to PHP Documentation on the $_SERVER superglobal:

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 the implementation depends on your web server software. For Apache some of the indices (like REMOTE_HOST) comes from the configuration file httpd.conf

Daniel
  • 10,641
  • 12
  • 47
  • 85
0

From the PHP documentation (which I recommend):

$_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.

See here for a more detailed explanation: http://php.net/manual/en/reserved.variables.server.php

You can set Environment variables in your apache config using SetEnv ENVIRONMENT "production" for example.

Also take a look at this question and answer How to set global environment variables for PHP

delboy1978uk
  • 12,118
  • 2
  • 21
  • 39