PHP installation _php base on IIS and APACHE2 servers under XP

Source: Internet
Author: User
Tags install php iis php code phpinfo sapi port number
Recently, a lot of friends asked me about the installation process of PHP under Windows XP, just recently I successfully installed the PHP4.23 in a modular manner on my own machine. Since so many friends need it, I'll take the most common IIS and Apache servers for example, write the PHP installation process under Windows XP, hoping to help a friend to install PHP. Without special instructions, the following introduction also applies to the Win2000 version.

First, overview:

Between installations, you must first understand the two different modes of PHP installation, one is the CGI mode (CGI executable), and the other is modular installation. This can be distinguished by: in CGI mode, if the client requests a PHP file, The Web server calls Php.exe to interpret the file, the results are then returned to the client in the form of a Web page, and in Modularity, PHP is started and run with the Web server, so in a way, the PHP4 installed in the Apache module has better security than the CGI mode and better Execution efficiency and speed.

Second, the SOFTWARE preparation:

The so-called "工欲善其事 its prerequisite", in order to run PHP on your machine must first prepare the required software.

A Web server

First you need a Web server to support the operation of PHP, here we choose the two most common, but also use the most of the two servers to introduce separately.

1.IIS (Internet infomation Server)

IIS presumably everyone is not unfamiliar with it, in Window2000, IIS is installed by default. You can open it by "Start-> settings-> Control Panel-> admin tools->internet Information Service." If you are not installed, you can install it by using the Windows Add Remove component. There are a lot of introductions about IIS installed on the Web, and this is no longer introduced here.


Apache is also a very good Web server program, and it is also the author's favorite Web server. It's not only small, flexible, but also very stable in use, without some inexplicable errors (IIS is relatively poor), and more importantly, it supports the installation of PHP into one of its modules.

Therefore, I strongly recommend you use Apache to install PHP. Now the common Apache has two versions, one is 1.36, the other is the Apache2 series version, where you are recommended to use the Apache2 version, you can download the latest version on the official Apache website.

Apache Official website:

Two PHP Program

The latest PHP code you can download on its official website, note to choose that kind of zip package, can not choose to install the kind, in writing this, the latest version of PHP is 4.23 version, the size is 5417KB. Of course, you can also download the site in the download section. All right. The software is ready, the following is the start of our PHP installation Tour bar!

Note: The following installation process is based on the PHP4.23 version, Apache2.040.

Third, install under IIS:

1. Download the downloaded PHP installation package to your C-packing directory (this is the choice of the C root directory disk is for later modification and debugging convenient to use, you can also choose a different directory, after decompression should be able to get a similar "Php-4.2.3-win32" directory, the directory name changed to "PHP."

2. Open just decompression of the PHP directory, you will find that there is a file called "Php.ini-dist", this is the PHP configuration file, you need to rename it to "PHP.ini", and then copied to the system directory (if your system installed in the C disk, XP is "C:\ Windows ", Windows2000 is" C:\winnt ").

A lot of previous articles about PHP installation files said to modify the php.ini "Extension_dir" and "doc_root" values, but the author in the installation of PHP has not changed, nor any errors, it seems that these two parameters are not necessary. Of course, if you do not trust can also be modified. Change the doc_root to your server's root directory, and change the extension_dir to the absolute path of the Extensions folder in your PHP installation folder.

3. Open your IIS Information Service console, right-click the "Default Web Site" icon, select Properties, open the Default Web site properties selection, and then select the Home Directory tab

Click on the "Configure" button and you will see another tab out of the document type you have defined. Click the "Add" button, in the Executable text box of the Out dialog box, tap the absolute path of your php.exe, plus "%s%s", here is "C:\php\php.exe%s", and the Extension text box writes the suffix name you requested in the PHP program, where we write " . PHP, the following options are set by default.

4. Ok. Now try to save the following sections of code as a PHP file, and then put it into one of your virtual directories to visit to see if there are any normal results.

Phpinfo ();


Perhaps you will encounter the following output results:

Security alert! The PHP CGI

cannot be accessed directly.

This PHP CGI binary is compiled

With Force-cgi-redirect enabled.

This is means that a page would be

Served up if the Redirect_status CGI

variable is set,

e.g. via an Apache Action directive.

For more information as to why

This behaviour exists,

The manual page for CGI security.

For more information about changing

This behaviour or re-enabling this webserver,

Consult the installation file that

Came with this distribution,

or visit the manual page.

Don't worry, this is because PHP is now running in CGI in IIS, and your PHP configuration file does not open this one. If you see a warning above, you need to open your php.ini file, and then look for "Cgi.force_redirect = 1" Such a sentence, this sentence before the semicolon removed, and then the 1 to 0 on the OK, and now to refresh your just the page, if there is no accident , the result on your screen should be similar to my screenshot below. To this end, the installation of PHP on IIS is complete.

Four, under the Apache installation:

This time we are using a new version of Apache Apache2, the previous installation of PHP under the Apache memory is still more trouble, now in the Apache2 platform, we can easily modular way to install PHP, if the PHP version must be more than 4.0.

Of course, it's very rare to use PHP3 now. So this time we only introduce how to modular in the way to install PHP under Apache, if you want to know how to use CGI in Apache loading PHP, you can refer to another article of this site "Php+apache in Win9x Installation and configuration" (http:// WWW.HOODAY.COM/?N=READARTICLE&A=34). Well, less gossip, let's enjoy the modular installation of PHP style bar.

1. Run your downloaded Apache2 installation files, install Apache, the installation process will prompt you to enter the host name, administrator mailbox, such as mailbox, this information after you install can be modified, so can be assured of input. When choosing the installation path, the author recommends that you also select the installation path as the root of the C disk. After a step-by-step "next", you'll find that Apache is easy to install.

Now look at the right side of your taskbar, there should be an icon similar to this small icon, this is the Apache2 Service Manager, is not the apache1.x version. Note that the state of this picture, if there is a small green triangle, indicating that your server has been installed successfully, if it is red, your Apache is not installed successfully, you need to go further to find the root cause of failure.

The most common error is the port is conflicting, the Apache default port is 80, if your 80 port is occupied by another program (such as IIS), you will be unable to start the situation. In this case, you can modify the following methods: Click "Start-> program->apache HTTP Server 2.0.40->configure Apache Server->edit the Apache httpd.conf Configuration file will open an Apache profile, which you can open with a text editor.

Then in the 120th line of the file, you'll find the words "Listen 80". Now just change the 80 to the port you want, but don't forget to add the port when browsing in your browser.

Here, your Apache should have lit the green light, let's test whether it is working. Open your browser, enter "http://localhost/" on the Address bar (if your port is not 80, you need to add ": Port number"), do not know whether you see the Apache Welcome page, the author in this step did not see, do not know what the reason, The Apache2 version does not appear to have a default boot page. If you don't see it, try adding a filename "index.html.en" in the back, and if you can get a page like this, Apache is working properly.

2. OK, Apache has installed OK, next is to see how to combine with PHP.

The first two steps and the IIS steps described above are the same, is also extracted after the copy to C packing directory, and then renamed, and then copy the php.ini to the System folder, if necessary, modify the "Extension_dir" and "Doc_root" the value of the two items. The above has been made very clear, not to say more.

Then is the most important step, but also a modular installation of the core steps, but to look carefully.

Open the Apache2 configuration file (http.conf) by clicking "Start-> program->apache http Server 2.0.40->configure Apache server->edit" Apache httpd.conf Configuration File "opens.

or open the Conf directory under your Apache installation directory, and you'll find a file called http.conf, which you can open with any text editor. In the 121th line of this file, you should be able to find the word "LoadModule", followed by a string of paths, which is the Apache default to load the module, again, we can add a sentence, let him to load the PHP module.

In fact, it is so simple, you just add such a phrase "LoadModule php4_module c:/php/sapi/php4apache2.dll", here to explain "Php4_module" is the name of the module, The following path changes with your PHP installation directory, which is separated by spaces between the three strings.

Next, there is a step-by-step work, but also a lot of failed to install the friend ignored, just start the author is anyway to join the top of the sentence after the Apache will not start up. Then after several experiments, only to find that your PHP installation directory under the "Php4ts.dll" must be copied to the Windows system system32 directory, otherwise, it will not be able to start up.

Now try again, is everything OK. OK, let's review the process we installed under Apache.

(1) Add "LoadModule php4_module c:/php/sapi/php4apache2.dll".

(2) Copy "Php4ts.dll" to system32 directory.

Yes, it's that simple, PHP is already running on your machine. You can see this by double-clicking the taskbar's Apache server icon.

3. Let's test it again.

Save the following code as a info.php file in the Htdocs directory under your Apache installation directory.

Phpinfo ();


Then type http://localhost/info.php in the browser (if your port is not 80, please add ": Port number" after localhost/), see the screen like the one shown below. If yes, congratulations, you have successfully installed PHP in a modular way.

The above in the Apache part of the things that are not familiar with the Apache configuration of friends may not understand a little bit, but as long as you follow the steps I mentioned above, there should be no big trouble. If you don't know which part of your change makes Apache start up, you can switch to the Conf folder in the Apache installation directory, Delete the http.conf file, and then rename the Apache default profile httpd.default.conf to http.conf. If you want to learn more about Apache's configuration.

Four, PostScript

The installation of PHP is a very simple thing, especially after the process of installing PHP in a modular way. If you have time, you may try it yourself, so that you can experience the joy of success.

Finally, I wish you all a smooth installation of PHP.

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.