Vous êtes sur la page 1sur 5

How to Install WAMP

AppServ Open Project. Screen shot by J Kyrnin courtesy AppServ

By Jennifer Kyrnin
Web Design & HTML Expert
Definition:
WAMP is an acronym that stands for Windows, Apache, MySQL, and PHP (or Perl or Python).
It is a Web development platform that defines the Operating System (Windows), Web Server
(Apache), database (MySQL), and scripting language (PHP, Perl, or Python).

Choose the Right WAMP Installer


There are a number of different WAMP installers out there you can use to install Apache,
MySQL, and PHP on Windows (WAMP). Some of the better ones are: AppServ, EasyWamp,
PHPDev, PHP Triad, Typo3 WAMP Installer (includes a CMS program), and WampServer. I'm
going to show you how to use AppServ.

How to Install AppServ


1. Download AppServ from SourceForge and double click it to open it.
2. Agree to the license and then choose the directory where you want to install AppServ.
3. I recommend you install all four elements: Apache, MySQL, PHP, and phpMyAdmin.
The only one not required for a testing server is phpMyAdmin, but it's very useful.
4. Because this is being set up as a testing server, use localhost as the server name and
admin@localhost as the administrator's email address. You can leave the port the
default (80).
5. MySQL defaults to a blank root password, but that is very insecure, so give your set up a
secure root password one that you'll remember. Then click Install.
1. AppServ will go through all the steps to install Apache, MySQL, and PHP on your
system.
2. Have AppServ start Apache and MySQL, and then browse to http://localhost/ to see
your new website.

Configure Your WAMP Server


AppServ puts all your web pages into the DocumentRoot this is located in the www subdirectory off of the AppServ directory that you chose. The default is C:/AppServ/www.
I recommend changing this location, so that your testing server is located nearer to your other
web files. To change the location of your server:
1. Open httpd.conf in a text editor. The httpd.conf file will be found in the
AppServ/Apache2.2/conf directory.
2. Search for the word DocumentRoot in that file.
3. Place a hash mark (#) at the front of the line that starts DocumentRoot. This will
comment out this line.
4. Write a new line that reads:
DocumentRoot "Full path to your website directory"

5. Then go down to a line that reads:


<Directory "C:/PROGRA~1/AppServ/www">

and change the path in quotes to your DocumentRoot path.


6. Restart Apache (go to your Start menu, All Programs, AppServ, and choose Apache
Restart in control server by service).
If you want phpMyAdmin running on your server, you'll need to copy the phpMyAdmin folder
from the AppServ/www folder into your new DocumentRoot folder. Login using the root
username and password you defined in setup.

PHP MySQL Tutorial


By Angela Bradley
PHP/MySQL Expert
1 of 5

Connect to MySQL
Updated February 18, 2016.

Interacting with MySQL makes PHP a far more powerful tool. In this tutorial we will go through
some of the most common ways PHP interacts with MySQL. To follow along with what we are
doing, you will need to create a database table by executing this command:
CREATE TABLE friends (name VARCHAR(30), fav_color VARCHAR(30), fav_food
VARCHAR(30), pet VARCHAR(30));
INSERT INTO friends VALUES ( "Rose", "Pink", "Tacos", "Cat" ), ( "Bradley",
"Blue", "Potatoes", "Frog" ), ( "Marie", "Black", "Popcorn", "Dog" ), (
"Ann", "Orange", "Soup", "Cat" )

This will create a table for us to work with, that has friends' names, favorite colors, favorite
foods, and pets.
The first thing we need to do in our PHP file is connect to the database. We do that using this
code:
<?php
// Connects to your Database
mysql_connect("your.hostaddress.com", "username", "password") or
die(mysql_error());
mysql_select_db("Database_Name") or die(mysql_error());
?>

Of course you will replace server, username, password, and Database_Name with the
information relevant to your site. If you are unsure what these values are, contact your hosting
provider.

Retrieve Data
Next we will retrieve the information from the database table we created called "friends"
// Collects data from "friends" table
$data = mysql_query("SELECT * FROM friends")
or die(mysql_error());

And we will then temporally put this information into an array to use:
// puts the "friends" info into the $info array
$info = mysql_fetch_array( $data );

Now let's print out the data to see if it worked:


// Print out the contents of the entry
Print "<b>Name:</b> ".$info['name'] . " ";
Print "<b>Pet:</b> ".$info['pet'] . " <br>";

However this will only give us the first entry in our database. In order to retrieve all the
information, we need to make this a loop. Here is an example:

while($info = mysql_fetch_array( $data ))


{
Print "<b>Name:</b> ".$info['name'] . " ";
Print "<b>Pet:</b> ".$info['pet'] . " <br>";
}

So let's put all the these ideas together to create a nicely formatted table with this final php code:
<?php
// Connects to your Database
mysql_connect("your.hostaddress.com", "username", "password") or
die(mysql_error());
mysql_select_db("Database_Name") or die(mysql_error());
$data = mysql_query("SELECT * FROM friends")
or die(mysql_error());
Print "<table border cellpadding=3>";
while($info = mysql_fetch_array( $data ))
{
Print "<tr>";
Print "<th>Name:</th> <td>".$info['name'] . "</td> ";
Print "<th>Pet:</th> <td>".$info['pet'] . " </td></tr>";
}
Print "</table>";
?>

3 of 5

SQL Queries with PHP


Now that you have done one query, you can do more complicated queries using the same basic
syntax. If you have forgotten the queries, you can review them in the MySQL glossary.
Let's try to do a query of our database for people who have cats for a pet. We will do this by
adding a WHERE clause to set pet equal to Cat.
<?php
// Connects to your Database
mysql_connect("your.hostaddress.com", "username", "password") or
die(mysql_error());
mysql_select_db("Database_Name") or die(mysql_error());
$data = mysql_query("SELECT * FROM friends WHERE pet='Cat'")
or die(mysql_error());
Print "<table border cellpadding=3>";
while($info = mysql_fetch_array( $data ))
{
Print "<tr>";
Print "<th>Name:</th> <td>".$info['name'] . "</td> ";
Print "<th>Color:</th> <td>".$info['fav_color'] . "</td> ";
Print "<th>Food:</th> <td>".$info['fav_food'] . "</td> ";
Print "<th>Pet:</th> <td>".$info['pet'] . " </td></tr>";
}
Print "</table>";

?>

Create Tables
Following this same structure, we can connect to a database and create new tables. At the end we
will print a line, so we know that it is done executing:
<?php
// Connects to your Database
mysql_connect("your.hostaddress.com", "username", "password") or
die(mysql_error());
mysql_select_db("Database_Name") or die(mysql_error());
mysql_query("CREATE TABLE tablename ( name VARCHAR(30),
age INT, car VARCHAR(30))");
Print "Your table has been created"; ?>

I find this method is often used when installing a PHP program someone else has written. Often
an install file includes a way for the user to update the MySQL database from the browser. This
allows people less familiar with the code to install the program more easily.

Insert Into Tables


We can use the same method of using SQL commands to populate our database as we did to
create it. Here is an example:
<?php
// Connects to your Database
mysql_connect("your.hostaddress.com", "username", "password") or
die(mysql_error()); mysql_select_db("Database_Name") or die(mysql_error());
mysql_query("INSERT INTO tablename VALUES ( 'Bill', 29, 'Ford' ), ( 'Mike',
16, 'Beetle' ), ( 'Alisa', 36, 'Van' )");
Print "Your table has been populated"; ?>

Vous aimerez peut-être aussi