


The Definitive Guide to Installing Apache2 and PHP4 in Windows_PHP Tutorial
Apache 2和PHP是创建交互式网站的流行方案,而且成本很低。在Windows中安装Apache 2是一件轻而易举的事情,但要使PHP 4与Apache 2配合无间地运行,就需要一定的技巧。
在PHP 4.3手册的Windows安装小节,没有解释如何让PHP与Apache 2配合使用,而有关Apache 2安装的小节缺失了你需要的大量信息。在网上公布的其他安装指南中,也包含了不少错误,使一些安装人员只好不断试验和犯错。例如,有些人甚至将PHP的DLL替换成其他PHP版本的DLL。OK,为了节省你的宝贵时间,我们准备了这篇最权威的指南文章,帮你扫除一切烦恼。
使用正确版本的Windows
首先要说一说兼容性:Apache 2不能在Windows 95上运行;在Windows 98上勉强能够运行,但不能作为服务使用。从4.3版本开始,PHP也不再支持Windows 95。所以,你的Windows操作系统必须是Windows NT、2000或者XP。
Apache 2:源码还是二进制?
如果你有Visual C++ 5.0或更高的版本,或者安装了Microsoft Visual Studio,那么虽然可以根据源码来生成Apache,但请绝对不要这样做。在Visual Studio IDE中,Windows下的生成过程非常复杂。即使从命令行编译,也绝对不是一件易事。所以,除非你喜欢创建makefile,否则最好获得一份Windows Installer二进制发行包,也就是一个.msi文件。等你对Apache有了足够多的认识,知道自己要进行哪些定制操作时,才可考虑亲手生成(编译)Apache。
如果已经安装好并正在运行老版本的Apache,首先要停止它,卸载它,然后才能开始安装新服务器。多个版本的Apache 2不能共存。
双击Apache 2 .msi文件。同意许可协议后,会出现如图A所示的对话框。
图A
正确地设置Network Domain和Server Name(如果不打算将Apache安装到远程计算机,那么设置localhost就可以了),在Administrator's Email Address区域输入你的电子邮件地址,保持端口80/服务选项单选钮的选中状态。在下一个对话框中如果选择Typical安装,可以快速地获得一个能实际工作的服务器环境。
安装提示
建议将默认安装目录从C:\Program Files\Apache Group变成C:\Apache或者符合8.3文件名格式的其他名称。这样一来,以后每次输入Apache安装路径时,都不必为其添加引号。
稍候片刻,安装向导会告诉你Apache 2安装成功。接下来惟一要做的事情就是进行测试,请打开浏览器并访问localhost,这样应该看到默认的Apache 2主页。
然后可以删除主Web服务器目录中的所有示例文件,它们默认位于C:\InstallDirectory\Apache\Apache2\htdocs中。如果有一个现成的主页Index.html,请把它拷贝到这里;另外,也可以马上创建一个空白主页。对于未初始化的HTML,以下代码就可以了:
转自:动态网制作指南 www.knowsky.comcolor=#0066ff>
title=default server page
Default server page
让Apache 2为PHP做好准备
从现在开始,你需要较多地以人工方式进行安装,不能简单地点击和选择几个选项了事。尽快习惯它吧,这才是Apache的方式。你需要编辑文件来设置不同的配置选项;如果操作不当,你所做的修改就会妨碍Apache的正确加载。如果设置引发错误,那么错误可能被记录到Apache 2错误日志中(默认为C:\InstallDir\Apache2\Logs\Error.log)。但能够像这样进行记录的毕竟是少数,大多数错误只会记录到Windows事件日志中(开始| 设置| 控制面板| 管理工具| 事件查看器)。
令人遗憾的是,在你对安装设置进行调试时,Windows事件日志并不是一个方便的工具。更好的做法是在命令行窗口中测试Apache服务器的加载,这样能立即看到错误报告。所以,在完成了我即将讨论的配置修改后,请打开一个命令行窗口,切换到Apache的binary目录(C:\InstallDir\Apache2\bin),在那里启动Apache。
Apache配置文件是C:\Apache\Apache2\Conf\Httpd.conf,可用任何文本编辑器来编辑。查找DirectoryIndex,定位到下面这一行:
DirectoryIndex index.html index.html.var # index.php
为了允许Apache处理PHP页,要删除注释字符(#),变成:
DirectoryIndex index.html index.html.var index.php
还要允许在任何目录中使用.htaccess文件,所以请在配置文件中查找AllowOverride,把这个设置从None改成All。保存了所做的改动后,可继续在文本编辑器中打开该文件,因为等会儿安装PHP时,要再次编辑这个文件。
安装PHP
虽然可以下载PHP的源码,但和Apache 2一样,最好直接使用二进制发行包。Apache 2可采取2种方式来运行PHP程序:通过一个CGI接口来运行(外部调用Php.exe),或者使用PHP的DLL文件在Apache的内部运行。后一种方式的速度较快。所以,针对每个版本的PHP,都会提供2个Windows二进制发行包。较小的是.msi包,它会安装CGI可执行程序Php.exe,但其中拿掉了通过Apache DLL来运行PHP脚本所需的模块。较大的.zip包则包含了所有这些东西,你可以从snaps.php.net网站的Win32区域下载它们。文件下载完毕后,把它解压到C:\Php(保留文件夹名称)。除非你有绝对的把握,请同时下载PHP手册,它有多种语言的版本可供选择。
配置Apache 2来运行PHP4
现在来到了最有趣的部分:将Apache和PHP完美地配合起来。首先,请将C:\Php\Dlls目录中的所有DLL文件拷贝到Windows的System目录(%windir%\System)。接着,在Apache的配置文件(Httpd.conf)中查找包含了大量AddType命令那个小节,自己添加下面这一行:
AddType application/x-httpd-php .php
将C:\Php\Php.ini-recommended拷贝到Windows目录(%windir%),把它重命名为Php.ini,并用文本编辑器打开它。编辑其中对doc_root、extension_dir和session.save_path进行设置的3行,使其和下面展示的一致,注意要把InstallDir替换成你的Apache 2的安装目录的名称。
doc_root = c:\apache\apache2\htdocs
extension_dir = c:\php\extensions
session.save_path = c:/temp
在session.save_path中使用正斜杠和反斜杠都是允许的。PHP手册声称这些路径参数需要在最后添加一个反斜杠,但这个说法是不正确的。在PHP 4.3中不需要这样做。另外,如果C:\Temp不存在,请自己创建它。
下一步是允许Apache将PHP程序作为模块来运行,这要求你采取2个步骤。首先,将C:\Php\Php4ts.dll拷贝到Windows的系统文件夹(%windir%\System)。在Httpd.conf中找到LoadModule小节,自己添加下面这一行:
LoadModule php4_module “c:/php/php4apache2.dll”
如果你出于某种原因而需要在CGI模式中运行PHP程序(使用Php.exe),请将上面这一行变成注释,并在Httpd.conf中添加下面这些行:
ScriptAlias /php/ "c:/php/"
Action application/x-httpd-php "/php/php.exe"
一切都搞定了吗?
After saving the changes, you need to prove two things yourself to ensure that Apache 2/PHP 4 is a perfect match: Can Apache load properly? Can it handle PHP pages correctly? ?
To know whether Apache can load normally, enter the following command in the command line window you have opened:
apache –k start
In addition, if Apache is running, It can be restarted with the following command:
apache –k restart
The advantage of starting Apache from the command line is that if an error occurs, Apache will report it immediately. The most common problem you may encounter is that Apache may not be able to load Php4apache2.dll for some reason. If Apache reports this error, please follow the steps described above again to make sure everything is correct.
To know if Apache can handle PHP pages correctly, use your text editor to create a simple PHP page, named Phptest.php, which only contains the following line:
phpinfo(); ?>
Save the file to the main web server directory (C:InstallDirectoryApacheApache2Htdocs), and use a browser to access http://localhost/phptest.php. If everything is fine, you should see a web page with the PHP logo and a lot of settings and other information. To know whether PHP is currently running through CGI or inside Apache, you can check the environment variable orig_script_name. If PHP is run via CGI, the value of this variable is /Php/Php.exe. If Apache is running PHP scripts as modules, the value of this variable should be /Phptest.php.
Although installing Apache 2 and PHP on Windows is not an easy task, there is no need to cross the river by feeling for the stones. Through the instructions in this article, you should be able to quickly set up the best and lowest-cost web development environment in history.

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

AI Hentai Generator
Generate AI Hentai for free.

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

The way to update ByBit exchanges varies by platform and device: Mobile: Check for updates and install in the app store. Desktop Client: Check for updates in the Help menu and install automatically. Web page: You need to manually access the official website for updates. Failure to update the exchange can lead to security vulnerabilities, functional limitations, compatibility issues and reduced transaction execution efficiency.

DeepSeek is a powerful intelligent search and analysis tool that provides two access methods: web version and official website. The web version is convenient and efficient, and can be used without installation; the official website provides comprehensive product information, download resources and support services. Whether individuals or corporate users, they can easily obtain and analyze massive data through DeepSeek to improve work efficiency, assist decision-making and promote innovation.

Detailed explanation and installation guide for PiNetwork nodes This article will introduce the PiNetwork ecosystem in detail - Pi nodes, a key role in the PiNetwork ecosystem, and provide complete steps for installation and configuration. After the launch of the PiNetwork blockchain test network, Pi nodes have become an important part of many pioneers actively participating in the testing, preparing for the upcoming main network release. If you don’t know PiNetwork yet, please refer to what is Picoin? What is the price for listing? Pi usage, mining and security analysis. What is PiNetwork? The PiNetwork project started in 2019 and owns its exclusive cryptocurrency Pi Coin. The project aims to create a one that everyone can participate

There are many ways to install DeepSeek, including: compile from source (for experienced developers) using precompiled packages (for Windows users) using Docker containers (for most convenient, no need to worry about compatibility) No matter which method you choose, Please read the official documents carefully and prepare them fully to avoid unnecessary trouble.

This tutorial demonstrates how to efficiently process XML documents using PHP. XML (eXtensible Markup Language) is a versatile text-based markup language designed for both human readability and machine parsing. It's commonly used for data storage an

A string is a sequence of characters, including letters, numbers, and symbols. This tutorial will learn how to calculate the number of vowels in a given string in PHP using different methods. The vowels in English are a, e, i, o, u, and they can be uppercase or lowercase. What is a vowel? Vowels are alphabetic characters that represent a specific pronunciation. There are five vowels in English, including uppercase and lowercase: a, e, i, o, u Example 1 Input: String = "Tutorialspoint" Output: 6 explain The vowels in the string "Tutorialspoint" are u, o, i, a, o, i. There are 6 yuan in total

The official website entrance of the Coinsuper Exchange: https://www.coinsuper.com. The client download channels are: Windows client, macOS client, and mobile (iOS/Android). Registration requires an email, mobile phone number and password, and you need to complete real-name authentication before you can trade. The platform provides a variety of digital asset transactions, including Bitcoin, Ethereum, etc., with the transaction fee rate of 0.1% for both orders and acceptors. Security safeguards include cold wallet storage, dual-factor verification, anti-money laundering and anti-terrorism financing measures, and with security public

BITGet is a cryptocurrency exchange that provides a variety of trading services including spot trading, contract trading and derivatives. Founded in 2018, the exchange is headquartered in Singapore and is committed to providing users with a safe and reliable trading platform. BITGet offers a variety of trading pairs, including BTC/USDT, ETH/USDT and XRP/USDT. Additionally, the exchange has a reputation for security and liquidity and offers a variety of features such as premium order types, leveraged trading and 24/7 customer support.
