A Free Trial That Lets You Build Big!
Start building with 50+ products and up to 12 months usage for Elastic Compute Service
During installation, you must first understand two different PHP installation modes: Cgi executable and modular installation. In the cgimode, if the client requests a php file, the webserver calls php.exe to explain the file, and then returns the result to the client in the form of a webpage. in modularization, PHP is started and run together with the Web server. from a certain point of view, the PHP4 installed in the apache module has better security and execution efficiency and speed than the CGI mode.
2. software preparation:
The saying goes, "you must first sharpen your tools to do something better." to run PHP on your machine, you must first prepare the required software.
(1) WEB servers
First, you need a WEB server to support the running of PHP. here we will introduce the two most common and used servers.
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 service. If you have not installed it, you can install it through "add and delete components" in Windows. There are many introductions on IIS installation.
Apache is also a very good Web server program, and it is also my favorite Web server. It is not only small, flexible, but also very stable in the use process, there will be no inexplicable errors (IIS is relatively much worse), and more importantly, it also supports installing PHP into a module.
Therefore, I strongly recommend that you use Apache to install PHP. Apache has two common versions: version 1.36 and version 2. we recommend that you use Apache2, you can download the latest version from the official Apache website.
Apache official website: http://www.apache.org
(2) PHP program
The latest PHP code can be found on its official website. Of course, you can also download it from the download section on this site. Okay. The software is ready. let's start our PHP installation journey!
Note: The following installation processes are subject to PHP4.23 and Apache2.040.
III. IIS installation:
1. decompress the downloaded PHP installation package to the root directory of your C drive (select the C root directory disk for later debugging convenience, you can also select a different directory ), after decompression, you should be able to get a directory similar to "php-4.2.3-Win32", change the directory name to "PHP ".
2. open the decompressed PHP directory and you will find a directory named "php. ini-dist file. this is the PHP configuration file. you need to rename it to "php. ini ", and then copy it to the system directory (if your system is attached to drive C, it is" C: windows "under XP, and" C: winnt "under Windows2000 ").
In the past, many articles about PHP installation files mentioned that php should be modified. in ini, the values of "extension_dir" and "doc_root" have not been changed and no errors have been made during PHP installation. it seems that these two parameters are not necessary. Of course, you can modify it if you are not at ease. Change doc_root to the root directory of your server, and change 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 website" icon, select Properties, open the default website attribute selection, and then select the "main directory" tab
Click the "configure" button, and you will see a new tab, which is a defined document type. Click "add" to add "% s" to the absolute path of your php.exe in the executable file box of the dialog box. here is "c: php \ php.exe % s ", in the extension text box, write the suffix you want the php program to process. here we write ". php ", the following options can be set by default.
4. all right. Now, try to save the following code into a php file with the suffix, and put it in your virtual directory for access to see if the result is normal.
You may 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 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 worry, this is because PHP is running in IIS in Cgi mode, and this item is not opened in your php configuration file. If you see the above warning, you need to open your php. ini file, and then find "cgi. force_redirect = 1 ", remove the semicolon in front of this sentence, and change 1 to 0. now, refresh your page, if there is no accident, 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. install Apache:
We used a brand new version of Apache Apache2 this time. it was still troublesome to install PHP in Apache before. now, on the Apache2 platform, we can easily install PHP in a modular way, the premise is that the PHP version must be later than 4.0.
Of course, PHP3 is rarely used now. So this time we will only introduce how to install PHP in Apache in a modular way. if you want to know how to load php in Cgi mode in Apache, can refer to another article on this site "PHP + Apache in Win9x installation and configuration" (http://www.hooday.com /? N = ReadArticle & a = 34 ). Let's take a look at the modular installation of PHP.
1. run the downloaded Apache2 installation file to install Apache. during the installation process, you will be prompted to enter the host name, administrator mailbox, and other mailboxes. The information can be modified after installation, therefore, you can rest assured that the input. When selecting the installation path, I suggest you select the installation path as the root directory of drive C. After "Next" step by step, you will find that Apache is easily installed.
Now let's 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 Apache1.X. Note the status of this image. if there is a green triangle, it indicates that your server has been installed successfully. if it is red, it indicates that your Apache has not been installed successfully, you need to further find the root cause of failure.
The most common error is Port conflict. Apache uses port 80 by default. if your port 80 is occupied by another program (such as IIS, the instance cannot be started. In this case, you can click Start> Program> Apache HTTP Server 2.0.40> Configure Apache Server> Edit the Apache httpd. conf Configuration File "opens an Apache Configuration File, which can be opened in a text editor.
Then you will find the words similar to "Listen 80" in around 120th lines of this file. Now, you only need to change the port 80 to the port you want. of course, you should not forget to add the port when browsing in the browser.
Here, your Apache should have a 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, add ": port number" next to it "), I don't know if you have seen the Apache welcome page. I didn't see it in this step. I don't know why. Apache2 does not seem to have a default boot page. If you do not see it, try adding the file name "index.html. en" to the end. if the following page appears, it means that Apache is working properly.
2. now that Apache has been installed, you can see how to integrate it with PHP.
The first two steps are the same as the IIS steps described above. They are also extracted, copied to the C root directory, renamed, and PHP. copy ini to the system folder. if necessary, modify the values of "extension_dir" and "doc_root. I have already made it very clear. I will not talk about it more.
The next step is the most important step, which is also the core step of modular installation. you should check carefully.
Open the configuration file (http. conf), you can click "Start-> Program-> Apache HTTP Server 2.0.40-> Configure Apache Server-> Edit the Apache httpd. conf Configuration File "open.
Or open the Conf directory under your Apache installation directory and you will find a file named http. conf, which can be opened in any text editor. In about 121st lines of this file, you should be able to find the "LoadModule" text, followed by a string of paths. this is the module to be loaded by Apache by default. Similarly, we can also add a sentence after it to let him load the PHP module.
In fact, it is so simple. you just need to add the following 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 following path is changed with your PHP installation directory. these three strings are separated by space characters.
Next, there is another step, which is ignored by many installation failures. at the beginning, the author did not start Apache after adding the above sentence. After several experiments, we found that the "php4ts. dll" under your PHP installation directory must be copied to the system32 directory of the windows system. Otherwise, it cannot be started.
Now, try again to see if everything is normal. Now let's review the installation process in 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 view this by double-clicking the Apache server icon in the taskbar.
3. try again.
Save the following code as the info. php file and place it in the htdocs directory under your Apache installation directory.
Then, enter http: // localhost/info in the browser. php (if your port is not 80, add ": port number" after localhost/). Is it displayed on a screen similar to the following. If yes, congratulations, you have successfully installed PHP in modular mode
The above content in the Apache section may not be quite clear to friends who are not familiar with Apache configuration. However, as long as you follow the steps mentioned above, there should be no major problems. If you do not know which part you want to change makes Apache unable to start, you can switch to the Conf folder under the Apache installation directory and. delete the conf file, and then delete the default Apache configuration file httpd. default. change conf to http. conf. If you want to learn more about Apache configuration.
PHP installation is a simple task, especially the modular installation of PHP later. If you have time, try it on your own so that you can experience the joy of success.
Finally, I wish you a smooth installation of PHP.
Start building with 50+ products and up to 12 months usage for Elastic Compute Service