search
HomeBackend DevelopmentPHP TutorialThe Definitive Guide to Installing Apache2 and PHP4 on Apache Windows

Apache 2 and PHP are popular options for creating interactive websites at very low cost. Installing Apache 2 in Windows is a breeze, but making PHP 4 run seamlessly with Apache 2 requires certain skills.
In the Windows installation section of the PHP 4.3 manual, there is no explanation of how to use PHP with Apache 2, and the section on Apache 2 installation is missing a lot of information you need. Other installation guides posted online also contain many errors, forcing some installers to resort to trial and error. For example, some people even replace PHP DLLs with DLLs from other PHP versions. OK, in order to save your precious time, we have prepared this most authoritative guide article to help you eliminate all worries.
Use the correct version of Windows
First, let’s talk about compatibility: Apache 2 cannot run on Windows 95; it can barely run on Windows 98, but it cannot be used as a service. Starting from version 4.3, PHP no longer supports Windows 95. Therefore, your Windows operating system must be Windows NT, 2000 or XP.
 Apache 2: Source code or binary?
 If you have Visual C++ 5.0 or higher, or have Microsoft Visual Studio installed, then although you can generate Apache from the source code, please never do this. In the Visual Studio IDE, the generation process under Windows is very complicated. Even compiling from the command line is definitely not an easy task. So, unless you like creating makefiles, it's best to get a copy of the Windows Installer binary distribution, which is an .msi file. Only when you know enough about Apache and know what customization operations you want to perform can you consider generating (compiling) Apache yourself.
 If you have installed and are running an old version of Apache, you must first stop it and uninstall it before you can 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 plan to install Apache to a remote computer, then set localhost), enter your email address in the Administrator's Email Address field, and keep the port 80/Service tab The selected state of the option button. If you choose Typical installation in the next dialog box, you can quickly get a server environment that actually works.
 Installation Tips
 It is recommended to change the default installation directory from C:Program FilesApache Group to C:Apache or other names that comply with the 8.3 file name format. This way, you don't have to add quotes to the Apache installation path every time you enter it in the future.
  Wait a moment and the installation wizard will tell you that Apache 2 is successfully installed. The only thing left to do next is to test. Open a browser and visit localhost. 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 by default in C:InstallDirectoryApacheApache2htdocs. If there is a ready-made homepage Index.html, please copy it here; in addition, you can also create a blank homepage immediately. For uninitialized HTML, the following code will do:
<html>
<head>title=default server page</head>
<body>Default server page</body>
</html>
Let Apache 2 be PHP is ready
From now on, you need to install it more manually, and you can't simply click and select 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; if not done correctly, the changes you make will prevent Apache from loading correctly. If the setting causes an error, the error may be logged to the Apache 2 error log (default is C:InstallDirApache2LogsError.log). But there are only a few that can be recorded like this, and most errors will only be recorded in the Windows event log (Start | Settings | Control Panel | Administrative Tools | Event Viewer).
Sadly, the Windows event log is not a handy tool when debugging your installation setup. A better approach is to test the loading of the Apache server in a command line window so you can see error reports immediately. So, after completing the configuration changes I'm about to discuss, open a command line window, switch to Apache's binary directory (C:InstallDirApache2bin), and start Apache there.
 The Apache configuration file is C:ApacheApache2ConfHttpd.conf and can be edited with any text editor.Find DirectoryIndex and locate the following line:
DirectoryIndex index.html index.html.var # index.php
In order to allow Apache to process the PHP page, delete the comment character (#) and become:
DirectoryIndex index.html index.html .var index.php
 Also allow the use of .htaccess files in any directory, so please look for AllowOverride in the configuration file and change this setting from None to All. After saving 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 the source code of PHP, like Apache 2, it is best to use the binary distribution package directly. Apache 2 can run PHP programs in two ways: through a CGI interface (calling Php.exe externally), or using a PHP DLL file to run inside Apache. The latter method is faster. Therefore, for each version of PHP, 2 Windows binary distribution packages will be provided. The smaller one is the .msi package, which installs the CGI executable Php.exe, but removes the modules required to run PHP scripts through the Apache DLL. The larger .zip package contains all these things and can be downloaded from the Win32 section of the snaps.php.net website. Once the file is 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.
  Configuring Apache 2 to run PHP4
Now comes the most interesting part: perfectly matching Apache and PHP. First, please copy all DLL files in the C:PhpDlls directory to the Windows System directory (%windir%System). Next, look for the section containing a large number of AddType commands in the Apache configuration file (Httpd.conf), and add the following line yourself:
AddType application/x-httpd-php .php
Copy C:PhpPhp.ini-recommended to Windows directory (%windir%), rename it to Php.ini and open it with a text editor. Edit the three lines that set doc_root, extension_dir and session.save_path to be consistent with those shown below. Be sure to replace InstallDir with the name of your Apache 2 installation directory.
doc_root = c:apacheapache2htdocs
extension_dir = c:phpextensions
session.save_path = c:/temp
The use of forward slashes and backslashes in session.save_path is allowed. The PHP manual claims that these path parameters require a backslash at the end, but this is incorrect. This is not required in PHP 4.3. Also, if C:Temp does not exist, create it yourself.
 The next step is to allow Apache to run PHP programs as modules, which requires you to take 2 steps. First, copy C:PhpPhp4ts.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 PHP programs in 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 "
Is everything done?
After saving the changes, you need to prove two things yourself to ensure that Apache 2/PHP 4 is a perfect pair: 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, you can restart it with the following command:
apache –k restart
From the command The advantage of starting Apache online 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 whether Apache can handle PHP pages correctly, please 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: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.

The above introduces the authoritative guide for installing Apache2 and PHP4 in Apache Windows, including Apache content. I hope it will be helpful to friends who are interested in PHP tutorials.

Statement
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Explain the concept of a PHP session in simple terms.Explain the concept of a PHP session in simple terms.Apr 26, 2025 am 12:09 AM

PHPsessionstrackuserdataacrossmultiplepagerequestsusingauniqueIDstoredinacookie.Here'showtomanagethemeffectively:1)Startasessionwithsession_start()andstoredatain$_SESSION.2)RegeneratethesessionIDafterloginwithsession_regenerate_id(true)topreventsessi

How do you loop through all the values stored in a PHP session?How do you loop through all the values stored in a PHP session?Apr 26, 2025 am 12:06 AM

In PHP, iterating through session data can be achieved through the following steps: 1. Start the session using session_start(). 2. Iterate through foreach loop through all key-value pairs in the $_SESSION array. 3. When processing complex data structures, use is_array() or is_object() functions and use print_r() to output detailed information. 4. When optimizing traversal, paging can be used to avoid processing large amounts of data at one time. This will help you manage and use PHP session data more efficiently in your actual project.

Explain how to use sessions for user authentication.Explain how to use sessions for user authentication.Apr 26, 2025 am 12:04 AM

The session realizes user authentication through the server-side state management mechanism. 1) Session creation and generation of unique IDs, 2) IDs are passed through cookies, 3) Server stores and accesses session data through IDs, 4) User authentication and status management are realized, improving application security and user experience.

Give an example of how to store a user's name in a PHP session.Give an example of how to store a user's name in a PHP session.Apr 26, 2025 am 12:03 AM

Tostoreauser'snameinaPHPsession,startthesessionwithsession_start(),thenassignthenameto$_SESSION['username'].1)Usesession_start()toinitializethesession.2)Assigntheuser'snameto$_SESSION['username'].Thisallowsyoutoaccessthenameacrossmultiplepages,enhanc

What are some common problems that can cause PHP sessions to fail?What are some common problems that can cause PHP sessions to fail?Apr 25, 2025 am 12:16 AM

Reasons for PHPSession failure include configuration errors, cookie issues, and session expiration. 1. Configuration error: Check and set the correct session.save_path. 2.Cookie problem: Make sure the cookie is set correctly. 3.Session expires: Adjust session.gc_maxlifetime value to extend session time.

How do you debug session-related issues in PHP?How do you debug session-related issues in PHP?Apr 25, 2025 am 12:12 AM

Methods to debug session problems in PHP include: 1. Check whether the session is started correctly; 2. Verify the delivery of the session ID; 3. Check the storage and reading of session data; 4. Check the server configuration. By outputting session ID and data, viewing session file content, etc., you can effectively diagnose and solve session-related problems.

What happens if session_start() is called multiple times?What happens if session_start() is called multiple times?Apr 25, 2025 am 12:06 AM

Multiple calls to session_start() will result in warning messages and possible data overwrites. 1) PHP will issue a warning, prompting that the session has been started. 2) It may cause unexpected overwriting of session data. 3) Use session_status() to check the session status to avoid repeated calls.

How do you configure the session lifetime in PHP?How do you configure the session lifetime in PHP?Apr 25, 2025 am 12:05 AM

Configuring the session lifecycle in PHP can be achieved by setting session.gc_maxlifetime and session.cookie_lifetime. 1) session.gc_maxlifetime controls the survival time of server-side session data, 2) session.cookie_lifetime controls the life cycle of client cookies. When set to 0, the cookie expires when the browser is closed.

See all articles

Hot AI Tools

Undresser.AI Undress

Undresser.AI Undress

AI-powered app for creating realistic nude photos

AI Clothes Remover

AI Clothes Remover

Online AI tool for removing clothes from photos.

Undress AI Tool

Undress AI Tool

Undress images for free

Clothoff.io

Clothoff.io

AI clothes remover

Video Face Swap

Video Face Swap

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

Hot Tools

VSCode Windows 64-bit Download

VSCode Windows 64-bit Download

A free and powerful IDE editor launched by Microsoft

DVWA

DVWA

Damn Vulnerable Web App (DVWA) is a PHP/MySQL web application that is very vulnerable. Its main goals are to be an aid for security professionals to test their skills and tools in a legal environment, to help web developers better understand the process of securing web applications, and to help teachers/students teach/learn in a classroom environment Web application security. The goal of DVWA is to practice some of the most common web vulnerabilities through a simple and straightforward interface, with varying degrees of difficulty. Please note that this software

Atom editor mac version download

Atom editor mac version download

The most popular open source editor

Notepad++7.3.1

Notepad++7.3.1

Easy-to-use and free code editor

mPDF

mPDF

mPDF is a PHP library that can generate PDF files from UTF-8 encoded HTML. The original author, Ian Back, wrote mPDF to output PDF files "on the fly" from his website and handle different languages. It is slower than original scripts like HTML2FPDF and produces larger files when using Unicode fonts, but supports CSS styles etc. and has a lot of enhancements. Supports almost all languages, including RTL (Arabic and Hebrew) and CJK (Chinese, Japanese and Korean). Supports nested block-level elements (such as P, DIV),