PHP4.23 installation instances on IIS and Apache2 two servers under Windows XP

Source: Internet
Author: User
Tags install php iis ini php file php code phpinfo port number root directory
apache|iis|window| Server recently, the forum has many friends asked me in Windows XP under the installation process of PHP, just recently I successfully on my own machine in a modular way to install the PHP4.23. 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. You can differentiate: in CGI mode, if a client requests a PHP file, the Web server calls Php.exe to interpret the file, and then returns the result to the client as a Web page, and in Modularity, PHP starts and runs with the Web server. So in a way, the PHP4 installed in the Apache module has better security than the CGI model 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.

2.Apache
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 commonly used 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 on the official Apache website of the latest version, you can also in the site (http:// Download the download section of Www.phpe.net to the author's version (Apache2.040) used to write this article.
Apache Official website: http://www.apache.org

Two PHP Program

The latest PHP code you can download on its official website http://www.php.net/downloads.php, 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 5,417kb. Of course, you can also download the site in the download section.

All right. The software is ready, so let's start our PHP installation Tour here:
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, as shown in the following illustration:




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 your Php.exe's absolute path plus "%s%s", here is "C:phpphp.exe%s", and in the Extension text box write the suffix name you requested in the PHP program, where we write ". PHP, the following options are set by default. The following figure:




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.
<?php
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 means that a page would be served up if the Redirect_status CGI variable are set, e.g. via an Apache Action direct Ive.

For more information as to why this behaviour exists, and 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. Notice that I use a red line in the diagram to indicate that PHP is running in CGI mode. (Click to enlarge)





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.PHPE.NET/?N=READARTICLE&AMP;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 "AddType application/x-httpd-php. php".
(2) Add "LoadModule php4_module c:/php/sapi/php4apache2.dll".
(3) 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. The following figure is the comparison between loading PHP modules and not loading PHP modules:



3. Let's test it again.
Save the following code as a info.php file in the Htdocs directory under your Apache installation directory.
<?php
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 so, congratulations, you have successfully installed PHP in a modular manner, and note that the following figure shows the difference between the screenshots that were installed in the CGI module under IIS.




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 know more about Apache configuration, you can refer to another article of this site "Apache Server Configuration" (http://www.phpe.net/?n=ReadArticle&a=94).

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. :P

Remember: A lot of friends read this article after all said that the above method can not install the correct PHP, this reason is due to the PHP version of the reason, please go to the download section download tested can be modular installation of the PHP installation package. If you have any questions, please come to the online forum.



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: info-contact@alibabacloud.com 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.