Recently, many friends have asked me about the installation process of PHP under WindowsXp. Just recently, I successfully installed PHP4.23 on my own machine in a modular way. 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 method. 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 of all, 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.
So, 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 find the latest PHP program code on its official website http: Download it from //www.php.net/downloads.php. Be careful to choose the ZIP package. You cannot choose the self-installation one. 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 future modification Debugging, you can also choose a different directory), you should be able to get A directory similar to "php-4.2.3-Win32", 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 configuration file of PHP. You need to rename it. into "php.ini", and then 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 has not changed it during the installation of PHP, nor has it been done. Any errors, it seems these two 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, and then select the "Home Directory" tab
Click "Configure" button, you will see another tab pop up with the defined document types above. 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:\php\php.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,
e.g. 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:
This time we are using a new version of Apache, Apache2. I remember it was quite troublesome to install PHP under Apache in the past. Now under the Apache2 platform, we PHP can be easily installed in a modular manner, provided that 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 rest assured. input of. 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 texteditor.
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 you browse with the browser.
At this point, your Apache should have the green light on. 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. Okay, Apache has been installed. 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 "extension_dir" and "doc_root". It’s been made very clear above, so I won’t say more.
The next step is 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), you can click "Start->Programs->Apache HTTP Server 2.0.40->Configure Apache Server->Edit the Apache httpd.conf Configuration File"Open.
Or open the Conf directory in your Apache installation directory, you will find a file named http.conf, that's it, you can use any text editor to open it. 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.
Actually, it’s that simple. You just need to add the 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 is Depending on your PHP installation directory, 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 also couldn't start Apache after adding the above sentence. 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's 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 you The 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 way If you follow the step-by-step instructions mentioned above, there should be no major 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.
The above is the detailed content of PHP installation on IIS and Apache2 server under XP_php basics. For more information, please follow other related articles on the PHP Chinese website!