apache默认是用自带的mod_php模块运行php,现在我们介绍使用fastcgi来执行php脚本。先说下fastcgi的优点:
Fastcgi的优点:
安装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
转载请注明文章来源:http://www.centos.bz/2011/12/configure-apache-run-php-as-fastcgi/
固定链接: http://anywang.vicp.net:8180/wp/?p=257 | 网邻's Blog
最新评论
厉害,一个信息技术教师的水平