The authoritative guide for installing Apache2 and PHP4 in Apache windows

Source: Internet
Author: User
Tags apache windows php source code
Apache 2 and PHP are popular scenarios for creating interactive Web sites and are inexpensive. Installing Apache 2 in Windows is a breeze, but for PHP 4 to work seamlessly with Apache 2, you need some skill.
In the Windows installation section of the PHP 4.3 manual, there is no explanation for how to use PHP with Apache 2, while the section on Apache 2 installation is missing a lot of the information you need. Other installation guides published on the web include a number of errors that have allowed some installers to keep experimenting and making mistakes. For example, some people even replace PHP DLLs with other PHP versions of DLLs. OK, in order to save your valuable time, we have prepared this most authoritative guide article, help you to sweep away all troubles.
Using the correct version of Windows
The first thing to say is compatibility: Apache 2 cannot run on Windows 95; It is barely able to run on Windows 98, but it cannot be used as a service. Starting with version 4.3, PHP also no longer supports Windows 95. Therefore, your Windows operating system must be Windows NT, 2000, or XP.
Apache 2: source or binary?
If you have Visual C + + 5.0 or later, or if you have Microsoft Visual Studio installed, you can generate Apache based on the source code, but never do so. In the visual Studio IDE, the build process under Windows is very complex. Even compiling from the command line is definitely not an easy thing to do. So, unless you like to create makefile, it's a good idea to get a copy of the Windows Installer binary release package, which is an. msi file. When you have enough knowledge of Apache to know what custom actions you want to make, you can only consider generating (compiling) your own Apache.
If you have already installed and are running an older 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 agreeing to the license agreement, set the network domain and server Name correctly (if you do not intend to install Apache on the remote computer, then set up localhost), at administrator ' s Email Enter your e-mail address area to keep the port 80/Service option radio button selected. In the next dialog box, if you choose Typical installation, you can quickly get a server environment that can actually work.
Installation Tips
It is recommended that you change the default installation directory from C:\Program Files\apache group to C:\Apache or another name that matches the 8.3 file name format. This way, you do not have to add quotation marks each time you enter the Apache installation path.
After a while, the installation Wizard will tell you that the Apache 2 installation was successful. The only thing to do next is to test, open your browser and visit localhost, so you should see the default Apache 2 home page.
You can then delete all the sample files in the main Web server directory, which are in C:\InstallDirectory\Apache\Apache2\htdocs by default. If you have a ready-made homepage index.html, please copy it here; Alternatively, you can create a blank home page right away. For uninitialized HTML, the following code is available:
<body> Default Server Page </body>
Get Apache 2 ready for PHP
From now on, you need to install more manually, not simply clicking and selecting a few options. Get used to it as soon as possible, this is the Apache way. You need to edit the file to set different configuration options, and if you do it incorrectly, your changes will prevent Apache from loading properly. If the setting throws an error, then the error may be logged in the Apache 2 error log (default is C:\InstallDir\Apache2\Logs\Error.log). But there are a handful of records that can be recorded like this, and most errors are only recorded in the Windows event log (Start | Settings | Control Panel | Management Tools | Event Viewer).
Unfortunately, the Windows event log is not a convenient tool when you are debugging Setup settings. A better practice is to test the Apache server load in a command-line window so that you can immediately see the error report. So, after completing the configuration changes I'm about to discuss, open a command-line window and switch to Apache's binary directory (C:\InstallDir\Apache2\bin), where Apache is launched.
The Apache configuration file is C:\Apache\Apache2\Conf\Httpd.conf and can be edited by any text editor. Locate the DirectoryIndex, and navigate to the following line:
DirectoryIndex index.html Index.html.var # index.php
To allow Apache to process PHP pages, remove the comment character (#) and change to:
DirectoryIndex index.html Index.html.var index.php
Also allow the. htaccess file to be used in any directory, so look for the allowoverride in the configuration file and change the setting from none to all. After you save your changes, you can continue to open the file in a text editor, because you will need to edit the file again when you install PHP later.
Install PHP
Although you can download PHP source code, but like Apache 2, it is best to use the binary distribution package directly. Apache 2 can be used in 2 ways to run PHP programs: Run via a CGI interface (external call to Php.exe), or use PHP DLL files to run inside Apache. The latter way is faster. Therefore, for each version of PHP, 2 windows binaries are available. The smaller is the. msi package, which installs the CGI executable Php.exe, but it takes away the modules required to run PHP scripts through the Apache DLL. The larger. zip package contains all of these items and you can download them from the Win32 area of the website. Once the file has been downloaded, unzip it to C:\PHP (keep the folder name). Unless you are absolutely sure, please also download the PHP manual, which is available in multiple languages.
Configure Apache to run PHP4
Now comes the most interesting part: the perfect match between Apache and PHP. First, copy all the DLL files in the C:\Php\Dlls directory to the Windows System directory (%windir%\system). Next, look for the section in the Apache configuration file (httpd.conf) that contains a large number of ADDTYPE commands and add the following line yourself:
AddType application/x-httpd-php. php
Copy the C:\Php\Php.ini-recommended to the Windows directory (%windir%), rename it to PHP.ini, and open it with a text editor. Edit the 3 lines in which the Doc_root, Extension_dir, and Session.save_path are set to match the one shown below, and note to replace the installdir with the name of your Apache 2 installation directory.
Doc_root = C:\apache\apache2\htdocs
Extension_dir = C:\php\extensions
Session.save_path = C:/temp
It is permissible to use both forward slash and backslash in Session.save_path. The PHP manual claims that these path parameters need to be added at the end of a backslash, but this argument is incorrect. You do not need to do this in PHP 4.3. In addition, if C:\Temp does not exist, create it yourself.
The next step is to allow Apache to run the PHP program as a module, which requires you to take 2 steps. First, copy the C:\Php\Php4ts.dll to the Windows System folder (%Windir%\System). Find the LoadModule section in httpd.conf and add the following line yourself:
LoadModule php4_module "C:/php/php4apache2.dll"
If you need to run a PHP program in CGI mode for some reason (using Php.exe), turn the line above into a comment and add the following lines in httpd.conf:
Action application/x-httpd-php "/php/php.exe"
Has everything been done?
After you save your changes, you need to prove two points in person to make sure Apache 2/php 40% is a perfect pair: can Apache load properly, and can it handle PHP pages correctly?
To see if Apache can load properly, enter the following command in the Command line window that you have opened:
Apache–k start
Also, if Apache is running, you can restart it 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 might encounter is that Apache may not be able to load Php4apache2.dll for some reason. If Apache reports this error, follow the steps described earlier to make sure that nothing is wrong.
To know if Apache can properly handle PHP pages, use your text editor to create a simple PHP page named phptest.php, which contains only the following line:
? Phpinfo ();? >
Save the file to the main Web server directory (C:\InstallDirectory\Apache\Apache2\Htdocs) and use the browser to access the http://localhost/phptest.php. If everything works, you should see a Web page with a PHP logo that contains 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 runs through CGI, the value of this variable is/php/php.exe. If Apache runs the php script as a module, the value of the variable should be/phptest.php.
Although installing Apache 2 and PHP on Windows is not an easy task, there is absolutely no need to take a stones approach. With the instructions in this article, you should be able to quickly build the best and lowest-cost web development environment in history.

The above describes the installation of Apache2 and PHP4 authoritative guide in Apache windows, including the Apache content, I hope to be interested in PHP tutorial friends helpful.

  • Related Article

    Contact Us

    The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

    If you find any instances of plagiarism from the community, please send an email to: and provide relevant evidence. A staff member will contact you within 5 working days.

    A Free Trial That Lets You Build Big!

    Start building with 50+ products and up to 12 months usage for Elastic Compute Service

    • Sales Support

      1 on 1 presale consultation

    • After-Sales Support

      24/7 Technical Support 6 Free Tickets per Quarter Faster Response

    • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.