Let your Apache 2.0.45 support PHP on the win platform

Source: Internet
Author: User
Tags date install php net php file php and php script php source code win32
Apache Preface
If you have a lack of confidence in using Apache. Or you're already using Apache 2 but you can't let him work with PHP (Apache can't parse your. php script). Don't be afraid, after reading this article, all the problems will meet the toughness and solution.
I'll summarize how to make Apache and PHP work together. In fact, this is much simpler than what other people say. I'm surprised that no one has written a how-to guide on this before, so that everyone can better understand and use Apache 2.0. With my personal interest, I analyzed Apache 2.0, and in particular, in order to get the latest Apache server, this article is 2.0.45 version.

Now, for anyone who is worried about upgrades, upgrading the server to Apache 2.0 is much more secure than upgrading Microsoft's IIS, and there's a whole bunch of useful tools. In this article, I'll show you how to configure your httpd.conf file to enable your server to handle. PHP and. Phps scripts. Next we're going to configure Apache 2, and when we ask for the. php page, the source code is not displayed or prompted to download without displaying the page we want to see.


The tasks we have to do include:

Download and install Apache 2.0.45
Configuring httpd.conf Files
Make apache2 run. php and. Phps files
This article is for Windows 2000/ME/XP users. WIN95/98 and NT4.0 users who do not have MSI installer may need to download and install it from Microsoft first. The reason I want to emphasize the Msi installer is because this article is for people who first installed Apache 2. If you've installed Apache before, then you can start installing it directly. But you need to be aware of some of the steps in this article, especially if you plan to install PHP 4.3.1. All right, let's get started.


Download apache2

If you already have Apache 1.3 installed, please don't uninstall it and stop it first. After installing the Apache2 and PHP script work, you can safely uninstall apache1.3, uninstall please be sure to take care to back up your httpd.conf file, so that you need to change a few places, you can use it on the new server.

For people who have not installed Apache or installed other servers on the machine, please go to apache.org to download apache2.0.45 (http://nagoya.apache.org/mirror/httpd/binaries/win32/) first. Be sure that the. msi file you downloaded is a 5.3M size. 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) that marks Apache at work. To make sure it's working, just move the mouse arrow to the monitor and it will tell you it's working. Your taskbar should be similar to the following image:



Someone may want to know why the "running 1 out of 2 Apache services" is displayed because you may have more than one version of Apache working. Most people don't do that, but I do have two Apache servers on my machine. My 1.3.27 stopped running, and Apache 2 is running. The following figure is the case for my machine:



Notice that there is a red light on the apache1.3.27 monitor, and there is a green light on the apache2. The first time you install Apache people can only see one, because you only have one.

All right. The Apache server has been basically installed. Now let's download the PHP source code, because we want PHP to work with APACHE to php.net download the latest version of PHP (currently PHP 4.3.2 http://www.php.net/downloads.php). If you have already installed PHP, check to see if there are any php4apache2.dll files under the Sapi file, and if so, you can skip the following steps.

We need to download Php-4.3.2-win32.zip and php-4.3.1-installer.exe two files, and many people have to ask why they want to download them.
This is to make you lazy so that you don't need to create a folder, you don't need to change the folder name from Php-4.3.1-win32 to PHP. We first use Installer.exe to install, it will create PHP folder for you, you can save more time. Run Installer.exe, install PHP according to your preferences, finish, unzip the zip file, and then locate the SAPI folder in the compressed package. Copy the folder to the PHP directory you just installed. (For example: c:php) Then we can delete the Php-4.3.2-win32 folder, because it is no longer needed (a little Shing feeling, haha). Copy the Php4ts.dll in the PHP folder to your system directory: Under XP is WINDOWSSystem32, under 2K is WINNTsystem32. Here we begin to modify the Conf file.



Let Apache parse the PHP page

Open the httpd.conf file with your favorite text editor, and let's add a few lines so that we can parse. php and. phps files in Apache. We need to note the two parts of the Conf file, the first part is the Dynamic Shared Object (DSO) Support list, the second part is Cgi-bin directory

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

# Dynamic Shared Object (DSO) Support
#
# to is able to use the functionality of a module which is built as a DSO you
# have to place corresponding ' LoadModule ' lines in this location so the
# directives contained in it are actually available _before_ they.
# statically compiled modules (those listed by ' httpd-l ') does not need
# to being loaded here.
#
# Example:
# LoadModule Foo_module modules/mod_foo.so

There's still a lot to find, the last line:

#LoadModule Ssl_module modules/mod_ssl.so

The line above is the last line of the list, and a blank line is generated by entering the line:

LoadModule Php4_module C:/php/sapi/php4apache2.dll

We need to add two more lines before we close the Conf file. Find the Cgi-bin directory, in order to save time, you can find this: press Ctrl+f, (Translator Note: If you are in Notepad instead of writing board edit this text, then, you should use the shortcut key F3) to find <directory "C:/apache2/cgi-bin" >, return two times after the second </Directory> to add the following two lines:

AddType application/x-httpd-php. php. phtml php3. PhP4
AddType Application/x-httpd-php-source. Phps

After adding good, save your conf file and restart your Apache server. Advanced users can now test your exciting PHP scripts. Once you run it successfully, your job is over. For the first-time installation, 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 a date.php.

<?php
$today = getdate ();
$month = $today [month];
$mday = $today [Mday];
$year = $today [year];
echo "$month $mday, $year";
?>

Now to test the above code (try typing in the browser's address bar: localhost/date.php, then hit Enter), you should display the current month, date, year. If the output is correct, it means that PHP has already started working on your server. To meet the wishes of those who want to see the source code, you can create a text document and add the following code:

<?php
$browser = getenv ("Http_user_agent");
?>
<p>you are using the <?php echo ($browser);? > Web browser.</p>
<?php $title = "Browser Details";?>
<title><?php echo $title;?></title>

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


Summarize

Now, Apache 2.0.45 should be able to handle your. PHP and. Phps Web pages. I hope everything is running smoothly. Now, you've got a whole 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.