How to Fix “php_value not allowed here” Error in Apache with PHP Module


5 views

When working with PHP running as an Apache module (mod_php), you might encounter the frustrating "php_value not allowed here" error in your error logs, even after properly setting AllowOverride All. This typically happens when the server configuration restricts the use of PHP directives in .htaccess files.

For php_value and php_flag directives to work in .htaccess, three conditions must be met:

  1. PHP must be running as an Apache module (not CGI/FPM)
  2. AllowOverride must permit FileInfo directives
  3. The PHP admin must allow configuration changes via .htaccess

What many developers overlook is the PHP_AUTH_CONFIG setting. In your main Apache configuration (httpd.conf or apache2.conf), you need:

<IfModule mod_php5.c>
    # For Apache 2.2
    AllowOverride Options=Includes,ExecCGI,FileInfo AuthConfig Limit
    # For Apache 2.4+
    AllowOverride All
    PHP_Admin_Flag engine on
    PHP_Admin_Value open_basedir none
</IfModule>

Here's a full working configuration example for a Gallery3 installation:

# In apache2.conf or your virtual host configuration
<Directory "/var/www/gallery3">
    Options FollowSymLinks
    AllowOverride All
    Require all granted
    
    <IfModule mod_php5.c>
        PHP_Admin_Value open_basedir "/var/www/gallery3:/tmp"
        PHP_Admin_Flag display_errors off
        PHP_Admin_Value upload_max_filesize "20M"
        PHP_Admin_Value post_max_size "22M"
    </IfModule>
</Directory>

If you still experience problems:

  • Check that mod_php is actually loaded: apachectl -M | grep php
  • Verify the PHP handler: AddHandler application/x-httpd-php .php
  • Test with a minimal .htaccess: php_value memory_limit 128M
  • Ensure no conflicting settings in php.ini override your .htaccess

While .htaccess PHP directives are convenient, they come with performance overhead. For production servers, consider:

# Move settings to vhost config when possible
<VirtualHost *:80>
    php_admin_value memory_limit 256M
    php_admin_flag log_errors on
</VirtualHost>

When working with PHP5 running as an Apache module (not CGI), you might encounter the frustrating "php_value not allowed here" error in your error logs, even after setting AllowOverride All in your Apache configuration. This typically occurs when trying to use PHP directives in .htaccess files for applications like Gallery3.

The key configuration you're missing is the PHPIniDir directive. For PHP values in .htaccess to work, Apache needs to know where to find the PHP configuration. Add this to your Apache configuration:

LoadModule php5_module modules/libphp5.so
PHPIniDir "/etc/php5/apache2"

Here's how your Apache configuration should look for the directory containing your Gallery3 installation:


    Options Indexes FollowSymLinks
    AllowOverride All
    Order allow,deny
    Allow from all
    PHPIniDir "/etc/php5/apache2"

Create a test.php file with this content to confirm PHP is running as an Apache module:


Check the "Server API" entry in the output - it should say "Apache 2.0 Handler" not "CGI/FastCGI".

Here are some typical PHP directives you might want to use in .htaccess for performance optimization:

php_value upload_max_filesize 20M
php_value post_max_size 22M
php_value memory_limit 128M
php_flag display_errors off
php_flag log_errors on
php_value error_log /var/log/php_errors.log

Be cautious when allowing PHP directives in .htaccess files:

  • Only enable for specific directories that need it
  • Set appropriate file permissions (644 for .htaccess)
  • Regularly monitor your error logs