{"id":1017,"date":"2009-12-11T14:51:00","date_gmt":"2009-12-11T06:51:00","guid":{"rendered":"\/?p=1017"},"modified":"2009-12-11T14:51:00","modified_gmt":"2009-12-11T14:51:00","slug":"1017","status":"publish","type":"post","link":"https:\/\/blog.vimge.com\/archives\/php\/1017.html","title":{"rendered":"PHP\u5728Apache\u4e2d\u4e24\u79cd\u5de5\u4f5c\u65b9\u5f0f\u7684\u533a\u522b(CGI\u6a21\u5f0f\u3001Apache \u6a21\u5757DLL)"},"content":{"rendered":"
Windows \u4e0b\u6709\u4e24\u79cd\u65b9\u6cd5\u4f7f PHP \u5de5\u4f5c\u4e8e Apache 2.0.x \u4e4b\u4e2d\u3002\u4e00\u79cd\u662f \u4f7f\u7528 CGI \u53ef\u6267\u884c\u7a0b\u5e8f\uff0c\u53e6\u4e00\u79cd\u662f\u9002\u7528 Apache \u6a21\u5757\u7684 DLL\u3002
\u8fd9\u4e24\u79cd\u5de5\u4f5c\u65b9\u5f0f\u7684\u5b89\u88c5\uff1a<\/p>\n
PHP \u5728 Apache 2.0 \u4e2d\u7684 CGI \u65b9\u5f0f
ScriptAlias \/php\/ "c:\/php\/"
AddType application\/x-httpd-php .php<\/p>\n
# \u5bf9 PHP 4 \u7528\u8fd9\u884c
Action application\/x-httpd-php "\/php\/php.exe"
# \u5bf9 PHP 5 \u7528\u8fd9\u884c
Action application\/x-httpd-php "\/php\/php-cgi.exe"
PHP \u5728 Apache 2.0 \u4e2d\u7684\u6a21\u5757\u65b9\u5f0f
# \u5bf9 PHP 4 \u7528\u8fd9\u4e24\u884c\uff1a
LoadModule php4_module "c:\/php\/php4apache2.dll"
# \u522b\u5fd8\u4e86\u4ece sapi \u76ee\u5f55\u4e2d\u628a php4apache2.dll \u62f7\u8d1d\u51fa\u6765\uff01
AddType application\/x-httpd-php .php<\/p>\n
# \u5bf9 PHP 5 \u7528\u8fd9\u4e24\u884c\uff1a
LoadModule php5_module "c:\/php\/php5apache2.dll"
AddType application\/x-httpd-php .php
# \u914d\u7f6e php.ini \u7684\u8def\u5f84
PHPIniDir "C:\/php"<\/p>\n
\u8fd9\u4e24\u79cd\u5de5\u4f5c\u65b9\u5f0f\u7684\u533a\u522b\uff1a
\u5728CGI\u6a21\u5f0f\u4e0b\uff0c\u5982\u679c\u5ba2\u6237\u673a\u8bf7\u6c42\u4e00\u4e2aphp\u6587\u4ef6\uff0cWeb\u670d\u52a1\u5668\u5c31\u8c03\u7528php.exe\u53bb\u89e3\u91ca\u8fd9\u4e2a\u6587\u4ef6\uff0c\u7136\u540e\u518d\u628a\u89e3\u91ca\u7684\u7ed3\u679c\u4ee5\u7f51\u9875\u7684\u5f62\u5f0f\u8fd4\u56de\u7ed9\u5ba2\u6237\u673a\uff1b
\u800c\u5728\u6a21\u5757\u5316(DLL)\u4e2d\uff0cPHP\u662f\u4e0eWeb\u670d\u52a1\u5668\u4e00\u8d77\u542f\u52a8\u5e76\u8fd0\u884c\u7684\u3002
\u6240\u4ee5\u4ece\u67d0\u79cd\u89d2\u5ea6\u4e0a\u6765\u8bf4\uff0c\u4ee5apache\u6a21\u5757\u65b9\u5f0f\u5b89\u88c5\u7684 PHP4\u6709\u7740\u6bd4CGI\u6a21\u5f0f\u66f4\u597d\u7684\u5b89\u5168\u6027\u4ee5\u53ca\u66f4\u597d\u7684\u6267\u884c\u6548\u7387\u548c\u901f\u5ea6\u3002<\/p>\n
\u4e00\u3001FastCGI\u662f\u4ec0\u4e48\uff1f \u3000\u3000FastCGI\u7684\u5de5\u4f5c\u539f\u7406\u662f\uff1a \u3000\u3000\u5728\u4e0a\u8ff0\u60c5\u51b5\u4e2d\uff0c\u4f60\u53ef\u4ee5\u60f3\u8c61 CGI\u901a\u5e38\u6709\u591a\u6162\u3002\u6bcf\u4e00\u4e2aWeb\u8bf7\u6c42PHP\u90fd\u5fc5\u987b\u91cd\u65b0\u89e3\u6790php.ini\u3001\u91cd\u65b0\u8f7d\u5165\u5168\u90e8dll\u6269\u5c55\u5e76\u91cd\u521d\u59cb\u5316\u5168\u90e8\u6570\u636e\u7ed3\u6784\u3002\u4f7f\u7528FastCGI\uff0c\u6240\u6709\u8fd9\u4e9b\u90fd\u53ea\u5728\u8fdb\u7a0b\u542f\u52a8\u65f6\u53d1\u751f\u4e00\u6b21\u3002\u4e00\u4e2a\u989d\u5916\u7684\u597d\u5904\u662f\uff0c\u6301\u7eed\u6570\u636e\u5e93\u8fde\u63a5(Persistent database connection)\u53ef\u4ee5\u5de5\u4f5c\u3002<\/p>\n \u4e8c\u3001\u4e3a\u4ec0\u4e48\u8981\u4f7f\u7528FastCGI\uff0c\u800c\u4e0d\u662f\u591a\u7ebf\u7a0bCGI\u89e3\u91ca\u5668\uff1f \u4e09\u3001\u4e0d\u4f7f\u7528FastCGI\u7684\u7406\u7531 \u56db\u3001IIS FastCGI\u914d\u7f6e\u65b9\u6cd5
\u3000\u3000FastCGI\u662f\u8bed\u8a00\u65e0\u5173\u7684\u3001\u53ef\u4f38\u7f29\u67b6\u6784\u7684CGI\u5f00\u653e\u6269\u5c55\uff0c\u5176\u4e3b\u8981\u884c\u4e3a\u662f\u5c06CGI\u89e3\u91ca\u5668\u8fdb\u7a0b\u4fdd\u6301\u5728\u5185\u5b58\u4e2d\u5e76\u56e0\u6b64\u83b7\u5f97\u8f83\u9ad8\u7684\u6027\u80fd\u3002\u4f17\u6240\u5468\u77e5\uff0cCGI\u89e3\u91ca\u5668\u7684\u53cd\u590d\u52a0\u8f7d\u662fCGI\u6027\u80fd\u4f4e\u4e0b\u7684\u4e3b\u8981\u539f\u56e0\uff0c\u5982\u679cCGI\u89e3\u91ca\u5668\u4fdd\u6301\u5728\u5185\u5b58\u4e2d\u5e76\u63a5\u53d7FastCGI\u8fdb\u7a0b\u7ba1\u7406\u5668\u8c03\u5ea6\uff0c\u5219\u53ef\u4ee5\u63d0\u4f9b\u826f\u597d\u7684\u6027\u80fd\u3001\u4f38\u7f29\u6027\u3001Fail-Over\u7279\u6027\u7b49\u7b49\u3002
FastCGI\u7684\u5b98\u65b9\u7ad9\u70b9\u5728http:\/\/www.fastcgi.com<\/a><\/p>\n
\u3000\u30001\u3001Web Server \u542f\u52a8\u65f6\u8f7d\u5165FastCGI\u8fdb\u7a0b\u7ba1\u7406\u5668\uff08IIS ISAPI\u6216Apache Module\uff09;
\u3000\u30002\u3001FastCGI\u8fdb\u7a0b\u7ba1\u7406\u5668\u81ea\u8eab\u521d\u59cb\u5316\uff0c\u542f\u52a8\u591a\u4e2aCGI\u89e3\u91ca\u5668\u8fdb\u7a0b (\u5728\u4efb\u52a1\u7ba1\u7406\u5668\u4e2d\u53ef\u89c1\u591a\u4e2aphp-cgi.exe)\u5e76\u7b49\u5f85\u6765\u81eaWeb Server\u7684\u8fde\u63a5\u3002
\u3000\u30003\u3001\u5f53\u5ba2\u6237\u7aef\u8bf7\u6c42\u5230\u8fbeWeb Server\u65f6\uff0cFastCGI\u8fdb\u7a0b\u7ba1\u7406\u5668\u9009\u62e9\u5e76\u8fde\u63a5\u5230\u4e00\u4e2aCGI\u89e3\u91ca\u5668\u3002Web server\u5c06CGI\u73af\u5883\u53d8\u91cf\u548c\u6807\u51c6\u8f93\u5165\u53d1\u9001\u5230FastCGI\u5b50\u8fdb\u7a0bphp-cgi.exe\u3002
\u3000\u30004\u3001FastCGI\u5b50\u8fdb\u7a0b\u5b8c\u6210\u5904\u7406\u540e\u5c06\u6807\u51c6\u8f93\u51fa\u548c\u9519\u8bef\u4fe1\u606f\u4ece\u540c\u4e00\u8fde\u63a5\u8fd4\u56deWeb Server\u3002\u5f53FastCGI\u5b50\u8fdb\u7a0b\u5173\u95ed\u8fde\u63a5\u65f6\uff0c\u8bf7\u6c42\u4fbf\u544a\u5904\u7406\u5b8c\u6210\u3002FastCGI\u5b50\u8fdb\u7a0b\u63a5\u7740\u7b49\u5f85\u5e76\u5904\u7406\u6765\u81eaFastCGI\u8fdb\u7a0b\u7ba1\u7406\u5668\uff08\u8fd0\u884c\u5728 WebServer\u4e2d\uff09\u7684\u4e0b\u4e00\u4e2a\u8fde\u63a5\u3002 \u5728\u6b63\u5e38\u7684CGI\u6a21\u5f0f\u4e2d\uff0cphp-cgi.exe\u5728\u6b64\u4fbf\u9000\u51fa\u4e86\u3002<\/p>\n
\u3000\u3000\u8fd9\u53ef\u80fd\u51fa\u4e8e\u591a\u65b9\u9762\u7684\u8003\u8651\uff0c\u4f8b\u5982\uff1a
\u3000\u30001\u3001\u4f60\u65e0\u8bba\u5982\u4f55\u4e5f\u4e0d\u80fd\u5728windows\u5e73\u53f0\u4e0a\u7a33\u5b9a\u7684\u4f7f\u7528\u591a\u7ebf\u7a0bCGI\u89e3\u91ca\u5668\uff0c\u65e0\u8bba\u662fIIS ISAPI\u65b9\u5f0f\u8fd8\u662fAPACHE Module\u65b9\u5f0f\uff0c\u5b83\u4eec\u603b\u662f\u8fd0\u884c\u4e00\u6bb5\u65f6\u95f4\u5c31\u5d29\u6e83\u4e86\u3002\u5947\u602a\u4e48\uff1f\u4f46\u662f\u786e\u5b9e\u5b58\u5728\u8fd9\u6837\u7684\u60c5\u51b5\uff01
\u3000\u3000\u5f53\u7136\uff0c\u4e5f\u6709\u5f88\u591a\u65f6\u5019\u4f60\u80fd\u591f\u7a33\u5b9a\u7684\u4f7f\u7528\u591a\u7ebf\u7a0bCGI\u89e3\u91ca\u5668\uff0c\u4f46\u662f\uff0c\u4f60\u6709\u53ef\u80fd\u53d1\u73b0\u7f51\u9875\u6709\u65f6\u5019\u4f1a\u51fa\u73b0\u9519\u8bef\uff0c\u65e0\u8bba\u5982\u4f55\u4e5f\u627e\u4e0d\u5230\u539f\u56e0\uff0c\u800c\u6362\u7528FastCGI\u65b9\u5f0f\u65f6\u8fd9\u79cd\u9519\u8bef\u7684\u6982\u7387\u4f1a\u5927\u5927\u7684\u964d\u4f4e\u3002\u6211\u4e5f\u4e0d\u6e05\u695a\u8fd9\u662f\u4e3a\u4ec0\u4e48\uff0c\u6211\u60f3\u72ec\u7acb\u5730\u5740\u7a7a\u95f4\u7684CGI\u89e3\u91ca\u5668\u53ef\u80fd\u7ec8\u7a76\u6bd4\u5171\u4eab\u5730\u5740\u7a7a\u95f4\u7684\u5f62\u5f0f\u6765\u5f97\u7a33\u5b9a\u4e00\u70b9\u70b9\u3002
\u3000\u30002\u3001\u6027\u80fd\uff01\u6027\u80fd\uff1f\u53ef\u80fd\u4e48\uff0c\u96be\u9053FastCGI\u6bd4\u591a\u7ebf\u7a0bCGI\u89e3\u91ca\u5668\u66f4\u5feb\uff1f\u4f46\u6709\u65f6\u5019\u786e\u5b9e\u662f\u8fd9\u6837\uff0c\u53ea\u6709\u6d4b\u8bd5\u4e00\u4e0b\u4f60\u7684\u7f51\u7ad9\uff0c\u624d\u80fd\u6700\u540e\u4e0b\u7ed3\u8bba\u3002\u539f\u56e0\u561b\uff0c\u6211\u89c9\u5f97\u5f88\u96be\u8bb2\uff0c\u4f46\u6709\u8d44\u6599\u8bf4\u5728Zend WinEnabler\u7684\u65f6\u4ee3\uff0cZend\u539f\u6765\u4e5f\u662f\u5efa\u8bae\u5728Windows\u5e73\u53f0\u4e0b\u4f7f\u7528FastCGI\u800c\u4e0d\u662fIIS ISAPI\u6216Apache Module\uff0c\u4e0d\u8fc7\u73b0\u5728Zend\u5df2\u7ecf\u4e0d\u505a\u8fd9\u4e2a\u4ea7\u54c1\u4e86\u3002<\/p>\n
\u3000\u30001\u3001\u591a\u8fdb\u7a0b\u6bd4\u591a\u7ebf\u7a0b\u6d88\u8017\u66f4\u591a\u7684\u670d\u52a1\u5668\u5185\u5b58\uff0cphp-cgi.exe\u89e3\u91ca\u5668\u6bcf\u8fdb\u7a0b\u6d88\u80177\u81f325\u5146\u5185\u5b58\uff0c\u5c06\u8fd9\u4e2a\u6570\u5b57\u4e58\u4ee550\u6216100\u8bd5\u8bd5\u3002
\u3000\u30002\u3001\u6027\u80fd\u3002\u786e\u5b9e\u6709\u65f6\u5019\u591a\u7ebf\u7a0bCGI\u89e3\u91ca\u5668\u66f4\u5feb\uff0c\u5475\u5475\uff0c\u800c\u4e14\u6709\u65f6\u5019\uff0c\u5b83\u4e5f\u5f88\u7a33\u5b9a\u3002
\u3000\u30003\u3001CGI\uff1f\u542c\u8d77\u6765\u5c31\u5f88\u571f\uff0c\u5475\u5475<\/p>\n
\u3000\u30001\u3001\u9996\u5148\u786e\u5b9a\u4f60\u5df2\u6b63\u786e\u5b89\u88c5\u4e86PHP 4.3.x\u53ca\u66f4\u65b0\u7684\u7248\u672c\u3002\u65e9\u671f\u7248\u672c\u7684PHP\u5e76\u672a\u9ed8\u8ba4\u52a0\u5165FastCGI\u652f\u6301\uff0c\u5982\u679c\u4f60\u60f3\u5728\u65e9\u671f\u7248\u672c\u4e2d\u5de5\u4f5c\uff0c\u9700\u8981\u91cd\u65b0\u7f16\u8bd1\u5b83\u3002\u6211\u4eec\u5047\u8bbePHP\u5b89\u88c5\u5728c:\\php\uff0c\u652f\u6301FastFCGI\u7684\u53ef\u6267\u884c\u6587\u4ef6\u540d\u662fphp-cgi.exe\u3002
\u3000\u3000\u3000\u3000\u6ce8\u610f\uff1a\u5efa\u8bae\u5728Php.ini\u4e2d\u5173\u95edcgi.force_redirect\uff0c\u542f\u7528fastcgi.impersonate\uff0c\u542f\u7528cgi.rfc2616_header<\/p>\n