簡體   English   中英

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

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

我做了什么:

從源代碼安裝apache 2.4和php 5.4。

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配置

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

在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>

從phpinfo(),我看到服務器API是FPM / FastCGI

我的問題:我將DirectoryIndex設置如下。 我在DirectoryRoot中有index.html,它是“ / var / www”。 當我訪問localhost時,應該看到index.html的內容。 但它給出了一個404文件未找到。

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

當我在上面的代碼中切換index.html和php的位置時。 這次html文件在php文件的前面。 然后,當我訪問localhost時,可以看到正確的內容。 然后我檢查了apache錯誤日志。 它說:

[2014年5月1日星期三23:21:15.968659] [proxy_fcgi:錯誤] [pid 3415:tid 140603093 993216] [客戶端192.168.1.157:60384] AH01071:收到錯誤消息“主腳本未知” \\ n

當/ var / www中只有index.php文件時,而像

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

還得到了404,訪問了本地主機。

我的問題:

  1. 如何解決以上問題?

  2. 我對fastcgi的配置做了一些研究。 這樣這個他們沒有提到mod_proxy_fcgi,但是都引用了這個

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

所以我不確定我是否正確使用FastCgi? 這種錯誤的方式會導致上述問題嗎?

【PS】謝謝雷吉羅。 我沒有使用vhost,並且已經檢查了error.log。 似乎與php-fpm有關。 瀏覽器中的響應頁面顯示“找不到文件”,而不是“ 404”,盡管響應代碼為404。這是error.log中的內容

[2014年5月1日星期三23:21:15.968659] [proxy_fcgi:錯誤] [pid 3415:tid 140603093 993216] [客戶端192.168.1.157:60384] AH01071:出現錯誤“主腳本未知\\ n”

我嘗試將所有以“ .php”結尾的請求轉發給fcgi。 但是上面的錯誤看起來像是當我請求index.html時,它也被轉發到fcgi,fcgi無法處理它。(這是我的猜測)有關此轉發的配置,請參見上面的代碼或搜索此代碼“ fcgi://”的頁面。

這是我的目錄配置。 我不確定這是否是您所需要的。

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

這在某種程度上是一個鏈接的答案,但是我與許多遇到這個問題的人共享一個答案,而且似乎可以解決問題。

簽出此GIST-> https://gist.github.com/diemuzi/3849349

在這里,您將找到我所有用於Apache和PHP-FPM的工作配置。 這似乎是組織我的配置的好地方,而不是將其粘貼到此處並使其他人困惑。 該鏈接不會過期,因此無需擔心。

也許您也可以將我的工作示例與已有的示例進行比較,找到當前未使用的缺少之處。 希望這可以幫助!

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM