如何在共享主机上使用已编译的 php-cgi 在 .htaccess 中使用 php 中的 getenv() 和 SetEnv [英] How to use getenv() in php and SetEnv in a .htaccess with a compiled php-cgi on a shared host

查看:25
本文介绍了如何在共享主机上使用已编译的 php-cgi 在 .htaccess 中使用 php 中的 getenv() 和 SetEnv的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

只是在上下文中澄清主要问题:

Just putting in context to clarify the main question:

在我的开发机器上,PHP5.3.1 作为模块安装在 Apache 上,我在应用程序的根 .htaccess 文件中使用 SetEnv APPLICATION_ENVIRONMENT 开发.然后可以使用 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').

在生产服务器上,在共享主机(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.

在我的域的共享主机根 .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 所在的位置.chmod 744 在名为 dispatch.fcgi 的文件上,dreamhost 的看门狗将允许更多内存.

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');

这篇关于如何在共享主机上使用已编译的 php-cgi 在 .htaccess 中使用 php 中的 getenv() 和 SetEnv的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆