简体   繁体   English

如何使用Apache 2.4和PHP 5.4启用FastCGI

[英]How to enable FastCGI with Apache 2.4 and PHP 5.4

What I have done: 我做了什么:

Install apache 2.4 and php 5.4 from source. 从源代码安装apache 2.4和php 5.4。

apache config: apache的配置:

./configure --prefix=/usr/local/apache --sysconfdir=/etc/httpd24 --enable-so --enable-ssl --enable-cgi --enable-rewrite --with-zlib --with-pcre --with-apr=/usr/local/apr --with-apr-util=/usr/local/apr-util/ --enable-modules=most --enable-mpms-shared=all --with-mpm=event

php config PHP配置

./configure --prefix=/usr/local/php \ 
--with-mysql=mysqlnd\
--with-pdo-mysql=mysqlnd \
--with-mysqli=mysqlnd \
--enable-mbstring \
--with-freetype-dir \
--with-jpeg-dir\
--with-png-dir\
--with-zlib \
--with-libxml-dir=/usr/local/libxml2 \
--enable-xml \
--enable-sockets \
--enable-fpm \
--with-mcrypt \
--with-config-file-path=/etc \
--with-config-file-scan-dir=/etc/php.d \
--with-bz2\
--with-apxs2=/usr/local/apache/bin/apxs

In the httpd.conf file, I enabled the mod_proxy.so and mod_proxy_fcgi.so and add the following config: 在httpd.conf文件中,我启用了mod_proxy.so和mod_proxy_fcgi.so并添加以下配置:

<IfModule proxy_module>
  ProxyRequests off
  ProxyPassMatch ^/(.*\.php)$ fcgi://127.0.0.1:9000/var/www/$1
</IfModule>

from phpinfo(), I see the Server API is FPM/FastCGI 从phpinfo(),我看到服务器API是FPM / FastCGI

My Problem: I set the DirectoryIndex as below. 我的问题:我将DirectoryIndex设置如下。 I have index.html in the DirectoryRoot which is "/var/www". 我在DirectoryRoot中有index.html,它是“ / var / www”。 When I visit localhost, I am supposed to see the content of index.html. 当我访问localhost时,应该看到index.html的内容。 But it gave a 404 file not found. 但它给出了一个404文件未找到。

<IfModule dir_module>
    DirectoryIndex index.php index.html
</IfModule>

When I switch the position of index.html and php in the above code. 当我在上面的代码中切换index.html和php的位置时。 This time the html file is in front of php file. 这次html文件在php文件的前面。 Then when I visit localhost, I can see the right content. 然后,当我访问localhost时,可以看到正确的内容。 And I checked the apache error log. 然后我检查了apache错误日志。 It says: 它说:

[Thu May 01 23:21:15.968659 2014] [proxy_fcgi:error] [pid 3415:tid 140603093 993216] [client 192.168.1.157:60384] AH01071: Got error 'Primary script unkn own\\n' [2014年5月1日星期三23:21:15.968659] [proxy_fcgi:错误] [pid 3415:tid 140603093 993216] [客户端192.168.1.157:60384] AH01071:收到错误消息“主脚本未知” \\ n

When there is only index.php file in the /var/www, and leaving the httpd.conf like 当/ var / www中只有index.php文件时,而像

<IfModule dir_module>    DirectoryIndex  index.html index.php</IfModule>

Also got 404, visiting the localhost. 还得到了404,访问了本地主机。

My Question: 我的问题:

  1. How do I fix the above problem? 如何解决以上问题?

  2. I did some research on the configuration of fastcgi. 我对fastcgi的配置做了一些研究。 like this and this They dont mention the mod_proxy_fcgi, but all refering this 这样这个他们没有提到mod_proxy_fcgi,但是都引用了这个

"FastCGIExternalServer /var/www/cgi-bin/php5.fcgi -host 127.0.0.1:9000" “ FastCGIExternalServer /var/www/cgi-bin/php5.fcgi -host 127.0.0.1:9000”

So I am not sure if I am using the FastCgi the right way? 所以我不确定我是否正确使用FastCgi? Does this wrong way cause the above problem? 这种错误的方式会导致上述问题吗?

【PS】 Thank you regilero. 【PS】谢谢雷吉罗。 I'm not using vhost and I had checked the error.log. 我没有使用vhost,并且已经检查了error.log。 It seems having something to do with php-fpm. 似乎与php-fpm有关。 The response page in the browser says "file not found", not "404", although the response code is 404. Here is what's in the error.log 浏览器中的响应页面显示“找不到文件”,而不是“ 404”,尽管响应代码为404。这是error.log中的内容

[Thu May 01 23:21:15.968659 2014] [proxy_fcgi:error] [pid 3415:tid 140603093 993216] [client 192.168.1.157:60384] AH01071: Got error 'Primary script unknown\\n' [2014年5月1日星期三23:21:15.968659] [proxy_fcgi:错误] [pid 3415:tid 140603093 993216] [客户端192.168.1.157:60384] AH01071:出现错误“主脚本未知\\ n”

I try to forward all the requersts ended with ".php" to fcgi. 我尝试将所有以“ .php”结尾的请求转发给fcgi。 But the error above looks like that when I request index.html, it is also forwarded to the fcgi, which fcgi cannot handle it.(This is my guess) For the config about this forwarding, please see the code above, or search this page for "fcgi://". 但是上面的错误看起来像是当我请求index.html时,它也被转发到fcgi,fcgi无法处理它。(这是我的猜测)有关此转发的配置,请参见上面的代码或搜索此代码“ fcgi://”的页面。

Here is my Directory config. 这是我的目录配置。 I'm not sure if this is what you need. 我不确定这是否是您所需要的。

DocumentRoot "/var/www"
<Directory "/var/www">
Options FollowSymLinks
AllowOverride All
Require all granted
</Directory>

This is somewhat of a linked answer however it's one I share with many who come across the problem you are facing now and it seems to do the trick. 这在某种程度上是一个链接的答案,但是我与许多遇到这个问题的人共享一个答案,而且似乎可以解决问题。

Checkout this GIST -> https://gist.github.com/diemuzi/3849349 签出此GIST-> https://gist.github.com/diemuzi/3849349

There you will find all my working configurations for Apache and PHP-FPM. 在这里,您将找到我所有用于Apache和PHP-FPM的工作配置。 It seems like a better place to organize my configurations instead of pasting them here and confusing others. 这似乎是组织我的配置的好地方,而不是将其粘贴到此处并使其他人困惑。 This link will not expire so no worries about that. 该链接不会过期,因此无需担心。

Perhaps also you can compare my working examples with what you have and find something missing that you currently are not using. 也许您也可以将我的工作示例与已有的示例进行比较,找到当前未使用的缺少之处。 Hope this helps! 希望这可以帮助!

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM