配置apache以fastcgi运行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
[*]wget http://apache.ziply.com//httpd/httpd-2.2.21.tar.gz
[*]tar xzf httpd-2.2.21.tar.gz
[*]cd httpd-2.2.21
[*]./configure --prefix=/usr/local/apache
[*]make && make install
安装fastcgi
[*]wget http://www.fastcgi.com/dist/mod_fastcgi-2.4.6.tar.gz
[*]tar xzf mod_fastcgi-2.4.6.tar.gz
[*]cd mod_fastcgi-2.4.6
[*]cp Makefile.AP2 Makefile
[*]make top_dir=/usr/local/apache
[*]make top_dir=/usr/local/apache install
完成之后编辑httpd.conf配置文件,加入fastcgi模块装载代码:
[*]LoadModule fastcgi_module modules/mod_fastcgi.so
安装php5.2
[*]wget http://us2.php.net/get/php-5.2.17.tar.gz/from/am.php.net/mirror
[*]tar xzf php-5.2.17.tar.gz
[*]cd php-5.2.17
[*]./configure --prefix=/usr/local/php --enable-fastcgi --disable-cli
[*]make && make install
配置apache支持php编辑httpd.conf文件,加入如下代码:
[*]### fastcgi ###
[*]ScriptAlias /fcgi-bin/ "/usr/local/php/bin/"
[*]AddHandler php-fastcgi .php
[*]Action php-fastcgi /fcgi-bin/php-cgi
[*]AddType application/x-httpd-php .php
[*]
[*]<IfModule mod_fcgid.c>
[*] AddHandler fcgid-script. .php .fcgi ### 暂时只配置支持.php
[*] IdleTimeout 300
[*] ProcessLifeTime 1800
[*] MaxProcessCount 100
[*] DefaultMinClassProcessCount 3
[*] DefaultMaxClassProcessCount 8
[*] IPCConnectTimeout 15
[*] IPCCommTimeout 300
[*] MaxRequestsPerProcess 100
[*]</IfModule>
[*]### fastcgi ###
建立虚拟主机可以这样配置:
[*]<VirtualHost *:80>
[*] DocumentRoot /usr/local/apache/htdocs
[*] ServerName localhost
[*] Options +ExecCGI
[*] AddHandler fastcgi-script .fcgi
[*] AddType application/x-httpd-php .php
[*] Action application/x-httpd-php /fcgi-bin/php-cgi
[*] <Directory /usr/local/apache/htdocs>
[*] Options Indexes ExecCGI
[*] Order allow,deny
[*] allow from all
[*] </Directory>
[*]</VirtualHost>
详细的fastcgi指令配置请看:http://www.fastcgi.com/mod_fastcgi/docs/mod_fastcgi.html
页:
[1]