Apache and php-fpm

Time:2019-6-24

Original address: Apache and php-fpm

Catalog

  • 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 = 127.0.0.1:9000

Httpd configuration

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

Php-fpm configuration

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

Httpd configuration

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

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

Need to be added to each Virtual Host

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

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://127.0.0.1:9000

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://127.0.0.1:9000.

  • 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 138.38.38.110, 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
    </Directory>
    ProxyRequests Off
    ProxyPassMatch ^/(.*\.php)$ fcgi://138.38.38.110:9000/var/www/htm/$1
</VirtualHost>

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://127.0.0.1:9000/path/to/webroot/
ProxyErrorOverride on
</LocationMatch>

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 […]