Install Apache2 and PHP4 in Windows
Author: Zhou Jing Translation Source: ZDNet
Apache 2 and PHP are an popular scheme for creating an interactive website and a low cost. Installing Apache 2 in Windows is a light, but to make PHP 4 with Apache 2, you need some skill.
In the Windows Installation Section of the PHP 4.3 manual, it does not explain how to make PHP with Apache 2, and the subtraction of Apache 2 is missing the large amount of information you need. In other installation guidelines released on the Internet, there is a lot of errors that make some installations have had to experiment and make mistakes. For example, some people even replace the PHP's DLL to other PHP versions of the DLL. OK, in order to save your valuable time, we prepare this most authoritative guide article, help you sweep all troubles.
Use the correct version of Windows
The first thing to say is to say compatibility: Apache 2 cannot run on Windows 95; barely can run on Windows 98, but cannot be used as a service. From version 4.3, PHP no longer supports Windows 95. So, your Windows operating system must be Windows NT, 2000 or XP. Apache 2: Source or binary? If you have Visual C 5.0 or higher, or install Microsoft Visual Studio, although you can generate Apache according to source code, please do not do this. In Visual Studio IDE, the generation process under Windows is very complicated. Even from the command line, it is absolutely not a matter. So, unless you like to create makefile, it is best to get a Windows Installer binary distribution package, which is a .msi file. When you have enough understandings for Apache, you can consider yourself (compilation) Apache when you do what you have to do. If you have already installed and run the old version of Apache, first stop it, uninstall it, and then start installing the new server. Multiple versions of Apache 2 cannot coexist. Double-click the Apache 2 .msi file. After agrees with the license agreement, the dialog shown in Figure A will appear.
Figure A
Set NetWork Domain and Server Name correctly (if you do not intend to install Apache to remote computer, set LocalHost), enter your email address in the Administrator's Email Address area, keep the port 80 / service option, lettage button. status. In the next dialog, if you select a Typical installation, you can quickly get a server environment that can actually work.
Installation Tips It is recommended to turn the default installation directory from C: / Program Files / Apache Group into C: / Apache or other names that meet the 8.3 file name format. In this way, you don't have to add quotes for each time you enter the Apache installation path.
Wait a moment, the installation wizard will tell you that apache 2 is successful. The only thing to do next is to test, please open your browser and visit LocalHost so you should see the default Apache 2 home page. You can then delete all sample files in the main web server directory, which are located in C: / InstallDirectory / Apache / Apache2 / HTDOCS by default. If there is a ready-made home index.html, copy it here; in addition, you can also create a blank home page immediately. For HTMLs that are not initialized, the following code can be:
title = default server page head> default server page body> html> Let Apache 2 are ready for PHP
From now on, you need to install more in manual way, you can't simply click and choose a few options. I am used to it as soon as possible, this is the way Apache. You need to edit files to set different configuration options; if you don't operate, what you do will hinder the correct loading of Apache. If you set an error, then the error may be recorded in the Apache 2 error log (default is C: /installDir/apache2/logs/error.log). But after all, it is a small number, most errors will only be logged into the Windows event log (Start | Settings | Control Panel | Administrative Tools | Event Viewer).
Unfortunately, the Windows event log is not a convenient tool when you debug the installation settings. Better approach is to test the loading of the Apache server in the command line window, so you can see the error report immediately. So, after completing the configuration modification I will discuss, open a command line window to switch to the binary directory of Apache (C: / InstallDir / Apache2 / bin), where to start Apache.
The Apache profile is c: /apache/apache2/conf/httpd.conf, you can use any text editor to edit. Find DirectoryIndex, locate this line: DirectoryIndex index.html index.html.var # index.php In order to allow apache to process PHP pages, you want to delete a comment character (#), becomes: DirectoryIndex index.html index.html.var Index .php
Also allow you to use the .htaccess file in any directory, so find the Allowoverride in the configuration file, change this setting from NONE to all. After saving the changes, you can continue to open the file in the text editor, because when you install PHP, you must edit this file again.
Install PHP
Although the source code of PHP can be downloaded, it is best to use a binary issue package directly with Apache 2. Apache 2 can take two ways to run the PHP program: run through a CGI interface (external call php.exe), or use the PHP's DLL file to run in the Apache. The latter way is faster. Therefore, 2 Windows binary issuings are available for each version of PHP. Smaller is the .msi package, which will install the CGI executable program php.exe, but take off the modules required to run the PHP script through the Apache DLL. A larger .zip package includes all these things, you can download them from the Win32 area of the snaps.php.net website. After the file is downloaded, extract it to the C: / PHP (Reserved Folder Name). Unless you have an absolute grasp, please download the PHP manual at the same time, it has multiple languages to choose from.
Configure Apache 2 to run PHP4
Now come to the most interesting part: the Apache and PHP are perfectly matched. First, copy all the DLL files in the C: / PHP / DLLS directory to the system directory (% windir% / system) of Windows. Next, lookups in the Apache's configuration file (httpd.conf) contains that section containing a large number of addtype commands, adds the following line: addtype application / x-httpd-php .php C: / php/php.ini-recommended copy Go to the Windows Directory (% windir%), rename it as php.ini, and open it with a text editor. Edit the 3 lines set for doc_root, extension_dir and session.save_path, making it the same as the following, pay attention to replace installdir to replace the name of your Apache 2 installation directory. Doc_root = c: / apache / apache2 / htdocsextension_dir = c: /php/extensionsSession.Save_path = C: / Temp is allowed to use the forward slash and backslash in session.save_path. The PHP manual claiming that these path parameters need to add a backslash at the end, but this statement is incorrect. Don't do this in PHP 4.3. Also, if C: / Temp does not exist, create it yourself. The next step is to allow Apache to run a PHP program as a module, which requires you to take 2 steps. First, copy C: /PHP/PHP4TS.DLL to Windows system folder (% windir% / system). Find the LoadModule section in httpd.conf, add this line below: loadModule PHP4_Module "C: /php/php4apache2.dll" If you need to run the PHP program in the CGI mode for some reason, use php.exe), Please turn the above line into a comment, and add the following lines in httpd.conf: scriptalias / php / "c: / php /" action application / x-httpd-php "/ php/php.exe" everything Yet?