title: How to enable FastCGI with Apache 2.4 and PHP 5.4
body: <p><strong>What I have done:</strong></p>
  
  <p>Install apache 2.4 and php 5.4 from source.</p>
  
  <p>apache config:</p>
  
  <pre><code>./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
  </code></pre>
  
  <p>php config</p>
  
  <pre><code>./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
  </code></pre>
  
  <p>In the httpd.conf file, I enabled the mod_proxy.so and mod_proxy_fcgi.so and add the following config:</p>
  
  <pre><code>&lt;IfModule proxy_module&gt;
    ProxyRequests off
    ProxyPassMatch ^/(.*\.php)$ fcgi://127.0.0.1:9000/var/www/$1
  &lt;/IfModule&gt;
  </code></pre>
  
  <p>from phpinfo(), I see the Server API is FPM/FastCGI</p>
  
  <p><strong>My Problem:</strong>
  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. </p>
  
  <pre><code>&lt;IfModule dir_module&gt;
      DirectoryIndex index.php index.html
  &lt;/IfModule&gt;
  </code></pre>
  
  <p>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: </p>
  
  <blockquote>
    <p>[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'</p>
  </blockquote>
  
  <p>When there is only index.php file in the /var/www, and leaving the httpd.conf like</p>
  
  <pre><code>&lt;IfModule dir_module&gt;    DirectoryIndex  index.html index.php&lt;/IfModule&gt;
  </code></pre>
  
  <p>Also got 404, visiting the localhost.</p>
  
  <p><strong>My Question:</strong></p>
  
  <ol>
  <li><p>How do I fix the above problem?</p></li>
  <li><p>I did some research on the configuration of fastcgi. like <a href="http://www.janoszen.com/2013/04/29/setting-up-apache-with-php-fpm/" rel="nofollow">this</a> and <a href="http://www.howtoforge.com/forums/showthread.php?t=62961" rel="nofollow">this</a>
  They dont mention the mod_proxy_fcgi, but all refering this </p></li>
  </ol>
  
  <blockquote>
    <p>"FastCGIExternalServer /var/www/cgi-bin/php5.fcgi -host
    127.0.0.1:9000"</p>
  </blockquote>
  
  <p>So I am not sure if I am using the FastCgi the right way? Does this wrong way cause the above problem?</p>
  
  <p>【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</p>
  
  <blockquote>
    <p>[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'</p>
  </blockquote>
  
  <p>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://".</p>
  
  <p>Here is my Directory config. I'm not sure if this is what you need.</p>
  
  <pre><code>DocumentRoot "/var/www"
  &lt;Directory "/var/www"&gt;
  Options FollowSymLinks
  AllowOverride All
  Require all granted
  &lt;/Directory&gt;
  </code></pre>