Adrian Preuss
Adrian Preuss

Reputation: 3113

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.

Currently I can only use one PHP configuration (php.ini), I would'nt change to FCGI or other Wrappers to use seperately configuration files.

I search for a solution to set special PHP configs on a directory. First things was to use an .htaccess with php_flag but that won't work (for example php_flag display_errors true).

How I can use this schema? Must I install a special module for that?

Upvotes: 1

Views: 10988

Answers (2)

Chris Wesseling
Chris Wesseling

Reputation: 6368

Let me first quote the apache manual on .htaccess

You should avoid using .htaccess files completely if you have access to httpd main server config file. Using .htaccess files slows down your Apache http server. 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.

That said, in those <Directory>- or <VirtualHost>- directives, you can

use php_valuefor setting ini-settings that need a value:

php_value memory_limit 64M

use php_flag for settings that are binary switches:

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.

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.

Keep in mind:

[this] Can be used only with PHP_INI_ALL and PHP_INI_PERDIR type directives.

you can check the Changeable column of the list of php.ini directives

Upvotes: 4

Marc Dannemann
Marc Dannemann

Reputation: 103

Try to enable AllowOverride Options or AllowOverride All in your main apache config for the directory you want to change this.

Then, for example to enable display error messages, use php_flag display_errors "1"

Upvotes: 1

Related Questions