Free web design training service and resources by the Rochester Web Wizard @ Data Info Magic

Free web design training guide and resources by the Rochester Web Wizard. Sponsored by Data Info Magic.

Lesson 2 : Installing your local server with PHP and MySQL.

I will assume that you will use XAMPP to install the Apache Server with MySQL and PHP. Apache as your local server and phpMyAdmin as your first MySQL editor. There is no cost for any of them. I would also suggest that you download and install DreamCoder for MySQL at this time.

 

Reminder: The download and installation instructions can me found on the Database page. I will limit my discussion here on the sequence and how they work together. Even though this is the most advanced topic, I am putting it in the second lesson so that it will be all set up when we are ready to use it. It will also allow you to start gradually and spiral up to the final phase. It will also give you the big picture earlier in the process. It sounds complicated, but we are mostly just installing software here and implementing the code later.

You will need 5 major free items (3 are in one package: XAMPP) installed to run PHP/MySQL:

1. A local server Apache is included in the package XAMPP,

2. A database language MySQL is included in the package XAMPP and

3. PHP is the language used to access MySQL and is included in XAMPP also.

4. A MySQL editor phpMyAdmin (separate download) and additionally

5. DreamCoder for MySQL (free edition) for easy MySQL editing is suggested.

There are 3 different free downloads. If you install XAMPP, there is no need to download and install separate versions of PHP or MySQL.

 

The 4 items that you must always know when dealing with a database on the local server (Apache installed on your machine) are:

1. Host is localhost

2. User Name is root

3. Password is can be left blank on the local machine so don't enter one initially.

4. Database name is whatever you choose and Table is also. One database may have many tables.

They can be the same on the remote server (The server set up by HostMonster or your current hosting company), except ALWAYS USE A PASSWORD AND SET YOUR USER PERMISSIONS AS STRICTLY AS POSSIBLE!!!!!

This is where I will put in a major plug for HostMonster again. They use the exact same setup as your local machine and make setup and usage free and very easy!!! Other hosting companies charge for both setup and/or monthly access plus their setup and use may be drastically more complicated and much different to what you will become accustomed. Hosting Companies usually offer little or no customer support for MySQL and PHP. You are considered to be on your own at that level.

All links and instructions are included below.

Text only XAMPP and phpMyAdmin installation instructions available...Here

Free Download XAMPP for Windows Free Download phpMyAdmin
PDF XAMPP Windows install instructions PDF phpMyAdmin install instructions

DreamCoder for MySQL free edition: Download the free version here

If you want to try PHP programs right away: Download Rapid PHP Editor Now $39

Rapid PHP 2010 Personal License - $39.85 (Special Offer) For personal non-commercial use by students and other individuals. Install and use the software 1) at home and 2) on a laptop. This will do the job while learning.

If you decide to go professional then you will need to upgrade to Adobe DreamWeaver CS4 for $399 and probably WebAssist SuperSuite for $499 or some other database package. Adobe offers substantiial discounts for students and teachers, but it must be verified.


Xampp

1. Go to the XAMMP link and download the zipped package to your desktop. Unzip the package and follow the instructions to install it. You will end up with the XAMPP control panel, That looks like a white dog bone on an orange background.Install both MySQL and Apache as a service. Click to maximize and start or stop Apache and MySQL. Click the xin the top right corner to minimize.You will also install WinMySQLAdmin 1.4 which looks like a little stoplight in the bottom right border of the screen. Click and Show Me to maximize and right click and Hide Me or minimize. Do not close with the x.

The screenshot below shows the main screen of WinMySQLAdmin. You can select the my.ini.setup to set the properties, but you may also need to manually modify the code in the C:/xampp/phpMyAdmin/config.inc.php on the highlighted lines to match what is in the control panel.

WinMySQLAdmin my.ini.setup tab.

#This File was made using the WinMySQLAdmin 1.4 Tool
#7/31/2008 10:33:29 AM

#Uncomment or Add only the keys that you know how works.
#Read the MySQL Manual for instructions

[mysqld]
basedir=C:/xampp/mysql
#bind-address=192.168.1.3
datadir=C:/xampp/mysql/data
#language=C:/xampp/mysql/share/your language directory
#slow query log#=
#tmpdir#=
#port=3306
#set-variable=key_buffer=16M
[WinMySQLadmin]
Server=C:/xampp/mysql/bin/mysqld-nt.exe
user=root
password=

code in the C:/xampp/phpMyAdmin/config.inc.php

$cfg['Servers'][$i]['host'] = 'localhost'; // MySQL hostname or IP address
$cfg['Servers'][$i]['port'] = ''; // MySQL port - leave blank for default port
$cfg['Servers'][$i]['socket'] = ''; // Path to the socket - leave blank for default socket
$cfg['Servers'][$i]['ssl'] = false; // Use SSL for connecting to MySQL server?
$cfg['Servers'][$i]['connect_type'] = 'tcp'; // How to connect to MySQL server ('tcp' or 'socket')
$cfg['Servers'][$i]['extension'] = 'mysql'; // The php MySQL extension to use ('mysql' or 'mysqli')
$cfg['Servers'][$i]['compress'] = FALSE; // Use compressed protocol for the MySQL connection
// (requires PHP >= 4.3.0)
$cfg['Servers'][$i]['controluser'] = ''; // MySQL control user settings
// (this user must have read-only
$cfg['Servers'][$i]['controlpass'] = ''; // access to the "mysql/user"
// and "mysql/db" tables).
// The controluser is also
// used for all relational
// features (pmadb)
$cfg['Servers'][$i]['auth_type'] = 'config'; // Authentication method (valid choices: config, http, HTTP, signon or cookie)
$cfg['Servers'][$i]['user'] = 'root'; // MySQL user
$cfg['Servers'][$i]['password'] = '"'; // MySQL password (only needed

 

Important Notice!!!

Your MySQL data files will always be located in C:/xampp/mysql/data/

Your PHP files will always be located in C:/xampp/htdocs/

 

winmysqladmin

 

 

2. Download and install phpMyAdmin. Download the zip file. Unzip to c:/xampp/phpmyadmin folder. Follow the setup instructions. The information must be the same as you entered in the steps above for XAMPP.

Reference: For additional information look at O'Reilly p 126 referenced from the database page for complete setup instructions. I purchased the book 40% off of the $29 list price at Barnes and Noble. A used version is fine plus you can purchase elctronic versions cheaper and quicker.

phpmyadmin

 

 

3. Download and install DreamCoder for MySQL. Download the free version here. Use the same information you used to set up phpMyAdmin. You will find the link and information on the database page. You can see the main page and a sample table setup below.

dreamcoder

screenshot

phpMyAdmin and DreamCoder really do the same things. You can learn about them yourself by looking around at the menus until they become familiar to you. You basically need to create MySQL databases and tables and execute MySQL commands. You can start by creating a new database, adding a table with 3 columns: a number, a string (word) and another string. Use int (integer) for the number and varchar (characters) for the strings similar to id, first and last in the table above. Be sure save your database to C:/xampp/mysql/data/

DreamCoder: Make a new database called ijdb. Select Tools/SQL Editor, copy and paste the white code and Run SQL from the first icon just above the window, to run the following script:

/*!40014 SET @OLD_FOREIGN_KEY_CHECKS=@@FOREIGN_KEY_CHECKS, FOREIGN_KEY_CHECKS=0 */;
DROP TABLE IF EXISTS ijdb.joketable;
CREATE TABLE `joketable` (
`id` int(11) NOT NULL auto_increment,
`joketext` text,
`jokedate` date default '0000-00-00',
PRIMARY KEY (`id`)
) ENGINE=MyISAM AUTO_INCREMENT=5 DEFAULT CHARSET=latin1;
/*!40014 SET FOREIGN_KEY_CHECKS=@OLD_FOREIGN_KEY_CHECKS */;

or you can use the columns tab to enter the properties below.

joke columns

Then Use the Schema window to select the database ijdb and the table joketable and the data tab to enter the values in the table below.


ijdb database

DreamCoder: Tools/SQL editor/Choose database to enter MySQL commands. Each command is excuted individually.

USE ijdb;
SELECT joketext FROM joketable;
SELECT joketext, jokedate FROM joketable;
SELECT id,joketext, jokedate FROM joketable;
SELECT * FROM joketable;(shows all data)
DESCRIBE joketable;(shows design properties)
SHOW DATABASES;
SHOW TABLES; (shows tables in that database)
SHOW TABLES FROM addressbook; (shows tables in different database)
SHOW COLUMNS FROM joketable;

 

 

 

You should now be ready to write your first PHP program!

Every section of PHP code starts and ends by turning on and off PHP tags to let the server know that it needs to execute the PHP in between them. Here is an example:

<?php //on

//and

//off ?>

If you haven't purchased RapidPHP yet then you can use notepad or any word processor to type (or copy and paste) the following code (copy is control c and paste is control v):

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">

<html xmlns="http://www.w3.org/1999/xhtml">

<head>
<title>Hello!</title>
</head>

<body>
<! html comment>
<?php
echo "Hello<br/>"; //php comment
echo "World<br/>"; /*php comment*/
?>

</body>

</html>

Save as hello. Change the file extension to .php and save in C:/xampp/htdocs/

To run the code, open your browser (Internet Explorer or FireFox) and type in the address bar:

http:// localhost/hello.php

If it works you will see a message:

Hello
World

That may not seem like a big deal but it is!

More Practice: Here is a link to a pdf document loaded with MySQL commands and screenshots that you can try: MySQLcommands.pdf using DreamCoder. You can also purchase and install RapidPHP where you can execute php code on your local server. Download Rapid PHP Editor Now You can also find plenty of php at Tizag PHP Tutorial and MySQL at Tizag MySQL Tutorial. I personally purchased the PDF versions and found them to be quite a bargain, but you can use them for free on the Tizag.com website also.

Go on to Lesson 3 (Available NOW!)

 
Back to Main Menu