NotoriousWebmaster
NotoriousWebmaster

Reputation: 3568

Can I Override PHP Setting in htaccess When Using PHP-FPM?

My vhost looks like this:

<Directory "/var/www">
  Options Indexes FollowSymlinks MultiViews
  AllowOverride All
  Require all granted

  <FilesMatch "\.php$">
    Require all granted
    SetHandler proxy:fcgi://127.0.0.1:9000
  </FilesMatch>
</Directory>

I'm trying to add php_value lines to my .htaccess file. As soon as I do, I get 500 errors, and this in my Apache's errors log:

/var/www/.htaccess: Invalid command 'php_value', perhaps misspelled or defined by a module not included in the server configuration

So, the question: Is there any way to override php.ini settings via .htaccess, when using PHP-FPM?

tia.

Upvotes: 8

Views: 20744

Answers (1)

Olaf Dietsche
Olaf Dietsche

Reputation: 74048

As others already pointed out, no, you can't override settings via .htaccess when using PHP-FPM.

But there seems to be a similar mechanism from PHP, named .user.ini files.

Since PHP 5.3.0, PHP includes support for configuration INI files on a per-directory basis. These files are processed only by the CGI/FastCGI SAPI. This functionality obsoletes the PECL htscanner extension. If you are using Apache, use .htaccess files for the same effect.

In addition to the main php.ini file, PHP scans for INI files in each directory, starting with the directory of the requested PHP file, and working its way up to the current document root (as set in $_SERVER['DOCUMENT_ROOT']). In case the PHP file is outside the document root, only its directory is scanned.

Only INI settings with the modes PHP_INI_PERDIR and PHP_INI_USER will be recognized in .user.ini-style INI files.

And in a comment below

"If you are using Apache, use .htaccess files for the same effect."

To clarify, this applies only to Apache module mode. If you put php directives in .htaccess on an Apache CGI/FastCGI server, this will bomb the server out with a 500 error.

So you can create .user.ini files analogue to .htaccess, but in ini style format.

Upvotes: 18

Related Questions