PHP ve Apache ortam değişkenleri

2 Cevap php

Ben açılışta apache linux bir ortam değişkeni geçmek istiyorum.

export MYVAR=5 --I define my environment variable on the command line

PassEnv MYVAR --set apache to import the variable in apache config file

apachectl restart --when I restart apache I don't get an error message. However I have noticed that if I do not create the environment variable in my first step, I get a warning message, so must be working here

echo $_SERVER['MYVAR'] --i try to access the environment variable within PHP but it is not defined

Ben zaten çıkar bir ortam değişkeni (kendimi oluşturuldu havn't bir) PassEnv çalışırsanız gayet iyi çalıştığını tespit ettik. SetEnv yönergesi de gayet iyi çalışıyor.

Ben gerçekten bir dosyaya yazmadan anında apache bir ortam değişkeni geçmek istiyorum. Çok takdir Yardım.

Ben CentOS, PHP5 ve Apache2'yi kullanıyorum.

Teşekkürler.

update it seems the environment variable gets passed if i invoke the apache startup directly with httpd and not use apachectl which is a shell script. I would have thought that the "export" would have exported the variable to the shell script no? I am not a linux guru so excuse my lack of knowledge.

2 Cevap

Eğer ortam değişkeni apache geçirilecek istiyorsanız, ortam değişkeni apache Bunu yapmak için içeri çalışan çevre için tanımlanan dedi emin olmalısınız, kolay seçenek, bir export MYVAR=value satırı eklemek için Envvars için (/ etc/apache2 yer olmalıdır) veya (/ etc / init.d) apache başlar ve komut dosyası apache konfigürasyonunda aranıyor sizin PassEnv MyVar ekleyin.

Apache yeniden başlatılıyor MYVAR ortam değişkeni geçirilen emin olun. Apache olsa çalışırken AFAIK bu değişkenin değerini değiştirmek mümkün olmayacaktır ...

CentOS için gerekli bazı bilgileri: http://php.dzone.com/news/inserting-variable-headers-apa&default=false&zid=159&browser=16&mid=0&refresh=0

Sen superglobali kullanarak ortam değişkenleri erişmek $_ENV olmalıdır:

$_ENV['MYVAR']

http://www.php.net/manual/en/reserved.variables.environment.php

Update

Sizin değişken aslında aşağıdaki linke göre, afterall $_SERVER altında olabilir. Değer olsa da $_ENV kontrol.

http://www.php.net/manual/en/reserved.variables.environment.php#97105 başı olarak