Apache and php-fpm


Original address: Apache and php-fpm


  • 1.SetHandler

  • 2.ProxyPassMatch

  • 3.ProxyPass

<h3 id=”1″>1.SetHandler</h3>

  1. Deploy only once in the Apache configuration file
  2. Apache 2.4.9 or more is required.
Ip: port configuration

Php-fpm configuration

listen =

Httpd configuration

<FilesMatch \.php$>
setHandler "proxy:fcgi://"
UDS configuration

Php-fpm configuration

listen = /var/run/php-fpm/php-fpm.sock

Httpd configuration

<FilesMatch \.php$>
    SetHandler "proxy: unix:/var/run/php-fpm/php-fpm.sock | fcgi://localhost" Apache 2.4.10 settings

<h3 id=”2″>2.ProxyPassMatch</h3>

Need to be added to each Virtual Host

Ip: port configuration
<VirtualHost *:80>
ProxyPassMatch ^/(.*\.php(/.*)?)$ fcgi://$1
DirectoryIndex /index.php
  • ProxyPassMatch
    Only content that satisfies a particular regular pattern matches and executes the rule, where the pattern is,

Start with the root directory of the Web site (virtual host < Virtual Host >), and match any path that ends with. PHP or follows one / more content after. php.

  • ^ (caret) and $(dollar)

Marks the beginning and end of the path to match

  • ( )

The contents in parentheses can be expressed as $1 to facilitate later reference.

  • fcgi://

Forwarding agent through mod_proxy_fcgi, using the fast CGI protocol, transfers to the port that PHP-FPM monitors.
Changing IP addresses and/or port numbers can lead to different pools. With this, server shunting and balancing can be realized.

  • /path/to/your/documentroot/

Very important! It must match the path of the virtual host, and it must be the absolute path of the corresponding PHP file in the operating system. Otherwise, you won’t find the file (PHP Script File). This is also the purpose of URL address rewriting: to convert the URL address to the absolute path of the PHP file immediately following fcgi://

  • It can be extended from the original request to a variable of the entire request path, which refers to the path (uri) matched in the front peripheral ().

My native docker container httpd and php-fpm configuration
My php-fpm is on, and the configuration will be different.

<VirtualHost *:80>
    ServerAdmin [email protected]
    DocumentRoot "/usr/local/apache2/htdocs"
    ServerName localhost
    <Directory "/usr/local/apache2/htdocs">
     Options None
     Require all granted
    ProxyRequests Off
    ProxyPassMatch ^/(.*\.php)$ fcgi://$1

For docker-compose installation configuration, see my docker compose installation configuration nginx reverse proxy httpd php-fpm
<h3 id=”3″>3.ProxyPass</h3>

Similar to ProxyPassMatch, you need to set it separately in each Virtual Host

<LocationMatch ^(.*\.php)$>
ProxyPass fcgi://
ProxyErrorOverride on

Finally, thanks to http://cnzhx.net/blog/apache-…

Recommended Today

Win10 quick preview 19592 update push (with summary of update and repair contents)

Microsoft released the latest Windows 10 quick preview 19592 system update early this morning. This is an active development version after windows 10 20h1 (also known as 2004 version). It is understood that although the functions in the active development branch may appear in the future version of windows 10, they no longer match the […]