On the WIN platform, let your Apache2.0.45 support the PHP-php Tutorial.

Source: Internet
Author: User
Preface if you have no confidence in using Apache. Or you are already using apache2, but you cannot have it work with php (apache cannot parse your. php script ). Don't be afraid. after reading this article, all problems will be solved. I will summarize the steps for how to make Apache and PHP work together. In fact, this is much easier than others have said. I was surprised why no one wrote a question about this before. Preface
If you are not confident in using Apache. Or you are using apache 2, but you cannot make it work with php (apache cannot parse your. php script ). Don't be afraid. after reading this article, all problems will be solved.

I will summarize the steps for how to make Apache and PHP work together. In fact, this is much easier than others have said. I was surprised why no one had written a guide to this issue so that everyone could better understand and use Apache 2.0. Based on my personal interests, I analyzed Apache 2.0. in particular, in order to obtain the latest Apache server, this article uses version 2.0.45.

Now, upgrading servers to Apache 2.0 is much safer than upgrading Microsoft's IIS, and there are a lot of useful tools. In this article, I will show you how to configure your httpd. conf file so that your server can process. php and. phps scripts. Next we will configure apache 2 together. when we request the. php page, the source code or prompt download will not be displayed, but the page we want to see will not be displayed.


Our work includes:

  • Download and install apache 2.0.45
  • Configure the httpd. conf file
  • Run the. php and. phps files in apache2.

This article is intended for Windows 2000/Me/XP users. If you do not have an msi installer, you may need to download and install it from Microsoft. The reason why I want to emphasize the Msi installation program is that this article is for those who first installed Apache 2. If you have installed Apache before, you can directly start the installation. However, pay attention to the steps in this article, especially when you plan to install PHP 4.3.1. Okay. let's get started.


Download apache2

If you have installed apache 1.3, do not uninstall it and stop it first. After installing apache2 and PHP scripts, you can safely uninstall apache1.3. conf file. in this way, you can use it on the new server with only a few changes.

If you have not installed apache or other servers on your machine, go to apache.org to download apache2.0.45 (http://nagoya.apache.org/mirror/httpd/binaries/win32 ). Make sure that the. msi file you downloaded is 5.3M. Run the downloaded. msi file to install apache. Your server will start automatically. If you have a firewall, make sure that the firewall allows access to Apache.

You should pay attention to the apache service monitor (a green light in the taskbar), which indicates that apache is working. Make sure that it is working. just move the mouse arrow to the monitor and it will tell you that it is working. Your taskbar should be similar:

Someone may wonder why "running 1 out of 2 apache services" is displayed, because you may have more than one version of apache working. Most people won't do this, but I do have two apache servers on my machine. My 1.3.27 is stopped, while apache 2 is running. It is my machine:

Note that there is a red light on the monitor of apache1.3.27 and a green light on the monitor of apache2. The first time you install apache, you can only see one, because you have only installed one.

Okay. The Apache server has been basically installed. Now let's download the PHP source code, because we want PHP to work with APACHE, go to php.net to download the latest version of PHP (currently PHP 4.3.2 http://www.php.net/downloads.php ). If you have installed PHP, check whether the php4apache2. dll file exists in the sapi file. If yes, skip the following steps.

We need to download both the php-4.3.2-Win32.zip and the php-4.3.1-installer.exe, and many people have to ask why.
This is to make you lazy, so you don't need to create a folder, you don't need to change the folder name from the php-4.3.1-Win32 to PHP. We first use installer.exe for installation. it will create a PHP folder for you and save more time. Run installer.exe and install PHP according to your preferences. decompress the zip file and find the sapi folder in the compressed package. Copy this folder to the PHP directory you just installed. (For example: C: PHP) then we can delete the php-4.3.2-win32 folder, because now it is no longer needed (a bit of a sense of uninstallation, haha ). Copy php4ts. dll in the PHP folder to your system directory: WINDOWSSystem32 in XP and WINNTsystem32 in 2 K. Next, modify the conf file.

Let Apache parse php pages

Open the httpd. conf file in your text editor. let's add a few lines so that Apache can parse the. php and. phps files. Pay attention to the two parts of the conf file. The first part is the Dynamic Shared Object (DSO) Support list, and the second part is cgi-bin directory.

First, let's find the DSO list as shown below.

# Dynamic Shared Object (DSO) Support
#
# To be able to use the functionality of a module which was built as a DSO you
# Have to place corresponding 'loadmodule' lines at this location so
# Directives contained in it are actually available _ before _ they are used.
# Statically compiled modules (those listed by 'httpd-L') do not need
# To be loaded here.
#
# Example:
# LoadModule foo_module modules/mod_foo.so

There are many more, always find the last line:

# LoadModule ssl_module modules/mod_ssl.so

The preceding row is the last row of the list. press enter to generate an empty row and add the following line to the empty row:

LoadModule php4_module c:/php/sapi/php4apache2. dll

Before closing the conf file, we need to add two more lines. Find the CGI-BIN Directory, to save time, you can look for it like this: press CTRL + F) search In the second Press enter twice to add the following two lines:

AddType application/x-httpd-php. php. phtml. php3. php4
AddType application/x-httpd-php-source. phps

After adding the file, save your conf file and restart your apache server. Advanced users can now test your exciting PHP script. Once it runs successfully, your work is over. For initial installation users, you need to save the php file in your default path: c: PRogram FilesApache GroupApache2htdocs. Create a new text document, add the following code, and save it as date. php.

$ Today = getdate ();
$ Month = $ today [month];
$ Mday = $ today [mday];
$ Year = $ today [year];
Echo "$ month $ mday, $ year ";
?>

Now, test the above code (enter localhost/date. php in the address bar of the browser, and press enter). The current month, date, and year are displayed. If the output is correct, it indicates that PHP has started to work on your server. To satisfy those who want to view the source code, create a text document and add the following code:

$ Browser = getenv ("HTTP_USER_AGENT ");
?>

You are using Web browser.



<? Php echo $ title;?>

Save it as browser. phps and save it as browser. php. After testing the two examples, you will find that the results are different. Browser. php will display your browser version, such:
You are using the Mozilla/4.0 (compatible; MSIE 6.0; Windows 98) web browser.
Browser. phps shows your source code.


Summary

Now, Apache 2.0.45 can process your. php and. phps web pages. We hope everything will run smoothly. Now you have a brand new server. : P

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.