1. Overview:
Between installations, you must first understand the two different modes of PHP installation, one is Cgi mode (CGI executable), and the other is modular installation. This is how the difference can be made:existCGIIn mode,If the client requests aphpdocument,Web服务器就调用去解释这个document,Then return the explanation result to the client as a web page;而exist模块化中,PHPYes withWebThe server is up and running together,So from a certain perspective,byapacheModule installationPHP4Have a comparisonCGI模式更好的安全性by及更好的执行效率和速度。
2. Software preparation:
As the saying goes, "If you want to do something good, you must first sharpen your tools." If you want to run PHP on your machine, you must first prepare the required software.
(I) WEB server
First of all, you need a WEB server to support the operation of PHP. Here we will choose the two most common and most commonly used servers to introduce them separately.
(Internet Infomation Server)
IIS is probably familiar with everyone. In Window 2000, IIS is installed by default. You can open it by "Start -> Settings -> Control Panel -> Administrative Tools -> Internet Information Services". If you don't have it installed, you can install it through "Add and Remove Components" on Windows. There are many introductions on the Internet about IIS installation, so I will not introduce them here.
Apache is also a very excellent web server program, and it is also my favorite web server. It is not only small and flexible, but also very stable during use, and there will be no inexplicable errors (IIS is relatively worse). More importantly, it also supports installing PHP as a module.
Therefore, the author strongly recommends that you use Apache to install PHP. There are two versions of Apache that is commonly used now, one is the 1.36 version and the other is the Apache2 series version. Here you are recommended to use the Apache2 version, and you can download the latest version on Apache's official website.
Apache official website: http://
(II) PHP program
You can download the latest PHP program code on its official website http:///. Please note which ZIP package you want to choose, and you cannot choose which one to install. At the time of writing this article, the latest version of PHP is version 4.23, and the size is 5417KB. Of course, you can also download it in the download column of this site. alright. The software is ready, let’s start our PHP installation journey!
Note: The following installation process is based on PHP4.23 version and Apache2.040.
III. Installation under IIS:
1. Unzip the downloaded PHP installation package to the root directory of your C drive (the C root directory disk is selected here for the convenience of future modification and debugging, and you can also choose a different directory). After decompression, you should get a directory similar to "php-4.2.3-Win32" and change the directory name to "PHP".
2. Open the PHP directory you just unzipped, and you will find a file called "-dist", which is the PHP configuration file. You need to change it to "", and then copy it to the system directory (if your system is installed on C drive, it is "C:\windows" under XP, and it is "C:\winnt" under Windows 2000).
There have been many articles introducing PHP installation files that say that the values of "extension_dir" and "doc_root" should be modified, but the author has not changed them during the installation of PHP, nor has hesitated any errors. It seems that these two parameters are not necessary. Of course, if you are worried, you can also modify it. Change doc_root to the root directory of your server, and change extension_dir to the absolute path where the extensions folder in your PHP installation folder is located.
3. Open your IIS Information Service Console, right-click the "Default Website" icon, select properties, open the default website attribute selection, and then select the "Home Directory" tab
Click the "Configuration" button and you will see another tab popping up with the defined document type. Click the "Add" button, and type in the absolute path you are in in the executable file text box of the dialog box and add "%s %s". Here is "c:\php\ %s %s". Write the suffix name you require to process in the extension text box. Here we write ".php" and follow the default settings for the following options.
4. OK. Now try to save the following sections of code into a suffixed php file, and then put it in one of your virtual directories to access it to see if normal results can occur.
phpinfo();
?>
Maybe 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 that a page will only be
served up if the REDIRECT_STATUS CGI
variable is set,
. via an Apache Action directive.
For more information as to 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 in Cgi mode in IIS, and this item in your php configuration file is not opened. If you see a warning above, you need to open your file and look for the sentence "cgi.force_redirect = 1", remove the semicolon in front of this sentence, and change 1 to 0, and it will be OK. Now refresh the page you just now. If nothing unexpected happens, the result on your screen should be similar to the screenshot below. At this point, the installation process of PHP on IIS has been completed.
4. Installation under Apache:
This time we are using Apache, a brand new version of Apache. I remember that it was quite troublesome to install PHP under Apache. Now, under the Apache2 platform, we can easily install PHP in a modular way, provided that the PHP version must be 4.0 or above.
Of course, there are very few people who are still using PHP3 now. So this time we will only introduce how to install PHP under Apache in a modular way. If you want to know how to load php in Cgi under Apache, you can refer to another article on this website "PHP+Apache installation and configuration under Win9x" (http:///?n=ReadArticle&a=34). Okay, let’s not talk about it, let’s appreciate the style of modular installation of PHP.
1. Run the Apache2 installation file you downloaded and install Apache. During the installation process, you will be prompted to enter the host name, administrator mailbox and other mailboxes. These information can be modified after you have installed, so you can enter it with confidence. When selecting the installation path, the author recommends that you also select the installation path as the root directory of the C drive. After step by step "Next", 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 service manager of Apache2, which is also not available in the version. Pay attention to the status of this picture. If there is a small green triangle, it means that your server has been installed successfully. If it is red, it means that your Apache has not been installed successfully. You need to further find the root cause of the failure.
Generally, the most common mistake is that there is a conflict in ports. The default port of Apache is 80. If your port 80 is occupied by another program (such as IIS), it will not be started. This situation occurs, you can modify it in the following way: Click "Start->Program->Apache HTTP Server 2.0.40->Configure Apache Server->Edit the Apache Configuration File" will open an Apache configuration file, and you can use a text editor to open it.
Then around line 120 of this file, you will find words similar to "Listen 80". Now just change this 80 to the port you want. Of course, don’t forget to add the port when browsing with your browser.
At this point, your Apache should have already lit up the green light. Let's test whether it is working. Open your browser and enter "http://localhost/" in the address bar (if your port is not 80, you need to add ":port number" afterwards). I don't know if you see Apache's welcome page. The author did not see it at this step. I don't know why, the Apache2 version does not seem to have a default boot page. If you don't see it, you can try adding a file name "" to the back. If a similar page appears, it means that Apache is working properly.
2. Okay, Apache has been installed OK, and the next step is to see how to combine it with PHP.
The first two steps are the same as the IIS steps introduced above. They are also decompressed and copied to the root directory of the C drive, then renamed, and then copied to the system folder. If necessary, modify the values of the "extension_dir" and "doc_root". The above has been made very clear, so I won’t say more.
Next is the most important step, which is also the core step of modular installation, but it depends on it carefully.
Open the configuration file of Apache2 (), which can be opened by clicking "Start -> Programs -> Apache HTTP Server 2.0.40 -> Configure Apache Server -> Edit the Apache Configuration File".
Or open the Conf directory under your Apache installation directory, and you will find a file named, which is it. You can use any text editor to open it. Around line 121 of this file, you should be able to find the word "LoadModule", followed by a string of paths. This is the module that Apache wants to load by default. Similarly, we can also add a sentence after it to let it load the PHP module.
In fact, it is that simple. You just need to add the following sentence "LoadModule php4_module C: /php/sapi/". Here we need to explain that "php4_module" is the name of the module, and the path followed by it changes according to your PHP installation directory. These three strings are separated by space characters.
Next, there is another step of work that many friends who fail to install are ignored. At the beginning, the author added the above sentence no matter how it was, Apache couldn't start. Later, after several experiments, I found that the "" in your PHP installation directory must be copied to the system32 directory of the Windows system, otherwise it will not be possible to start.
Now try again, is everything normal? OK, let’s review our installation process under Apache.
(1) Add "LoadModule php4_module C:/php/sapi/".
(2) Copy "" to the system32 directory.
Yes, it's that simple, PHP is already running on your machine. You can see this by double-clicking the Apache server icon in the taskbar.
3. Let’s test it again.
Save the following code as a file and place it in the htdocs directory under your Apache installation directory.
phpinfo();
?>
Then type in http://localhost/ in the browser (if your port is not 80, please add ":port number" after localhost/). Do you see something similar to the one shown in the screen below? If so, congratulations, you have successfully installed PHP in a modular way
Friends who are not familiar with Apache configuration may not understand the things mentioned above, but as long as you follow what I said above, there should be no major problems. If you don't know which part you changed makes Apache unable to start, you can switch to the Conf folder in the Apache installation directory, delete the file, and then change the name of Apache's default configuration file. If you want to know more about Apache configuration.
4. Postscript
Installing PHP is a very simple thing, especially the process of installing PHP in modular form later. If you have time, you might as well try it yourself, so that you can experience the joy of success.
Finally, I wish everyone a smooth installation of PHP.