Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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.

like image 850
NotoriousWebmaster Avatar asked Jul 04 '16 18:07

NotoriousWebmaster


People also ask

Does PHP-FPM use PHP INI?

fpm/php. ini will be used when PHP is run as FPM -- which is the case with an nginx installation. And you can check that calling phpinfo() from a php page served by your webserver.

Can you use PHP-FPM with Apache?

By default Apache will use mod_php so now you can configure Apache to use PHP-FPM.

Does PHP use htaccess?

htaccess using PHP's built-in webserver (it is not relying on apache, it is implemented entirely in PHP's core).

Do you need PHP-FPM?

Conclusion. PHP-FPM is an efficient method on how to minimize the memory consumption and rise the performance for the websites with heavy traffic. It is significantly faster than traditional CGI-based methods in multi-user PHP environments.


1 Answers

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.

like image 76
Olaf Dietsche Avatar answered Sep 29 '22 21:09

Olaf Dietsche