Windows 下 Apache 1.3 以 FastCGI 模式运行 PHP
我一直以来都是以 ISAPI 模式运行 php(做为现在的主流开发语言) 的,这种方式最大的缺点就是稳定性不好,当 php(做为现在的主流开发语言) 出错的时候,apache(Unix平台最流行的WEB服务器平台)进程也死掉了。后来看到网上关于 php(做为现在的主流开发语言) 以 Fastcgi(现在已经不多人在用了) 模式运行的介绍,其中提到的种种好处(稳定、安全、高性能)让我决定尝试一下。
不过事情远不如预计的那么顺利。Google 了无数次也没找到一篇如何在 Windows 下用 apache(Unix平台最流行的WEB服务器平台) + Fastcgi(现在已经不多人在用了) 跑 php(做为现在的主流开发语言) 的资料,iis(微软的WEB服务器平台) + Fastcgi(现在已经不多人在用了) 跑 php(做为现在的主流开发语言) 的倒是不少。其中有一篇提到 Zend 公司也推荐以 Fastcgi(现在已经不多人在用了) 模式运行 php(做为现在的主流开发语言)(http://php(做为现在的主流开发语言)lens.com/php(做为现在的主流开发语言)everywhere/fastcgi(现在已经不多人在用了)-php(做为现在的主流开发语言))。
经过几个小时的摸索,终于成功实现了 apache(Unix平台最流行的WEB服务器平台) 1.3 + Fastcgi(现在已经不多人在用了) 跑 php(做为现在的主流开发语言)。
准备工作:
首先访问 http://www.fastcgi(现在已经不多人在用了).com/dist/ 下载用于 apache(Unix平台最流行的WEB服务器平台) 的 mod_fastcgi(现在已经不多人在用了)。我使用的是 mod_fastcgi(现在已经不多人在用了)-2.4.2-AP13.dll。下载后将这个文件复制到 apache(Unix平台最流行的WEB服务器平台) 的 modules 目录中。
下载 php(做为现在的主流开发语言)(我使用的 php(做为现在的主流开发语言)-5.0.4),并解压缩,根据需要修改 php(做为现在的主流开发语言).ini 文件。注意不需要从 php(做为现在的主流开发语言) 所在目录复制任何文件到 Windows 目录中。
修改配置:
然后修改 httpd.conf 文件,加入下面几行:
LoadModule fastcgi(现在已经不多人在用了)_module modules/mod_fastcgi(现在已经不多人在用了)-2.4.2-AP13.dll
ScriptAlias /fcgi(现在已经不多人在用了)-php(做为现在的主流开发语言)5/ "d:/usr/local/php(做为现在的主流开发语言)-5.0.4/"
Fastcgi(现在已经不多人在用了)Server "d:/usr/local/php(做为现在的主流开发语言)-5.0.4/php(做为现在的主流开发语言)-cgi(现在已经不多人在用了).exe" -processes 3
# 说明:此处的 -processes 3 表示启动三个 php(做为现在的主流开发语言)-cgi(现在已经不多人在用了).exe 进程,
# 关于 Fastcgi(现在已经不多人在用了)Server 的详细参数请参考 Fastcgi(现在已经不多人在用了) 文档。
AddType application/x-httpd-fastphp(做为现在的主流开发语言)5 .php(做为现在的主流开发语言)
Action application/x-httpd-fastphp(做为现在的主流开发语言)5 "/fcgi(现在已经不多人在用了)-php(做为现在的主流开发语言)5/php(做为现在的主流开发语言)-cgi(现在已经不多人在用了).exe"
# 说明:根据你的 php(做为现在的主流开发语言) 文件所在位置修改上面两处黑体字。
修改完成后,重新启动 apache(Unix平台最流行的WEB服务器平台) 即可。
常见问题:
根据我的多次试验,最容易出现的几个问题主要都是由路径引起的。因此首先检查 php(做为现在的主流开发语言).ini 和 httpd.conf 文件中的所有路径是否正确。其次就是如果系统中以前安装过 php(做为现在的主流开发语言),那么要将 C:Windowsphp(做为现在的主流开发语言).ini 改名或删除。
其次还要检查 php(做为现在的主流开发语言) 文件所在目录是否有足够的权限(我都是设置为 Everyone - 完全控制,反正开发用机不用考虑那么多安全限制)。
Fastcgi(现在已经不多人在用了) 模式运行 php(做为现在的主流开发语言) 的优点:
以 Fastcgi(现在已经不多人在用了) 模式运行 php(做为现在的主流开发语言) 有几个主要的好处。首先就是 php(做为现在的主流开发语言) 出错的时候不会搞垮 apache(Unix平台最流行的WEB服务器平台),只是 php(做为现在的主流开发语言) 自己的进程当掉(但 Fastcgi(现在已经不多人在用了) 会立即重新启动一个新 php(做为现在的主流开发语言) 进程来代替当掉的进程)。其次 Fastcgi(现在已经不多人在用了) 模式运行 php(做为现在的主流开发语言) 比 ISAPI 模式性能更好(我本来用 apache(Unix平台最流行的WEB服务器平台)Bench 进行了测试,但忘了保存结果,大家有兴趣可以自己测试)。
最后,就是可以同时运行 php(做为现在的主流开发语言)5 和 php(做为现在的主流开发语言)4。参考下面的配置文件,分别建立了两个虚拟主机,其中一个使用 php(做为现在的主流开发语言)5,另一个使用 php(做为现在的主流开发语言)4。
LoadModule fastcgi(现在已经不多人在用了)_module modules/mod_fastcgi(现在已经不多人在用了)-2.4.2-AP13.dll
ScriptAlias /fcgi(现在已经不多人在用了)-php(做为现在的主流开发语言)5/ "d:/usr/local/php(做为现在的主流开发语言)-5.0.4/"
Fastcgi(现在已经不多人在用了)Server "d:/usr/local/php(做为现在的主流开发语言)-5.0.4/php(做为现在的主流开发语言)-cgi(现在已经不多人在用了).exe" -processes 3
ScriptAlias /fcgi(现在已经不多人在用了)-php(做为现在的主流开发语言)4/ "d:/usr/local/php(做为现在的主流开发语言)-4.3.11/"
Fastcgi(现在已经不多人在用了)Server "d:/usr/local/php(做为现在的主流开发语言)-4.3.11/php(做为现在的主流开发语言).exe"
Listen 80
NameVirtualHost *:80
DocumentRoot d:/www
Options Indexes FollowSymlinks MultiViews
ServerName php(做为现在的主流开发语言)5.localhost
AddType application/x-httpd-fastphp(做为现在的主流开发语言)5 .php(做为现在的主流开发语言)
Action application/x-httpd-fastphp(做为现在的主流开发语言)5 "/fcgi(现在已经不多人在用了)-php(做为现在的主流开发语言)5/php(做为现在的主流开发语言)-cgi(现在已经不多人在用了).exe"
IndexOptions FancyIndexing FoldersFirst
Options Indexes FollowSymLinks MultiViews
AllowOverride None
Order allow,deny
Allow from all
Listen 8080
NameVirtualHost *:8080
DocumentRoot d:/www
Options Indexes FollowSymlinks MultiViews
ServerName php(做为现在的主流开发语言)4.localhost
AddType application/x-httpd-fastphp(做为现在的主流开发语言)4 .php(做为现在的主流开发语言)
Action application/x-httpd-fastphp(做为现在的主流开发语言)4 "/fcgi(现在已经不多人在用了)-php(做为现在的主流开发语言)4/php(做为现在的主流开发语言).exe"

Hot AI Tools

Undresser.AI Undress
AI-powered app for creating realistic nude photos

AI Clothes Remover
Online AI tool for removing clothes from photos.

Undress AI Tool
Undress images for free

Clothoff.io
AI clothes remover

Video Face Swap
Swap faces in any video effortlessly with our completely free AI face swap tool!

Hot Article

Hot Tools

Notepad++7.3.1
Easy-to-use and free code editor

SublimeText3 Chinese version
Chinese version, very easy to use

Zend Studio 13.0.1
Powerful PHP integrated development environment

Dreamweaver CS6
Visual web development tools

SublimeText3 Mac version
God-level code editing software (SublimeText3)

Hot Topics

PHP and Python each have their own advantages, and choose according to project requirements. 1.PHP is suitable for web development, especially for rapid development and maintenance of websites. 2. Python is suitable for data science, machine learning and artificial intelligence, with concise syntax and suitable for beginners.

To set up a CGI directory in Apache, you need to perform the following steps: Create a CGI directory such as "cgi-bin", and grant Apache write permissions. Add the "ScriptAlias" directive block in the Apache configuration file to map the CGI directory to the "/cgi-bin" URL. Restart Apache.

PHP is used to build dynamic websites, and its core functions include: 1. Generate dynamic content and generate web pages in real time by connecting with the database; 2. Process user interaction and form submissions, verify inputs and respond to operations; 3. Manage sessions and user authentication to provide a personalized experience; 4. Optimize performance and follow best practices to improve website efficiency and security.

When the Apache 80 port is occupied, the solution is as follows: find out the process that occupies the port and close it. Check the firewall settings to make sure Apache is not blocked. If the above method does not work, please reconfigure Apache to use a different port. Restart the Apache service.

PHP is still dynamic and still occupies an important position in the field of modern programming. 1) PHP's simplicity and powerful community support make it widely used in web development; 2) Its flexibility and stability make it outstanding in handling web forms, database operations and file processing; 3) PHP is constantly evolving and optimizing, suitable for beginners and experienced developers.

PHP is widely used in e-commerce, content management systems and API development. 1) E-commerce: used for shopping cart function and payment processing. 2) Content management system: used for dynamic content generation and user management. 3) API development: used for RESTful API development and API security. Through performance optimization and best practices, the efficiency and maintainability of PHP applications are improved.

PHP is mainly procedural programming, but also supports object-oriented programming (OOP); Python supports a variety of paradigms, including OOP, functional and procedural programming. PHP is suitable for web development, and Python is suitable for a variety of applications such as data analysis and machine learning.

Apache connects to a database requires the following steps: Install the database driver. Configure the web.xml file to create a connection pool. Create a JDBC data source and specify the connection settings. Use the JDBC API to access the database from Java code, including getting connections, creating statements, binding parameters, executing queries or updates, and processing results.
