Recently, many friends have asked me about the installation process of PHP under Windows Xp. Just recently, I successfully installed PHP4.23 in a modular manner on my own machine. Since so many friends need it, I will take the most common IIS and Apache servers as examples and write down the installation process of PHP under Windows XP. I hope it will be helpful to friends who want to install PHP. Unless otherwise specified, the following introduction also applies to the Win2000 version.
1. Overview:
Before installation, you must first understand the two different modes of PHP installation, one is Cgi mode (CGI executable), and the other is modular installation. It can be distinguished this way: 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 interpretation to the client in the form of a web page; in modularization , PHP starts and runs together with the web server, so from a certain perspective, PHP4 installed in the apache module mode has better security and better execution efficiency and speed than the CGI mode.
2. Software preparation:
As the saying goes, "If you want to do your job well, you must first sharpen your tools." If you want to run PHP on your machine, you must first prepare the required software.
(1) WEB server
First, you need a WEB server to support the operation of PHP. Here we choose the two most common and most commonly used servers to introduce them respectively.
1.IIS (Internet Infomation Server)
IIS must be familiar to everyone. In Window2000, IIS is installed by default. You can open it through "Start->Settings->Control Panel->Administrative Tools->Internet Information Services". If you don't have it installed, you can install it through Windows' "Add and Remove Components". There are many online introductions to the installation of IIS, so I won’t introduce them here.
2.
Apache 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 will not cause some inexplicable errors (IIS is much worse). More importantly, it also supports the installation of PHP as one of its modules.
Therefore, the author strongly recommends that you use Apache to install PHP. There are two versions of Apache commonly used today, one is version 1.36, and the other is the version of the Apache2 series. It is recommended that you use the Apache2 version. You can download the latest version from the official website of Apache.
Apache official website: http://www.apache.org
(2) PHP program
You can download the latest PHP program code from its official website http://www.php.net/downloads.php. Be careful to choose which one. For ZIP packages, you cannot choose self-installation. 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 section 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.
3. Installation under IIS:
1. Unzip the downloaded PHP installation package to the root directory of your C drive (the C root directory is chosen here for the convenience of later modification and debugging. You can also choose a different directory). After decompression, you should get a file similar to "php- 4.2.3-Win32" directory, change the directory name to "PHP".
2. Open the PHP directory you just decompressed. You will find a file called "php.ini-dist". This is the PHP configuration file. You need to rename it to "php.ini" and copy it to the system directory. (If your system is installed on the C drive, it is "C:windows" under XP and "C:winnt" under Windows 2000).
In the past, many articles introducing PHP installation files said that the values of "extension_dir" and "doc_root" in php.ini should be modified, but the author did not change it during the installation of PHP, nor did I make any errors. It seems that this Both parameters are not required. Of course, you can modify it if you are worried. Change doc_root to the root directory of your server and extension_dir to the absolute path to the extensions folder in your PHP installation folder.
3. Open your IIS information service console, right-click the "Default Website" icon, select Properties, open the default website property selection, then select the "Home Directory" tab
and click the "Configure" button, you will see another pop-up tab, above which are the defined document types. Click the "Add" button, and in the executable file text box of the dialog box that appears, type the absolute path where your php.exe is located plus "%s %s", here it is "c:phpphp.exe" %s %s", in the extension text box, write the suffix you want the php program to process. Here we write ".php", and the following options can be set by default.
4.Okay. Now try to save the following pieces of code as a file with the suffix php, 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,
eg via an Apache Action directive.
For more information as to why
this behavior exists,
see the manual page for CGI security.
For more information about changing
this behavior 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 is not turned on in your php configuration file. If you see the warning above, you need to open your php.ini file, then look for the sentence "cgi.force_redirect = 1", remove the semicolon in front of this sentence, and then change 1 to 0. Now refresh the page you just created. If there are no surprises, the results 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:
What we are using this time is Apache2, a brand new version of Apache. I remember that it was more troublesome to install PHP under Apache in the past. Now under the Apache2 platform, we can easily install PHP in a modular way. The prerequisite The PHP version must be 4.0 or above.
Of course, there are very few people still using PHP3. So this time we only introduce how to install PHP under Apache in a modular way. If you want to know how to load PHP in Cgi mode under Apache, you can refer to another article on this site "PHP+Apache under Win9x" Installation and Configuration" (http://www.hoday.com/?n=ReadArticle&a=34). Okay, without further ado, let’s appreciate the elegance of modular installation of PHP.
1. Run the Apache2 installation file you downloaded to install Apache. During the installation process, you will be prompted to enter the host name, administrator mailbox and other mailboxes. This information can be modified after you install it, 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 "Next" step by step, you will find that Apache is easily installed.
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 not available in the Apache1.X version. Pay attention to the status of this picture. If there is a 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 source of the failure.
The most common error is port conflict. The default port of Apache is 80. If your port 80 is occupied by another program (such as IIS), it will not start. If this happens, you can modify it as follows: Click "Start->Programs->Apache HTTP Server 2.0.40->Configure Apache Server->Edit the Apache httpd.conf Configuration File" to open an Apache configuration. file, you can open it with a text editor.
Then around line 120 of this file you'll find something like "Listen 80". Now just change this 80 to the port you want. Of course, don’t forget to add the port when you browse with the browser.
At this point, your Apache should have the green light, now 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" after it). I don't know if you have seen the Apache welcome page. The author did not see this step. For some reason, 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 "index.html.en" at the end. If a page similar to the one below appears, it means Apache is working normally.
2. Ok, Apache has been installed OK, 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 "extension_dir" and The value of these two items "doc_root". It’s been made very clear above, so I won’t say more.
Next comes the most important step, which is also the core step of modular installation, but you need to watch it carefully.
Open the Apache2 configuration file (http.conf) by clicking "Start->Programs->Apache HTTP Server 2.0.40->Configure Apache Server->Edit the Apache httpd.conf Configuration File".
Or open your Apache In the Conf directory under the installation directory, you will find a file named http.conf. That's it. You can open it with any text editor. Around line 121 of this file, you should be able to find the words "LoadModule", followed by a string of paths. This is the module that Apache loads by default. Similarly, we can also add a sentence after it to let him do it. Load the PHP module.
In fact, it's that simple, you just need to add this sentence "LoadModule php4_module C:/php/sapi/php4apache2.dll". Here we need to explain that "php4_module" is the name of the module, and the path that follows follows your PHP installation directory. However, these three strings are separated by spaces.
Next, there is another step, which is also ignored by many friends who failed to install. At the beginning, the author couldn't start Apache after adding the above sentence no matter what. Later, after several experiments, I discovered that "php4ts.dll" in your PHP installation directory must be copied to the system32 directory of the Windows system, otherwise, it will be impossible to start.
Try again now to see if everything is normal. Okay, let's review our installation process under Apache.
(1) Add "LoadModule php4_module C:/php/sapi/php4apache2.dll".
(2) Copy "php4ts.dll" to the system32 directory.
Yes, it is that simple, PHP is already running on your machine. You can see this by double-clicking the Apache server icon on the taskbar.
3. Let’s test it again.
Save the following code as an info.php file and place it 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/), do you see a screen similar to the one below? If so, congratulations, you have successfully installed PHP in a modular manner.
The things described above in the Apache part may be a bit unclear to friends who are not familiar with Apache configuration, but as long as you follow the step-by-step instructions I mentioned above Come on, there shouldn't be any big problems. If you don't know which part you changed that prevents Apache from starting, you can switch to the Conf folder in the Apache installation directory, delete the http.conf file, and then change Apache's default configuration file httpd.default. Just rename conf to http.conf. If you want to know more about Apache configuration.
4. Postscript
The installation of PHP is originally a very simple matter, especially the process of installing PHP in a modular manner as discussed 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.