apache下php配置fastcgi代替mod_php
来源:互联网 发布:数据库三张表关联查询 编辑:程序博客网 时间:2024/05/16 14:00
fastcgi
mod_php
it
apachephp配置
分类: LINUX-VPS资料一、fastcgi的好处:
1. FastCGI 像是一个常驻 (long-live) 型的 CGI,它可以一直执行着,只要激活后,不会每次都要花费时间去 fork 一次 (这是 CGI 最为人诟病的 fork-and-execute 模式)。
2. FastCGI 可在任何平台上使用,Netscape Enterprise 及 IIS 都有 FastCGI 的模块可供使用,阿帕契 (Apache,以及利用 Apache 衍生出做的服务器) 上也有 mod_fastcgi 可用。
3. FastCGI 支持 C/C++、Java、PHP、Python、Ruby、Perl,Tcl 等程序语言。
4. FastCGI 的应用程序亦兼容于 CGI。即 FastCGI 的应用程序也可以当成 CGI 来执行。
5. 现有的 CGI 程序要改写成 FastCGI 非常简单,最少可能只需要多加入三行程序代码。
6. FastCGI 的侦错方式与 CGI 大同小异,只要带入程序所需的环境变量及参数,即可在命令列模式执行或侦错。
7. FastCGI 应用程序的写作方式与 CGI 类似,除了几项原则要特别注意外,FastCGI 的写作方式跟 CGI 几乎一样,与学习 Web Server API 比较起来, FastCGI 简单多了。
8. FastCGI 支授分布式运算 (distributed computing),即 FastCGI 程序可以在网站服务器以外的主机上执行并且接受来自其它网站服务器来的请求。
二、性能比较
有两种观点,有说使用fastcgi替代mod_php后,速度更快了,效率fastcgi更胜一筹;但是我从实际情况来看,应该是mod_php比fastcgi要快一点的。老外有个Drupal爱好者写了一篇测试文章《mod_php or FastCGI?》(http://buytaert.net/drupal-performance?page=1),里面提到"When switching from mod_php to FastCGI we observe a 63% slowdown for anonymous visitors, and a 18% slowdown for authenticated visitors.",图标如下:
fastcgi官方的说法:
Of course, the answer is that it depends upon the application. A more complete answer is that FastCGI often wins by a significant margin, and seldom loses by very much.
个人观点:
如果在性能相差不大的情况下,还是更推荐使用fastcgi,那样的话可以更灵活,更安全。使用fastcgi,你的web server 可以比较简单的切换,可以测试不同的服务器,Apache,lightty,ngix 等等,不需要有代码的修改。再者,如果想换脚本的实现,如不用php,而是改成perl,python之类的,web服务器也不需要任何的改动。
三、配置
1.编译安装php,不能带–with-apxs2=,带上--enable-fastcgi
2.安装mod_fcgid
wgethttp://jaist.dl.sourceforge.net/sourceforge/mod-fcgid/mod_fcgid.2.2.tgz
tar zxvf mod_fcgid.2.2.tgz
cd mod_fcgid.2.2
make
make install
( )
vi /usr/local/apache2/conf/httpd.conf,加入:
### fastcgi ###
LoadModule fcgid_module modules/mod_fcgid.so
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 .py .pl .fcgi
AddHandler fcgid-script. .php .fcgi ### 暂时只配置支持.php
IdleTimeout 300
ProcessLifeTime 1800
MaxProcessCount 100
DefaultMinClassProcessCount 3
DefaultMaxClassProcessCount 8
IPCConnectTimeout 15
IPCCommTimeout 300
MaxRequestsPerProcess 100
# RewriteCond %{REQUEST_URI} ^/fcgi-bin/.* [NC]
# RewriteRule .*/php$ /nonexistent.file [L]
</IfModule>
# <Files ~ (/.php)>
# SetHandler fcgid-script
# FCGIWrapper /usr/local/php/bin/php .php
# Options +ExecCGI
# allow from all
#</Files>
### fastcgi ###
把:
<Directory />
Options FollowSymLinks
AllowOverride None
Order deny,allow
Deny from all
</Directory>
改成:
<Directory />
Options FollowSymLinks +ExecCGI
AllowOverride None
Order allow,deny
allow from all
</Directory>
( )
把具体VirtualHost对应的Directory做修改如下:
<Directory PATH>
Options FollowSymLinks
AllowOverride FileInfo Options All
Order allow,deny
Allow from all
</Directory>
改成:
<Directory PATH>
FCGIWrapper /var/www/php/bin/php .php
Options FollowSymLinks +ExecCGI
AllowOverride FileInfo Options All
Order allow,deny
Allow from all
</Directory>
/usr/local/php/bin/php -v 如果看不到类似于PHP 5.2.11 (cgi-fcgi) (built:的话,则可以:mv php php-cli
cp php-cgi php
重启Apache
- apache下php配置fastcgi代替mod_php
- apache 配置php mod_php cgi fastcgi访问方式
- apache nginx mod_php、FastCGI、PHP-FPM
- apache配置 之 fastcgi 与mod_php
- Apache + MySQL + PHP + FastCGI 配置(下)
- PHP 之 FastCGI 与 mod_php
- mod_php cgi fastcgi php-fpm
- php在apache中安装模式的区别:fastcgi和mod_php
- php在apache中安装模式的区别:fastcgi和mod_php
- php在apache中安装模式的区别:fastcgi和mod_php
- php在apache中安装模式的区别:fastcgi和mod_php
- PHP 之 FastCGI 与 mod_php 详解
- mod_php, FastCGI or PHP-FPM for Server?
- PHP填坑记之FastCGI与mod_php详解
- fastcgi+apache+php的配置
- windows下apache+fastCGI+PHP的安装与配置小计
- Apache下 FastCGI 配置小结
- Apache 配置------FastCGI方式使用PHP(包含:linux下编译安装fmod_fcgid,配置apache以支持FastCGI)
- 安装PHP出现make: *** [sapi/cli/php] Error 1 解决办法
- [Java] main方法的参数
- php缩略图...
- [转]使用C++为IIS的虚拟目录增加MIME类型
- A*算法求解最短路径
- apache下php配置fastcgi代替mod_php
- Control File (二)重建CONTROLFILE --- NORESETLOG
- Date、DateFormat、Calendar
- 成功不是必然的,努力才是必須的
- gdb 调试段错误
- vmstat的使用以及显示的字段信息说明
- 工厂模式(二)
- 开始写学习博客
- ASP.NET AjaxPro的应用