Home arrow Apache arrow Page 2 - Setting Up Apache 2.0.45 to Parse PHP Pages
APACHE

Setting Up Apache 2.0.45 to Parse PHP Pages


To learn how to configure your Apache 2 web server so that .php and .phps files can be used, read this article by William. He'll get you sorted out so you can spend more time developing your PHP apps.

Author Info:
By: William Young
Rating: 4 stars4 stars4 stars4 stars4 stars / 47
April 28, 2003
TABLE OF CONTENTS:
  1. · Setting Up Apache 2.0.45 to Parse PHP Pages
  2. · The Article
  3. · Conclusion

print this article
SEARCH DEVARTICLES

Setting Up Apache 2.0.45 to Parse PHP Pages - The Article
(Page 2 of 3 )

Downloading Apache 2

Now before we begin, if you have apache 1.3 already installed, do not un-install it but instead stop it for this article. Once you have apache 2 and your php scripts working, then you may un-install apache 1.3 but be sure to save your httpd.conf so you can make the necessary changes to your new server.

For those who don't have apache or any other server installed then go to apache's website and download apache 2.0.45. Make sure that you download the .msi file it will be 5.3 Megs in size.
Download Apache 2 Run the Microsoft installer (.msi) configure the server to your liking. Once that's complete, your server will start up on it's on. If you have a firewall running be sure to grant access to apache so it can run.

Next you should notice the apache service monitor with a green light showing indicating that apache2 is running. Itís located in the system tray and to make sure it is running just roll your cursor over the service monitor icon and it will say running, it will look like the image below.

Some of you might be wondering why does it say, running 1 out of 2 apache services, well that's because you may have more than one version of apache on your machine. Most won't but I have two apache servers on my machine. I have 1.3.27 stopped but I have apache 2 running. Look at the image below to see what Iím talking about.

Notice thereís a red light on the first version of apache and notice the green light on apache2; first timers installing apache2 will only see apache2, since you won't have any other apache servers on your machine.

After you've done all of that you'll need the php source code in order for php to work with apache2 so go to
Download PHP download the latest version of php which is 4.3.1. if you already have php installed on your machine then check to see if you have the php4apache2.dll in your sapi folder, if so then you may bypass the steps below.

Download both the php-4.3.1-Win32.zip file along with the php-4.3.1-installer.exe. I know a lot of you are asking why download both?

Well it's to make you lazy, so you don't have go about creating a folder or changing the php-4.3.1-Win32 folder name to php. By using the installer.exe, it will create the php folder for you so you can save more time. Once you have both downloaded, run the installer.exe. Setup php to your liking and after that's complete, unzip the zip file and look for the sapi folder.

Once you see it copy that folder to your php directory. (Ex: C:\PHP) After you've placed the sapi folder under your php directory, then you may delete the php-4.3.1-Win32 folder because we no longer need it. Copy the php4ts.dll from your php folder to your system32 folder WINDOWS\System32 under Xp and WINNT\system32 under Windows 2000. Now let's work on our conf file.

Setting Up Apache 2.0.45 to Parse php Pages

Open your httpd.conf file in your favorite text editor and let's add a few lines to it, so we can parse .php and .phps on our server. We'll need to pay attention to two parts in our conf file, the first part being is the Dynamic Shared Object (DSO) Support list and the second will be the cgi-bin directory.

Letís concentrate on the dso list.

# 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 the
# 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


Scroll all the way down to the end of the modules list,

#LoadModule ssl_module modules/mod_ssl.so


will be at the end of the list. Now press enter to make a new blank line and in that blank space let's add this line

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


Now before we close our conf file we'll need to add two more lines and we'll be set. Letís look for the cgi-bin directory and to save time press (control+f)and we'll get a find word box, copy this and paste it in the space provided <Directory "C:/Apache2/cgi-bin"> and press enter. You will be taken to that line; it will be enclosed in brackets. Now after the second </Directory> tag press enter twice so we can add the following lines


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


Once added, save your conf file and restart your server. Advanced user's you can test your existing php scripts to make sure they work. Once they are working you're finished. Now for the first time installers you'll need to put your saved php files in your default directory which is c:\Program Files\Apache Group\Apache2\htdocs. Open a new text document add this code to it and once you're done save it as date.php.

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

Now test it out it should display the month, date and the year like this And if it shows the month date and year then php is working on your server but now for those who want to display source code pages (.phps) on your server, then you'll need open up a new text document and let's add this in it.

<?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 browser.phps and then save it again as browser.php. Test both out and you'll see the difference between the two. The php version will show you what web browser you're using and the source code (.phps) will show you the complete code.
blog comments powered by Disqus
APACHE ARTICLES

- Programmatically Manipulating Microsoft Exce...
- Installing PHP under Windows
- Compressing Web Content with mod_gzip and mo...
- Compressing Web Output Using mod_deflate and...
- Setting Up Apache 2.0.45 to Parse PHP Pages
- Custom Error 404 Documents with PHP
- Using Apache and PHP on Mac OS X
- ASP: Active Sessions, Active Logins and Tota...
- Working With Oracle on Windows: Part 1
- The Quick-n-Dirty Guide to Setting Up Apache...
- Installing Apache With SSL: The Complete Gui...
- 7 Powerful .htaccess Customization Tips
- Trap And Get Notified: A Practical Solution ...
- One Way To Use Server Side Includes
- Using ForceType For Nicer Page URLs

Watch our Tech Videos 
Dev Articles Forums 
 RSS  Articles
 RSS  Forums
 RSS  All Feeds
Write For Us 
Weekly Newsletter
 
Developer Updates  
Free Website Content 
Contact Us 
Site Map 
Privacy Policy 
Support 

Developer Shed Affiliates

 




© 2003-2017 by Developer Shed. All rights reserved. DS Cluster - Follow our Sitemap
Popular Web Development Topics
All Web Development Tutorials