如何用getenv()在PHP和SETENV中的.htaccess与编译PHP,CGI的共享主机上 [英] How to use getenv() in php and SetEnv in a .htaccess with a compiled php-cgi on a shared host
问题描述
只是把在上下文中阐明的主要问题:
Just putting in context to clarify the main question:
在我的机器,PHP5.3.1上安装Apache作为一个模块,我用SETENV APPLICATION_ENVIRONMENT发展在我的应用程序的根.htaccess文件。它是那么的与GETENV('APPLICATION_ENVIRONMENT')。任何PHP脚本很容易地检索
On my development machine, PHP5.3.1 is installed on Apache as a module, I use SetEnv APPLICATION_ENVIRONMENT development in my application's root .htaccess file. It is then easily retrievable from any php script with getenv('APPLICATION_ENVIRONMENT').
在生产服务器上,一个sharedhost(Dreamhost的),我整理了自己php5.3.1因为它不直接支持。一切正常,只是GETENV('APPLICATION_ENVIRONMENT')返回false。
On the production server, on a sharedhost (dreamhost), I compiled myself php5.3.1 since it was not directly supported. Everything works fine except that getenv('APPLICATION_ENVIRONMENT') returns false.
在sharedhost根的.htaccess我的域,我用这个.htaccess文件
In the sharedhost root .htaccess for my domain, I use this .htaccess file
Options +ExecCGI
AddHandler php-cgi .php
Action php-cgi /cgi-bin/php.cgi
<FilesMatch "^php5?\.(ini|cgi)$">
Order Deny,Allow
Deny from All
Allow from env=REDIRECT_STATUS
</FilesMatch>
Options -indexes
php5.cgi驻留在/ cgi-bin目录和工作得很好。 当然,在我的应用程序的根文件夹我有另一种的.htaccess定义:
php5.cgi resides in /cgi-bin and works very well. Of course in my application's root folder I have another .htaccess defining:
SetEnv APPLICATION_ENVIRONMENT production
但在使用的getenv时,('APPLICATION_ENVIRONMENT')返回false,任何想法如何解决?
But when using getenv('APPLICATION_ENVIRONMENT') it returns false, any idea how to resolve this?
推荐答案
好吧,我终于得到它。上Dreamhost的,它有可能使用的fastcgi并因此与它声明环境变量。它包括刚刚加入这个简单的脚本
Ok I finally got it. On dreamhost, it is possible to use fastcgi and therefore declare environment variables with it. It consists of just adding this simple script
#!/bin/sh
export PHP_FCGI_CHILDREN=2
exec /home/USERNAME/YOURDOMAIN/cgi-bin/php.cgi
这是我的编译PHP5.3.1所在地。 在该文件名为dispatch.fcgi将由Dreamhost的的看门狗被允许更多的内存搭配chmod 744。
Which is where my compiled PHP5.3.1 was located. chmod 744 on that file called dispatch.fcgi which will be allowed more memory by dreamhost's watchdog.
在我添加到我的域的.htaccess中的以下内容:
After that I added to my domain's .htaccess the following:
Options +ExecCGI
AddHandler fastcgi-script fcg fcgi fpl
AddHandler php5-fastcgi .php
Action php5-fastcgi /dispatch.fcgi
现在在应用程序的根我有另一种的.htaccess有:
now in the application's root I have another .htaccess with:
SetEnv APPLICATION_ENVIRONMENT staging
在PHP脚本是通过getenv的检索('REDIRECT_APPLICATION_ENVIRONMENT');
In a php script is is retrievable via getenv('REDIRECT_APPLICATION_ENVIRONMENT');
这篇关于如何用getenv()在PHP和SETENV中的.htaccess与编译PHP,CGI的共享主机上的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!