background image

安装 php 路径是/usr/local/php/
1)安装 mod_fastcgi
wget http://www.fastcgi.com/dist/mod_fastcgi-2.4.6.tar.gz
tar zxvf mod_fastcgi-2.4.6.tar.gz
cd mod_fastcgi-2.4.6
cp Makefile.AP2 Makefile
vi Makefile,编辑 top_dir = /usr/local/httpd
make
make install
安装完后,
/usr/local/httpd/modules/多出一个文件:mod_fcgid.so
2)重新编译 php
./configure --prefix=/usr/local/php --enable-fastcgi --enable-force-cgi-redirect --disable-cli
make 
make install
这样编译后,在 PHP 的 bin 目录下的 php-cgi 就是 fastcgi 模式的 php 解释器了
安装成功后,执行
php -v 输出
PHP 5.3.2 (cgi-fcgi).
这里输出带了 cgi-fcgi

注意:

1.

 –

编译参数不能加 with-apxs=/usr/local/httpd/bin/apxs 否则安装出来的 php 执行文件是 cli

模式的
2 如果编译时不加--disable-cli

 

则输出 PHP 5.3.2(cli)

3)配置 apache
需要配置 apache 来以 fastcgi 模式运行 php 程序
vi httpd.conf
我们使用虚拟机的方式实现:
代码如下:
#加载 fastcgi 模块
LoadModule fastcgi_module modules/mod_fastcgi.so
#

//以静态方式执行 fastcgi 启动了 10 进程

FastCgiServer /usr/local/php/bin/php-cgi -processes 10 -idle-timeout 150 -pass-header 
HTTP_AUTHORIZATION
<VirtualHost *:80>
#
DocumentRoot /usr/local/httpd/fcgi-bin 
ServerName www.fastcgitest.com
 
ScriptAlias /fcgi-bin/ /usr/local/php/bin/ #

 

定义目录映射 /fcgi-bin/ 

 

代替 /usr/local/php/bin/

Options +ExecCGI
AddHandler fastcgi-script .php .fcgi #.php 结尾的请求都要用 php-fastcgi

 

来处理

AddType application/x-httpd-php .php #增加 MIME 类型