1
votes

What I have done:

Install apache 2.4 and php 5.4 from source.

apache config:

./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

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

<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

My Problem: I set the DirectoryIndex as below. I have index.html in the DirectoryRoot which is "/var/www". When I visit localhost, I am supposed to see the content of index.html. But it gave a 404 file not found.

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

When I switch the position of index.html and php in the above code. This time the html file is in front of php file. Then when I visit localhost, I can see the right content. And I checked the apache error log. 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'

When there is only index.php file in the /var/www, and leaving the httpd.conf like

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

Also got 404, visiting the localhost.

My Question:

  1. How do I fix the above problem?

  2. I did some research on the configuration of fastcgi. like this and this They dont mention the mod_proxy_fcgi, but all refering this

"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? Does this wrong way cause the above problem?

【P.S.】 Thank you regilero. I'm not using vhost and I had checked the error.log. It seems having something to do with 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

[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'

I try to forward all the requersts ended with ".php" to 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://".

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>
1
For the link you have followed, they use the old way of connecting php-fpm in apache with libapache2-mod-fastcgi. Since version 2.4 mod_proxy_fastcgi is the new official way to go. Now you should show your complete vhost configuration, and the 404 errors should add lines on the apache error.log with useful informations.regilero

1 Answers

2
votes

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

There you will find all my working configurations for Apache and 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!