简体   繁体   English

将路径设置为php.ini

[英]Set path to php.ini

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? 我知道您可以在.htaccess设置php.ini指令,但是可以定义要使用的特定php.ini文件吗?

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()一起使用。

Have a look at .user.ini section 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. 但是,除了.unser.ini解决方案之外,您还可以在“其他.ini文件已解析”目录中放置一个其他ini文件。 There you can use one single ini file to overwrite all other settings. 您可以在其中使用一个单一的ini文件来覆盖所有其他设置。 Name it with zzz at the beginning and it will be parsed at last. 首先以zzz命名,最后将对其进行解析。 This is also easy for your hoster to deploy without destroying his settings. 您的托管服务商也很容易在不破坏其设置的情况下进行部署。

Kolink, I suspect that you are on a shared hosting service, in which case your host may be using something called suPHP. Kolink,我怀疑您正在使用共享主机服务,在这种情况下,您的主机可能正在使用suPHP。 In this case -- as you describe -- the PHPINIDir directive doesn't work, in which case there is a suPHP_ConfigPath directive. 在这种情况下(如您所述),PHPINIDir指令不起作用,在这种情况下,存在suPHP_ConfigPath指令。

In terms of access, I have a standard mod_rewrite in my DOCROOT/.htaccess : 在访问方面,我在DOCROOT/.htaccess有一个标准的mod_rewrite:

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. 您需要在此处通过服务的本地设置替换DOCROOT。 Look for DOCUMENT_ROOT in a phpinfo() listing. phpinfo()清单中查找DOCUMENT_ROOT

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM