PHP installs _php Foundation on IIS and APACHE2 servers under XP

Source: Internet
Author: User
Tags apache php phpinfo sapi
Recently, a lot of friends asked me in the WindowsXP under the PHP installation process, just recently I on my own machine successfully in a modular way to install the PHP4.23. Since so many friends need, I will be the most common IIS and Apache server for example, the PHP installation process under the WindowsXP to write it, I hope to be able to install PHP friends a little help. If no special instructions are added, the following descriptions also apply to the Win2000 version.

First, overview:

Between installations, you must first understand the two different modes of PHP installation, one is CGI mode (CGI executable) and the other is the modular installation method. This can be distinguished from the following: in CGI mode, if the client requests a PHP file, The Web server calls Php.exe to interpret the file, and then returns the result of the explanation to the client as a Web page, while in Modularity, PHP is started and run with the Web server, so in some ways the Apache module installs the PHP4 with better security than CGI mode and better Execution efficiency and speed.

Second, software preparation:

The so-called "工欲善其事 its prerequisite", want 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 two of the most common, but also the most used two servers to introduce separately.

1.IIS (Internet infomation Server)

IIS must be familiar to everyone, in Window2000, IIS is installed by default. You can open it by using the Administrative Tools->internet Information Service, Control Panel, start-to-set. If you do not have it installed, you can install it through the Windows Add Remove component. There's a lot of information about the installation of IIS on the Web, which is no longer covered here.

2.Apache

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

Therefore, I strongly recommend that you use Apache to install PHP. Now commonly used Apache has two versions, one is 1.36 version, the other is the version of the Apache2 series, it is recommended that you use the Apache2 version, you can download the latest version of Apache's official website.

Apache Official website: http://www.apache.org

Two PHP Program

The latest PHP program code you can download to its official website http://www.php.net/downloads.php, note to choose the kind of zip package, you can not choose to install the kind, when writing this article, the latest version of PHP is 4.23 version, size is 5417KB. Of course, you can also download in the download section of this site. All right. The software is ready, let's start our PHP installation tour!

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

III. Installation under IIS:

1. Download the downloaded PHP installation package to your C packing directory (here to choose c Root disk is to modify debugging later, you can choose a different directory), decompression should be able to get a similar to the "Php-4.2.3-win32" directory, the directory name to "PHP."

2. Open the PHP directory you just unzipped, you will find 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 is installed in the C-drive, XP is "\ Windows ", under Windows2000 is" C:\winnt ").

There have been many articles about PHP installation files are said to modify the php.ini "Extension_dir" and "Doc_root" the value of the two, but the author in the installation of PHP process has not changed, and no errors, it seems that these two parameters are not required. Of course, if you do not trust can also be modified. Change the doc_root to the root of your server and change the Extension_dir to the absolute path of the Extensions folder in your PHP installation folder.

3. Open your IIS Information Services 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 the "Configure" button and you will see a tab that is already defined for the document type. Click on the "Add" button, in the box in the executable file of the dialog box, click on the absolute path of your php.exe, plus "%s%s", here is "C:\php\php.exe%s%s", in the Extension text box, write the name of the suffix you require the PHP program to process, where we write " . PHP, the options below are set by default.

4. Okay. Now try to save the following snippet of code to a PHP file, and then put it in one of your virtual directories to visit and see if you can get the normal results.


Phpinfo ();

?>

Perhaps you will encounter the following output:


Security alert! The PHP CGI

cannot be accessed directly.

This PHP CGI binary was compiled

With Force-cgi-redirect enabled.

This means a page would only be

Served up if the Redirect_status CGI

variable is set,

E.g via an Apache Action directive.

For more information as-why

This behaviour exists,

See 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 be afraid, this is because PHP is now running CGI in IIS, and this item in your PHP configuration file is not open. If you see a warning above, you need to open your php.ini file, and then find "Cgi.force_redirect = 1" Such a sentence, the first semicolon to remove the sentence, and then change 1 to 0 OK, and now to refresh the page you just, if there is nothing unexpected , the results on your screen should be the same as the screenshot below me. The installation process for PHP on IIS is complete.

IV. installation under Apache:

We are using a new version of Apache Apache2, previously installed in Apache PHP Remember also more trouble, now in the Apache2 platform, we can easily in a modular way to install PHP, if the PHP version must be more than 4.0.

Of course, it is very rare to use PHP3 now. So this time we only show how to install PHP in a modular way under Apache, if you want to know how to load PHP in the CGI way under Apache, you can refer to another article on this site "Php+apache under Win9x Installation and Configuration" (HTTP/ WWW.HOODAY.COM/?N=READARTICLE&A=34). Well, gossip less, let's take a taste of 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, the information after you installed is can be modified, so you can rest assured that the input. When choosing the installation path, I recommend that you also select the installation path as the root of the C drive. After the "Next" step, you will 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 also the apache1.x version does not have. Note the status of this picture, if there is a small green triangle, indicating that your server has been installed successfully, if it is red, then your Apache is not installed successfully, you need to find out the root of the failure.

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

Then in the 120th line of the file, you will find something similar to the word "Listen 80". Now just change this 80 to the port you want, of course, when you browse with a browser, do not forget to add the port Oh.

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

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

The first two steps and the IIS steps described above are the same, but also copied to the C packing directory after decompression, 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. The above has been said very clearly, no longer say.

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

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

or open your Apache installation directory under the Conf directory, you will find a file named http.conf, it is, you can use any text editor to open it. In the 121th line of the file, you should be able to find the word "LoadModule", followed by a string of paths, this is the default Apache to load the module, similarly, we can also add a sentence later, let him load the PHP module.

In fact, it is so simple, you just add such a sentence "LoadModule php4_module C:/php/sapi/php4apache2.dll", here to explain the "Php4_module" is the name of the module, The path followed is changed with your PHP installation directory, and the three strings are separated by a space character.

Next, there is a step of work, but also many failed to install the friends ignored, just beginning the author is anyway added to the top of the sentence after the Apache will not start up. After several experiments, it was found that the "Php4ts.dll" in your PHP installation directory must be copied to the System32 directory of the Windows system, otherwise it would not be possible to start up.

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

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

(2) Copy the "Php4ts.dll" to the System32 directory.

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

3. Test it again.

Save the following code as a info.php file under the Htdocs directory in 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/), is not seen similar to the screen shown below. If yes, congratulations, you have successfully installed PHP in a modular way

The above mentioned in the Apache section of the things that are not familiar with the Apache configuration of friends may be a bit less clear, but as long as you follow the steps I said above, there should be no big problem. If you do not know which part of the changes you have made Apache boot up, you can switch to the Apache installation directory of the Conf folder, Remove the http.conf file and rename the Apache default profile httpd.default.conf to http.conf. If you want to know more about Apache's configuration.

Iv. PostScript

The installation of PHP is a simple thing, especially the process of module-based PHP installation. You may have time to try it yourself, so that you can experience the joy of success.

Finally, I wish everyone will be able to install PHP smoothly.

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