我如何创建自定义的php.ini文件,为每个虚拟主机? [英] How do I create custom php.ini files for each virtual host?

查看:283
本文介绍了我如何创建自定义的php.ini文件,为每个虚拟主机?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我已经安装的EasyPHP WAMP仅为本地发展(我没有举办任何网站)。

I've installed EasyPHP WAMP for local development only (I'm not hosting any websites).

有没有办法来设置不同的虚拟主机定制的PHP设置?

Is there a way to set custom php settings for separate virtual hosts?

目前和出的现成的的php.ini 文件从加载: C:\\ Program Files文件(x86)的\\的EasyPHP-DevServer-14.1VC11 \\二进制\\ PHP \\ php_runningversion \\ php.ini中这将是很好如果说,我可以在自定义的下降的php.ini 文件到虚拟主机目录中覆盖设置原始的php.ini 这样的话,我可以更好地模拟生产服务器上的每个站点的基础环境。

Currently and out-of-the-box, the php.ini file is loaded from: C:\Program Files (x86)\EasyPHP-DevServer-14.1VC11\binaries\php\php_runningversion\php.ini It would be nice if, say, I could drop in a custom php.ini file into the virtual host directory to override settings in the original php.ini This way, I could better emulate a production server's environment on a per-site basis.

我见过的在线主机帐户这项工作。但我无法弄清楚如何使我的机器上这一工作。

I've seen this work with online hosting accounts. But I can't figure out how to make this work on my machine.

推荐答案

使用自定义的php.ini 文件是pretty简单明了的CGI / FastCGI的基于PHP安装,但运行PHP时作为Apache模块(mod_php的),因为整个服务器运行PHP间preTER的单个实例这是不可行的。

Using custom php.ini files is pretty straighforward for CGI/FastCGI based PHP installations but it isn't feasible when running PHP as Apache module (mod_php) because the whole server runs a single instance of the PHP interpreter.

我的建议是:


  • 从PHP本身设置尽可能多的设置,您可以:

  • Set from PHP itself as many settings as you can:

ini_set('memory_limit', '16M');
date_default_timezone_set('Europe/Madrid')
...

在换言之,可以在运行时改变指令

In other words, directives that can be changed at runtime.

从每个目录的Apache设置文件设置的东西,其余的(又名的.htaccess

Set the rest of stuff from per-directory Apache setting files (aka .htaccess):

php_flag short_open_tag off
php_value post_max_size 50M
php_value upload_max_filesize 50M

即,需要进行定义的脚本开始运行前设置

i.e., settings that need to be defined before the script starts running

请看看通过运行时配置了解更多详情。

Please have a look at the Runtime Configuration for further details.

有时候,你实际上需要的不同的的开发和生产中的设置。还有就是刚才有一个<$ C无尽的方式来解决与PHP code(从创建从 $ _ SERVER ['HTTP_HOST'] 变量的布尔常量$ C>的config.php 值不同的文件),但它与的.htaccess 棘手。我通常使用 &LT; IfDefine&GT; 指令

Sometimes, you'll actually need different settings in development and production. There're endless ways to solve that with PHP code (from creating a boolean constant from the $_SERVER['HTTP_HOST'] variable to just having a config.php file with different values) but it's trickier with .htaccess. I normally use the <IfDefine> directive:

<IfDefine DEV-BOX>
    #
    # Local server directives
    #
    SetEnv DEVELOPMENT "1"

    php_flag display_startup_errors on
    php_flag display_errors on
    php_flag log_errors off
    #php_value error_log ...
</IfDefine>
<IfDefine !DEV-BOX>
    #
    # Internet server directives
    #
    php_flag display_startup_errors off
    php_flag display_errors off
    php_flag log_errors on
    php_value error_log "/home/foo/log/php-error.log"
</IfDefine>

...其中 DEV-BOX 是一个字符串,我传递给本地Apache的命令行:

... where DEV-BOX is a string I pass to the local Apache command-line:

C:\Apache24\bin\httpd.exe -D DEV-BOX

如果你运行Apache作为服务时, -D DEV-BOX 位可以在Windows注册表中添加,例如:

If you run Apache as service, the -D DEV-BOX bit can be added in the Windows registry, e.g.:

HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\services\Apache2.4\Parameters\ConfigArgs


相关报道:<一href=\"http://stackoverflow.com/questions/16414054/find-out-how-php-is-running-on-server-cgi-or-fastcgi-or-mod-php\">Find如何PHP是在服务器上运行(CGI或快速或mod_php的)

这篇关于我如何创建自定义的php.ini文件,为每个虚拟主机?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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