配置apache以fastcgi運行php

來源:互聯網
上載者:User

標籤:http   os   io   使用   java   ar   檔案   div   cti   

配置apache以fastcgi運行php  文章目錄[隱藏]
  • 安裝apache
  • 安裝fastcgi
  • 安裝php5.2
  • 配置apache支援php

apache預設是用內建的mod_php模組運行php,現在我們介紹使用fastcgi來執行php指令碼。先說下fastcgi的優點:
Fastcgi的優點:

  • 從穩定性上看, fastcgi是以獨立的進程池運行來cgi,單獨一個進程死掉,系統可以很輕易的丟棄,然後重新分 配新的進程來運行邏輯.
  • · 從安全性上看,Fastcgi支援分布式運算. fastcgi和宿主的server完全獨立, fastcgi怎麼down也不會把server搞垮.
  • · 從效能上看, fastcgi把動態邏輯的處理從server中分離出來, 大負荷的IO處理還是留給宿主server, 這樣宿主server可以一心一意作IO,對於一個普通的動態網頁來說, 邏輯處理可能只有一小部分, 大量的圖片等靜態
  • IO處理完全不需要邏輯程式的參與.
  • · 從擴充性上講, fastcgi是一個中立的技術標準, 完全可以支援任何語言寫的處理常式 (php,java,perl,ruby,c++,python...)
  • · 適用作業系統,可在任何平台上http://www.fastcgi.com/dist/mod_fastcgi-current.tar.gz使用
安裝apache
  1. wget http://apache.ziply.com//httpd/httpd-2.2.21.tar.gz
  2. tar xzf httpd-2.2.21.tar.gz
  3. cd httpd-2.2.21
  4. ./configure --prefix=/usr/local/apache
  5. make && make install
安裝fastcgi
  1. wget http://www.fastcgi.com/dist/mod_fastcgi-2.4.6.tar.gz
  2. tar xzf mod_fastcgi-2.4.6.tar.gz
  3. cd mod_fastcgi-2.4.6
  4. cp Makefile.AP2 Makefile
  5. make top_dir=/usr/local/apache
  6. make top_dir=/usr/local/apache install

完成之後編輯httpd.conf設定檔,加入fastcgi模組裝載代碼:

  1. LoadModule fastcgi_module modules/mod_fastcgi.so
安裝php5.2
  1. wget http://us2.php.net/get/php-5.2.17.tar.gz/from/am.php.net/mirror
  2. tar xzf php-5.2.17.tar.gz
  3. cd php-5.2.17
  4. ./configure --prefix=/usr/local/php --enable-fastcgi --disable-cli
  5. make && make install
配置apache支援php

編輯httpd.conf檔案,加入如下代碼:

  1. ### fastcgi ###
  2. ScriptAlias /fcgi-bin/ "/usr/local/php/bin/"
  3. AddHandler php-fastcgi .php
  4. Action php-fastcgi /fcgi-bin/php-cgi
  5. AddType application/x-httpd-php .php
  6.  
  7. <IfModule mod_fcgid.c>
  8.     AddHandler fcgid-script. .php .fcgi   ### 暫時只配置支援.php
  9.     IdleTimeout 300
  10.     ProcessLifeTime 1800
  11.     MaxProcessCount 100
  12.     DefaultMinClassProcessCount 3
  13.     DefaultMaxClassProcessCount 8
  14.     IPCConnectTimeout 15
  15.     IPCCommTimeout 300
  16.     MaxRequestsPerProcess 100
  17. </IfModule>
  18. ### fastcgi ###

建立虛擬機器主機可以這樣配置:

  1. <VirtualHost *:80>
  2.  DocumentRoot /usr/local/apache/htdocs
  3.  ServerName localhost
  4.  Options +ExecCGI
  5.  AddHandler fastcgi-script .fcgi
  6.  AddType application/x-httpd-php .php
  7.  Action application/x-httpd-php /fcgi-bin/php-cgi
  8.  <Directory /usr/local/apache/htdocs>
  9.  Options Indexes ExecCGI
  10.  Order allow,deny
  11.  allow from all
  12.  </Directory>
  13. </VirtualHost>

詳細的fastcgi指令配置請看:http://www.fastcgi.com/mod_fastcgi/docs/mod_fastcgi.html

 

轉載請標明文章來源:《https://www.centos.bz/2011/12/configure-apache-run-php-as-fastcgi/》

配置apache以fastcgi運行php

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.