Home arrow Apache arrow Page 6 - Installing PHP under Windows
APACHE

Installing PHP under Windows


Not a Linux fan? Looking for a hassle-free way of setting up a PHP environment on your Windows box? Read as Matthew guides us through the process of installing Apache, MySQL and PHP on a Windows based machine, otherwise known as WAMP.

Author Info:
By: Matthew Phillips
Rating: 5 stars5 stars5 stars5 stars5 stars / 271
October 22, 2003
TABLE OF CONTENTS:
  1. · Installing PHP under Windows
  2. · What is it?
  3. · Installation - Apache
  4. · Installation Cont'd - MySQL
  5. · Installation Cont'd - PHP
  6. · Testing It All

print this article
SEARCH DEVARTICLES

Installing PHP under Windows - Testing It All
(Page 6 of 6 )

Now to see whether Apache recognises PHP, open notepad and save a file called "test.php" (putting the quotes around the name insures that notepad saves it as test.php, and not test.php.txt.  Notepad sometimes tries to be too helpful!).
 
In this file type the following:

<?php
 echo 'PHP is working.<br>';
 echo phpinfo();
?>

Save this file in your doc root (C:\Program Files\Apache Group\Apache2\htdocs).

Open your web browser and navigate to http://localhost/test.php you should see the line 'PHP is working' and a whole load of info about the current PHP configuration.

Testing Apache, MySQL and PHP Together

Call up a console window (Start > Run > cmd > OK), change to the mysql bin directory (cd c:\mysql\bin) start mysql, logged in as the root user (mysql -u root -p <enter> password)

We are now going to create a (simple) database:

CREATE DATABASE simple;
USE simple;
CREATE TABLE simple_table (
   id INT AUTO_INCREMENT,
   text MEDIUMTEXT,
   PRIMARY KEY (id)
);

Response: OK

Enter: GRANT ALL
Enter: ON simple.*
Enter: TO
testuser@localhost
Enter: IDENTIFIED BY 'testpassword';
Response: OK

Create a new file called "test_insert_mysql.php" and enter the following code into it:

<?php
 // Connect to the database
 $dbhost = 'localhost';
 $dbusername = 'testuser';
 $dbpasswd = 'testpassword';
 $database_name = 'simple';
 $connection = mysql_connect("$dbhost","$dbusername","$dbpasswd")
  or die ('Couldn\'t connect to server.');
 $db = mysql_select_db("$database_name", $connection)
  or die('Couldn\'t select database.');

 // Generate SQL code to store data on database.
 $insert_sql = 'INSERT INTO simple_table (text) VALUES (\'test text, 1,2,3\')';

 // Execute SQL code.
 mysql_query( $insert_sql )
  or die ( 'It Didn\t Work: ' . mysql_error() );

 // Tell User we are done.
 echo 'Code Inserted';
?>

Create a new file called "test_select_mysql.php" and enter the following code into it:

<?php
 // Connect to the database
 $dbhost = 'localhost';
 $dbusername = 'testuser';
 $dbpasswd = 'testpassword';
 $database_name = 'simple';
 $connection = mysql_connect("$dbhost","$dbusername","$dbpasswd")
  or die ('Couldn\'t connect to server.');
 $db = mysql_select_db("$database_name", $connection)
  or die('Couldn\'t select database.');

 // Generate code to retrieve data from database.
 $select_sql = 'SELECT text FROM simple_table';

 // Retrieve code from database.
 $result = mysql_query( $select_sql )
  or die ( 'It Didn\t Work: ' . mysql_error() );

 // Display results to user.
 while ( $row = mysql_fetch_object ( $result ) )
 {
  echo $row->text . <br>;
 }
?>

Browse to http://localhost/test_insert_sql.php, then http://localhost/test_select_sql.php.  Every time you view test_insert_sql.php, it adds a line to the database; viewable from test_select_sql.php. Now, even if you reset you computer the data is still stored in the database.  This example may not be the most thrilling, but hopefully it gives you a small idea of what is possible with WAMP.

If the above scripts all work as planned, then your WAMP environment is set up correctly!  Tune in to the next PHP Tutorial for some actual coding!

Copyright 2003 Matthew Phillips. Permission is granted to copy, distribute and/or modify this document as long as this notice is included. The original version can be found at http://www.phptutorials.cjb.net/ If you make this text available on your website please notify the author, for details of how to notify the author please go to the aforementioned web site and click on the 'Webmasters' link.


DISCLAIMER: The content provided in this article is not warranted or guaranteed by Developer Shed, Inc. The content provided is intended for entertainment and/or educational purposes in order to introduce to the reader key ideas, concepts, and/or product reviews. As such it is incumbent upon the reader to employ real-world tactics for security and implementation of best practices. We are not liable for any negative consequences that may result from implementing any information covered in our articles or tutorials. If this is a hardware review, it is not recommended to open and/or modify your hardware.

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