将自定义路径设置为php.ini(不在Apache中) [英] Setting custom path to php.ini (not in Apache)

查看:74
本文介绍了将自定义路径设置为php.ini(不在Apache中)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试学习Symfony,它在命令行/终端中使用php需要"某些任务.

I'm trying to learn Symfony that "requires" using php in the command line / terminal for some tasks.

我喜欢将我的php.ini存储在/apache2/conf目录中,以便将所有服务器配置都放在一个位置(并且不必在每次更改时都必须处理Windows的UAC).在Apache中,通过

I like to store my php.ini in the /apache2/conf directory, to have all the server configs at one place (and not having to deal with Windows' UAC everytime I change something). In Apache, it's no problem to set the default php.ini location via

PHPIniDir "C:/apache2/conf"

但是,从终端(而不是通过apache服务器)运行php时,默认情况下,它会在C:\ Windows目录中查找文件,尽管那里没有文件:

However, when running php from the terminal - not through the apache server - it looks for the file in the C:\Windows directory by default, although there's none there:

C:\>php -i
...
Configuration File (php.ini) Path => C:\Windows
Loaded Configuration File => (none)
Scan this dir for additional .ini files => (none)
Additional .ini files parsed => (none)
...

当然,我可以每次使用php -c C:\apache2\conf ...来绕过它,但是我更喜欢一个更简单,更持久的解决方案.

Of course, I can bypass this by using the php -c C:\apache2\conf ... everytime I use it but I'd prefer a more easy and permanent solution.

这可能吗? 预先感谢!

Is this possible? Thanks in advance!

推荐答案

http: //www.php.net/manual/en/configuration.file.php

在以下位置搜索

php.ini(按顺序):

php.ini is searched in these locations (in order):

  • SAPI模块的特定位置(Apache 2中的PHPIniDir指令,CGI和CLI中的-c命令行选项,NSAPI中的php_ini参数,THTTPD中的PHP_INI_PATH环境变量)

  • SAPI module specific location (PHPIniDir directive in Apache 2, -c command line option in CGI and CLI, php_ini parameter in NSAPI, PHP_INI_PATH environment variable in THTTPD)

PHPRC环境变量.在PHP 5.2.0之前,需要在下面提到的注册表项之后对此进行检查.

The PHPRC environment variable. Before PHP 5.2.0 this was checked after the registry key mentioned below.

从PHP 5.2.0开始,可以为不同版本的PHP设置php.ini文件的位置.依次检查以下注册表项:[HKEY_LOCAL_MACHINE \ SOFTWARE \ PHP \ xyz],[HKEY_LOCAL_MACHINE \ SOFTWARE \ PHP \ xy]和[HKEY_LOCAL_MACHINE \ SOFTWARE \ PHP \ x],其中x,y和z表示PHP专业语言,次要版本和发行版本.如果这些键中有IniFilePath的值,则找到的第一个将用作php.ini的位置(仅Windows).

As of PHP 5.2.0, the location of the php.ini file can be set for different versions of PHP. The following registry keys are examined in order: [HKEY_LOCAL_MACHINE\SOFTWARE\PHP\x.y.z], [HKEY_LOCAL_MACHINE\SOFTWARE\PHP\x.y] and [HKEY_LOCAL_MACHINE\SOFTWARE\PHP\x], where x, y and z mean the PHP major, minor and release versions. If there is a value for IniFilePath in these keys, then the first one found will be used as the location of the php.ini (Windows only).

[HKEY_LOCAL_MACHINE \ SOFTWARE \ PHP],IniFilePath的值(仅Windows).

[HKEY_LOCAL_MACHINE\SOFTWARE\PHP], value of IniFilePath (Windows only).

当前工作目录(CLI除外)

Current working directory (except CLI)

Web服务器的目录(用于SAPI模块),或PHP的目录(在Windows中为其他目录)

The web server's directory (for SAPI modules), or directory of PHP (otherwise in Windows)

Windows目录(对于Windows,是C:\ windows或C:\ winnt),或--with-config-file-path编译时间选项

Windows directory (C:\windows or C:\winnt) (for Windows), or --with-config-file-path compile time option

此外,从PHP 5.3开始,您还可以使用按目录的.ini文件.请参见 http://php.net/manual/zh/configuration.file. per-user.php

In addition as of PHP 5.3, you can use per-directory .ini files. See http://php.net/manual/en/configuration.file.per-user.php

这篇关于将自定义路径设置为php.ini(不在Apache中)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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