Apache|window Apache 2 and PHP are popular scenarios for creating interactive Web sites, and the cost is low. It's easy to install Apache 2 in Windows, but it takes a lot of skill to make PHP 4 work seamlessly with Apache 2.
In the Windows installation section of the PHP 4.3 manual, there is no explanation for how PHP can be used in conjunction with Apache 2, and the section on Apache 2 installation lacks the amount of information you need. Other installation guides published on the web also contain a number of errors that make it easier for some installers to experiment and make 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, helps you to eliminate all troubles.
Using the correct version of Windows
First of all, let's say 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. 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 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 creating 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 and know what custom operations you want to make, you can consider creating (compiling) Apache yourself.
If you have 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 network domain and server Name correctly (if you do not intend to install Apache to a remote computer, set localhost on it), in the administrator ' s Email Enter your email address in the adress area and keep the port 80/service option radio buttons selected. If you choose Typical installation in the next dialog box, 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 other names that conform to the 8.3 file name format. As a result, you do not have to add quotes to the Apache installation path each time you enter it.
A few moments later, the Setup Wizard will tell you that the Apache 2 installation was successful. The only thing to do next is to test, open the browser and access 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 located in C:\InstallDirectory\Apache\Apache2\htdocs by default. If you have a ready-made homepage index.html, please copy it here, or you can create a blank home page immediately. For uninitialized HTML, the following code is available:
<body> Default Server Page </body>
Make Apache 2 ready for PHP
From now on, you need to do more manual installation, not simply click and select a few options. Get used to it as soon as possible, this is the way of Apache. You need to edit the file to set different configuration options, and if not, your modifications will prevent Apache from loading correctly. If the setting throws an error, the error may be logged to the Apache 2 error log (default is C:\InstallDir\Apache2\Logs\Error.log). But there are few that can be logged like this, and most errors will only be recorded in the Windows event log (Start | Set up | 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 load of the Apache server in the command Line window, so that you can see the error report immediately. 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 you can start Apache.
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, delete the annotation character (#) and change to:
DirectoryIndex index.html Index.html.var index.php
Also allow the use of the. htaccess file in any directory, so find allowoverride in the configuration file and change this setting from none to all. After you save your changes, you can continue to open the file in a text editor, because you will edit the file again when you install PHP later.
Installing PHP
Although you can download PHP's source code, but as with Apache 2, it is best to use the binary distribution package directly. Apache 2 can run a PHP program in 2 ways: Run with a CGI interface (external call Php.exe) or use PHP's DLL file to run inside Apache. The latter way is faster. Therefore, for each version of PHP, there are 2 Windows binary release packs available. The smaller one is the. msi package, which installs the CGI executable Php.exe, but takes away the modules needed to run the PHP script through the Apache DLL. The larger. zip package contains all of these items, and you can download them from the Win32 area of the Snaps.php.net site. When the file is downloaded, extract it to C:\PHP (keep the folder name). Unless you are absolutely sure, download the PHP manual at the same time, it has a variety of language versions to choose from.
Configure Apache and run PHP4
Now comes the most interesting part: the perfect combination of Apache and PHP. First, copy all the DLL files from the C:\Php\Dlls directory to the Windows System directory (%windir%\system). Next, look up the section of 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 that the INSTALLDIR is replaced 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
Both the forward slash and the backslash are allowed in the Session.save_path. The PHP manual claims that these path parameters require a backslash to be added at the end, but this is not true. You do not need to 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 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 to the httpd.conf:
scriptalias/php/"c:/php/"
Action application/x-httpd-php "/php/php.exe"
Is everything done?
After you save your changes, you need to prove two in person to make sure that Apache 2/php 40% is the perfect partner: does Apache load correctly, and does it handle PHP pages properly?
To know 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 may 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 nothing is wrong.
To know if Apache can handle PHP pages correctly, create a simple PHP page with your text editor 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 access http://localhost/phptest.php in the browser. If everything works, you should see a Web page with a PHP logo that contains a lot of settings and other information. To see if PHP is currently running through CGI or inside Apache, 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 it is not easy to install Apache 2 and PHP on Windows, 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 cheapest web development environment in history.
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:
info-contact@alibabacloud.com
and provide relevant evidence. A staff member will contact you within 5 working days.