简体   繁体   English

在.htaccess中使用php_flag

[英]Use php_flag in .htaccess

I'm using PHP 5.4.4 as mod_php in Apache/2.2.22 on my Debian 7 Rootserver. 我在Debian 7 Rootserver上的Apache/2.2.22使用PHP 5.4.4作为mod_php。

Currently I can only use one PHP configuration (php.ini), I would'nt change to FCGI or other Wrappers to use seperately configuration files. 目前,我只能使用一种PHP配置(php.ini),不会更改为FCGI或其他Wrappers来单独使用配置文件。

I search for a solution to set special PHP configs on a directory. 我在寻找一种在目录上设置特殊PHP配置的解决方案。 First things was to use an .htaccess with php_flag but that won't work (for example php_flag display_errors true ). 第一件事是将.htaccessphp_flag一起使用,但这不起作用(例如php_flag display_errors true )。

How I can use this schema? 如何使用该架构? Must I install a special module for that? 我必须为此安装一个特殊的模块吗?

Let me first quote the apache manual on .htaccess 首先让我引用.htaccess上Apache手册

You should avoid using .htaccess files completely if you have access to httpd main server config file. 如果可以访问httpd主服务器配置文件,则应避免完全使用.htaccess文件。 Using .htaccess files slows down your Apache http server. 使用.htaccess文件会降低Apache http服务器的速度。 Any directive that you can include in a .htaccess file is better set in a Directory block, as it will have the same effect with better performance. 可以在.htaccess文件中包含的任何指令最好在Directory块中进行设置,因为它具有相同的效果和更好的性能。

That said, in those <Directory> - or <VirtualHost> - directives, you can 也就是说,在这些<Directory> -或<VirtualHost> -指令中,您可以

use php_value for setting ini-settings that need a value: 使用php_value设置需要值的ini设置:

php_value memory_limit 64M

use php_flag for settings that are binary switches: 使用php_flag进行二进制开关设置:

php_flag log_errors on

Further more, if you maintain a server with many users and you do want to allow them to use .htaccess for influencing the config, you can use php_admin_value and php_admin_flag to set them in a way that users cannot override them in .htaccess. 此外,如果您维护的服务器上有许多用户,并且确实希望允许他们使用.htaccess来影响配置,则可以使用php_admin_valuephp_admin_flag进行设置,以使用户无法在.htaccess中覆盖它们。

php_admin_value open_basedir /path/to/a/single/level/above/docroot
php_admin_flag display_errors on

See mod_php manual , this is the regular php apache module, so no extra special modules are needed. 参见mod_php manual ,这是常规的php apache模块,因此不需要额外的特殊模块。

Keep in mind: 记住:

[this] Can be used only with PHP_INI_ALL and PHP_INI_PERDIR type directives. [this]仅可与PHP_INI_ALL和PHP_INI_PERDIR类型指令一起使用。

you can check the Changeable column of the list of php.ini directives 您可以检查php.ini指令列表的Changeable列

Try to enable AllowOverride Options or AllowOverride All in your main apache config for the directory you want to change this. 尝试在要更改此目录的主apache配置中启用AllowOverride OptionsAllowOverride All

Then, for example to enable display error messages, use php_flag display_errors "1" 然后,例如,要启用显示错误消息,请使用php_flag display_errors "1"

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

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