设置 php.ini 的路径
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/9269083/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Set path to php.ini
提问by Niet the Dark Absol
Is it possible to have just a single php.ini file, for example in the webroot (or even outside of it to prevent people accessing it via GET), and tell PHP quickly and easily where it is?
是否有可能只有一个 php.ini 文件,例如在 webroot 中(甚至在它之外以防止人们通过 GET 访问它),并快速轻松地告诉 PHP 它在哪里?
I know you can set php.ini directives in .htaccess
, but is it possible to define a specific php.ini file to be used?
我知道您可以在 中设置 php.ini 指令.htaccess
,但是是否可以定义要使用的特定 php.ini 文件?
回答by alex
Add this to your server configuration...
将此添加到您的服务器配置...
<VirtualHost 1.2.3.4:80>
PHPINIDir /path/to/new/php_ini
</VirtualHost>
Make sure to just include the path to the directory, not the entire path to the file.
确保只包含目录的路径,而不是文件的整个路径。
Then restart Apache.
然后重新启动Apache。
Check it worked with phpinfo()
.
检查它是否与phpinfo()
.
回答by powtac
Have a look at .user.inisection at the php docs.
查看php 文档中的.user.ini部分。
Since PHP 5.3.0, PHP includes support for .htaccess-style INI files on a per-directory basis.
从 PHP 5.3.0 开始,PHP 支持基于每个目录的 .htaccess 样式的 INI 文件。
But beside the .unser.ini solution you can place an additional ini file in the "additional .ini files parsed" directory. There you can use one single ini file to overwrite all other settings. Name it with zzz at the beginning and it will be parsed at last. This is also easy for your hoster to deploy without destroying his settings.
但是在 .unser.ini 解决方案旁边,您可以在“已解析的附加 .ini 文件”目录中放置一个附加的 ini 文件。在那里您可以使用单个 ini 文件覆盖所有其他设置。以zzz开头命名,最后解析。这对于您的托管商来说也很容易部署,而不会破坏他的设置。
回答by TerryE
Kolink, I suspect that you are on a shared hosting service, in which case your host may be using something called suPHP. In this case -- as you describe -- the PHPINIDir directive doesn't work, in which case there is a suPHP_ConfigPath
directive.
Kolink,我怀疑您使用的是共享托管服务,在这种情况下,您的主机可能正在使用名为 suPHP 的东西。在这种情况下——正如你所描述的—— PHPINIDir 指令不起作用,在这种情况下有一个suPHP_ConfigPath
指令。
In terms of access, I have a standard mod_rewrite in my DOCROOT/.htaccess
:
在访问方面,我有一个标准的 mod_rewrite 在我的DOCROOT/.htaccess
:
RewriteEngine On
RewriteBase /
# if a forbidden directory or file name (starting with a . or /) then raise 404 Fatal
RewriteRule (^|/)[_.] - [F]
What this does is forbid any request for any filename or directory prefixed by .
or _
. I have a DOCROOT/_private
where I keep this stuff for me:
这样做是禁止对任何以.
或为前缀的文件名或目录的任何请求_
。我有一个DOCROOT/_private
存放这些东西的地方:
suPHP_ConfigPath DOCROOT/_private
where you will need to replace DOCROOT by your local setting on your service. Look for DOCUMENT_ROOTin a phpinfo()
listing.
您需要用服务的本地设置替换 DOCROOT。在列表中查找DOCUMENT_ROOTphpinfo()
。