Kee*_*use 5 server php apache2 fastcgi
通过调整来自这个 askubuntu 线程、这个 HowtoForge 文档和这个 Digital Ocean 教程的说明,我已经设法让 FastCGI 在 Ubuntu 16.04 上与 Apache 2.4 一起工作。
所有这些消息来源都说要创建 /etc/apache2/conf-available/php7.0-fpm.conf
并告诉您要放入什么。但是安装后php-fpm
,我已经有了那个文件,内容如下:
# Redirect to local php-fpm if mod_php is not available
<IfModule !mod_php7.c>
# Enable http authorization headers
SetEnvIfNoCase ^Authorization$ "(.+)" HTTP_AUTHORIZATION=$1
<FilesMatch ".+\.ph(p[3457]?|t|tml)$">
SetHandler "proxy:unix:/run/php/php7.0-fpm.sock|fcgi://localhost"
</FilesMatch>
<FilesMatch ".+\.phps$">
# Deny access to raw php sources by default
# To re-enable it's recommended to enable access to the files
# only in specific virtual host or directory
Require all denied
</FilesMatch>
# Deny access to files without filename (e.g. '.php')
<FilesMatch "^\.ph(p[3457]?|t|tml|ps)$">
Require all denied
</FilesMatch>
</IfModule>
Run Code Online (Sandbox Code Playgroud)
所以我创建了自己的 conf 并将指令中的代码放入其中并启用它。
存在是php7.0-fpm.conf
为了什么?如果我在 conf 之外启用它,我的网站就会停止工作。我担心我没有按照预期的方式做这件事,将来可能会出现问题。很难找到关于此的好的、最新的文档。
作为参考,这是我的整个过程:
sudo apt install libapache2-mod-fastcgi php-fpm
sudo a2dismod php7.0 mpm_prefork
sudo a2enmod actions fastcgi alias mpm_worker
sudoedit /etc/apache2/conf-available/custom-fpm.conf
Run Code Online (Sandbox Code Playgroud)
内容/etc/apache2/conf-available/custom-fpm.conf
:
<IfModule mod_fastcgi.c>
AddHandler php7-fcgi .php
Action php7-fcgi /php7-fcgi virtual
Alias /php7-fcgi /usr/lib/cgi-bin/php7-fcgi
FastCgiExternalServer /usr/lib/cgi-bin/php7-fcgi -socket /var/run/php/php7.0-fpm.sock -pass-header
<Directory /usr/lib/cgi-bin>
Require all granted
</Directory>
</IfModule>
Run Code Online (Sandbox Code Playgroud)
命令继续:
sudo a2enconf custom-fpm
sudo systemctl restart apache2 && sudo systemctl restart php7.0-fpm
Run Code Online (Sandbox Code Playgroud)
在此先感谢您的帮助。
小智 12
我遇到了同样的困惑,我感受到了你的痛苦。经过大量阅读后,我很清楚大多数文章都已过时并引用了以前的方法(或有时是组合)。
在 Ubuntu 16.04 的内置配置中使用 PHP-FPM,您只需要执行以下操作:
sudo a2enconf php7.0-fpm
sudo a2enmod proxy proxy_fcgi
Run Code Online (Sandbox Code Playgroud)
我做了你所做的大部分事情,然后在自定义配置没有意义时将其全部删除。
现有的 php7.0-fpm.conf 有什么用?
您发现由软件包安装的配置用于使用 mod_proxy_fcgi。它使用 mod_proxy 通过 Unix 域套接字将 .php 文件通过 mod_proxy_fcgi 绑定到 PHP FPM。据我所知,这是最新的“食谱”(现在可用的六个!)
您不需要安装libapache2-mod-fastcgi
这是一种不同的旧方法。您不需要编写该配置 - 那是为了直接使用 mod_fastcgi。您不需要安装actions fastcgi alias
它们来配置 mod_fastcgi。
我确实觉得很奇怪,没有一篇文章——甚至是那些针对 Ubuntu 16 的文章——提到新配方都是为你设置的!
这条评论为我澄清了历史:
现在首选的方法是 fastcgi,使用以下任一方法:
(mod_fastcgi, httpd 2.2) http://wiki.apache.org/httpd/php-fastcgi
(mod_fcgid, httpd 2.2) http://wiki.apache.org/httpd/php-fcgid
(mod_proxy_fcgi, httpd 2.4) http://wiki.apache.org/httpd/PHP-FPM
http://php.net/manual/en/install.unix.debian.php#112544 (2013)
此外这篇来自 Apache 的文章详细介绍了配置 mod_proxy_fcgi 以使用 ProxyPassMatch 或 SetHandler + UDS 连接到 FPM 的三个子选项。请注意,UDS 是从 Apache 2.4.10 开始的,每个https://httpd.apache.org/docs/2.4/mod/mod_proxy_fcgi.html因此需要 trusty-backports 或更新版本。
https://wiki.apache.org/httpd/PHP-FPM
所以我开始想象现在有六种方法可以配置它:
大致按历史顺序:
Apache PHP 模块:mod_php(旧方式)
通过 FastCGI - 使用 Handler/Action/Alias/FastCgiExternalServer 配置
一种。mod_fastcgi
湾 mod_fcgid
通过 mod_proxy_fcgi 使用 PHP-FPM,通过以下任一方式配置:
一种。TCP 套接字(IP 和端口) ProxyPassMatch ... fcgi://127.0.0.1:9000/path/
湾 Unix 域套接字 (UDS) ProxyPassMatch … unix:/path/to/socket
C。(UDS) 通过 SetHandler "proxy:unix: OR SetHandler "proxy:fcgi:
免责声明:这对我来说是全新的,所以我可能仍然有五件事错误和十件事需要学习。