48
1 Session 1: Introduction to PHP & MySQL iNET Academy Open Source Web Development

1 Session 1: Introduction to PHP & MySQL iNET Academy Open Source Web Development

Embed Size (px)

Citation preview

Page 1: 1 Session 1: Introduction to PHP & MySQL iNET Academy Open Source Web Development

1

Session 1: Introduction to PHP & MySQL

iNET Academy

Open Source Web Development

Page 2: 1 Session 1: Introduction to PHP & MySQL iNET Academy Open Source Web Development

2

Objectives

PHP & MySQL in web development Components of PHP applications Installation & Configurations of Apache,

MySQL and PHP Open source tools

Page 3: 1 Session 1: Introduction to PHP & MySQL iNET Academy Open Source Web Development

3

World Wide Web Web pages

Created by HTML => Static pages Dynamic pages

By modifying HTML code By using CGI programs written in C or Perl PHP&MySQL make creating dynamic websites easier and faster

World Wide Web: HTML & XHTML CSS URI HTTP

HTTP – HyperText Transfer Protocol Developed by W3C and IETF Defines how web pages are transferred across the Internet. A request-and-response protocol that connects clients and servers

Server listen on port 80 Client send request Server send back response (files, images …)

HTTP => TCP => IP

Page 4: 1 Session 1: Introduction to PHP & MySQL iNET Academy Open Source Web Development

4

PHP&MySQL in web development

PHP&MySQL work well together PHP&MySQL have open source power PHP&MySQL have community support PHP&MySQL are fast PHP&MySQL don’t bog you down with

unnecessary details

Page 5: 1 Session 1: Introduction to PHP & MySQL iNET Academy Open Source Web Development

5

Components of a PHP Application

PHP: programing language First appear in 1994 Is an interpreted language Compete with ASP and JSP Simply but powerful Compatible with many OS Can be extended with new capabilities

Page 6: 1 Session 1: Introduction to PHP & MySQL iNET Academy Open Source Web Development

6

Components of a PHP Application (cont.) Apache: web server

Get browser request and return web pages Currently have 3 versions:

1.3.x 2.0.x rewrite and support threading 2.2.x

Apache vs IIS Uses modules to load extensions Works with many OSs

Page 7: 1 Session 1: Introduction to PHP & MySQL iNET Academy Open Source Web Development

7

Components of a PHP Application (cont.) MySQL: database server

Developed in 1990 Support different database engines: MyISAM

and InnoDB Three versions currently

4.1 5.0 5.1

Page 8: 1 Session 1: Introduction to PHP & MySQL iNET Academy Open Source Web Development

8

Integrating many sources of Information Web pages includes not only HTML code but

also CSS: Cascading Style Sheets PHP/JSP/ASP Java Script

Page 9: 1 Session 1: Introduction to PHP & MySQL iNET Academy Open Source Web Development

9

Requesting data from a web page

Page 10: 1 Session 1: Introduction to PHP & MySQL iNET Academy Open Source Web Development

10

Requesting data from a web page (cont.)

Page 11: 1 Session 1: Introduction to PHP & MySQL iNET Academy Open Source Web Development

11

Installation

Install Apache, MySQL and PHP separately Install all-in-one package XAMPP

Page 12: 1 Session 1: Introduction to PHP & MySQL iNET Academy Open Source Web Development

12

Installing Apache using Installation Wizard Goto website http://httpd.apache.org Download the Apache 2.2.x Win32 MSI

apache_2.2.x-win32-x86-no_ssl.msi apache_2.2.x-win32-x86-openssl-….msi

Page 13: 1 Session 1: Introduction to PHP & MySQL iNET Academy Open Source Web Development

13

Installing Apache using Installation Wizard (cont.) The Installation Wizard prompts you for basic

configuration

Page 14: 1 Session 1: Introduction to PHP & MySQL iNET Academy Open Source Web Development

14

Installing Apache using Installation Wizard (cont.) Apache License terms and conditions for use

Page 15: 1 Session 1: Introduction to PHP & MySQL iNET Academy Open Source Web Development

15

Installing Apache using Installation Wizard (cont.) Apache HTTP Server Information

Page 16: 1 Session 1: Introduction to PHP & MySQL iNET Academy Open Source Web Development

16

Installing Apache using Installation Wizard (cont.) Server Network Information Dialog

Page 17: 1 Session 1: Introduction to PHP & MySQL iNET Academy Open Source Web Development

17

Installing Apache using Installation Wizard (cont.) Selecting a setup type

Page 18: 1 Session 1: Introduction to PHP & MySQL iNET Academy Open Source Web Development

18

Installing Apache using Installation Wizard (cont.) Destination Folder dialog for the Apache

installation files

Page 19: 1 Session 1: Introduction to PHP & MySQL iNET Academy Open Source Web Development

19

Installing Apache using Installation Wizard (cont.) “Ready to Install” dialog

Page 20: 1 Session 1: Introduction to PHP & MySQL iNET Academy Open Source Web Development

20

Installing Apache using Installation Wizard (cont.) Apache’s default index page after installation

Page 21: 1 Session 1: Introduction to PHP & MySQL iNET Academy Open Source Web Development

21

Configuring Apache

Choose Edit Apache httpd.conf

Some important directives Listen LoadModule DocumentRoot Directory Options Order, Allow, Deny Alias

Page 22: 1 Session 1: Introduction to PHP & MySQL iNET Academy Open Source Web Development

22

Practice: Installing & Configuring Apache

In this practice, you will Install the apache server using Installation

Wizard Config the server with the following tasks

Changge the Port to 8080 Change the DocumentRoot to another folder Add new aliases and directories Enable the Indexes directive on one of these

alias

Page 23: 1 Session 1: Introduction to PHP & MySQL iNET Academy Open Source Web Development

23

Installing PHP using Installation Wizard Goto http://www.php.net Download the PHP 5.2.x Win32 MSI

php-5.2.x-win32-installer.msi

Page 24: 1 Session 1: Introduction to PHP & MySQL iNET Academy Open Source Web Development

24

Installing PHP using Installation Wizard (cont.) The PHP MSI installer

Page 25: 1 Session 1: Introduction to PHP & MySQL iNET Academy Open Source Web Development

25

Installing PHP using Installation Wizard (cont.) The License Terms dialog

Page 26: 1 Session 1: Introduction to PHP & MySQL iNET Academy Open Source Web Development

26

Installing PHP using Installation Wizard (cont.) The installation directory for PHP

Page 27: 1 Session 1: Introduction to PHP & MySQL iNET Academy Open Source Web Development

27

Installing PHP using Installation Wizard (cont.) The Web Server Setup dialog

Page 28: 1 Session 1: Introduction to PHP & MySQL iNET Academy Open Source Web Development

28

Installing PHP using Installation Wizard (cont.) Select the Apache install path

Page 29: 1 Session 1: Introduction to PHP & MySQL iNET Academy Open Source Web Development

29

Installing PHP using Installation Wizard (cont.) The Installation Options dialog Choose extensions: mbstring and mysql

Page 30: 1 Session 1: Introduction to PHP & MySQL iNET Academy Open Source Web Development

30

Installing PHP using Installation Wizard (cont.) Dialog confirming that the installer will config

Apache

After finish, the Successful Installation dialog appears

Restart Apache Server

Page 31: 1 Session 1: Introduction to PHP & MySQL iNET Academy Open Source Web Development

31

Installing PHP manually

Goto the website http://www.php.net Download the PHP 5.2.x zip pakage

php-5.2.6-Win32.zip Unzip it to the folder C:\PHP Edit the httpd.conf. Add three lines as follow

at the bottom

Page 32: 1 Session 1: Introduction to PHP & MySQL iNET Academy Open Source Web Development

32

Installing PHP manually (cont.)

Goto folder C:\PHP Edit the file named “php.ini-recommended”

and SaveAs “php.ini” Restart the Apache server

Page 33: 1 Session 1: Introduction to PHP & MySQL iNET Academy Open Source Web Development

33

Test of PHP installation

Create a phpinfo.php file with the content <?php phpinfo(); ?>

Save it under the Apache DocumentRoot Directory. Open browser and type http://localhost/phpinfo.php in

the location bar The result should be

Page 34: 1 Session 1: Introduction to PHP & MySQL iNET Academy Open Source Web Development

34

Practice: Installing and Configuring PHP In this practice, you will:

Install PHP manually Test the installation

Page 35: 1 Session 1: Introduction to PHP & MySQL iNET Academy Open Source Web Development

35

Installing MySQL using Installation Wizard Goto the website http://www.mysql.com Download the window installer version of

MySQL 5.0.x mysql-essential-5.0.51b-win32.msi

Page 36: 1 Session 1: Introduction to PHP & MySQL iNET Academy Open Source Web Development

36

Installing MySQL using Installation Wizard (cont.) The MySQL Setup Wizard

Page 37: 1 Session 1: Introduction to PHP & MySQL iNET Academy Open Source Web Development

37

Installing MySQL using Installation Wizard (cont.) Select a setup type

Page 38: 1 Session 1: Introduction to PHP & MySQL iNET Academy Open Source Web Development

38

Installing MySQL using Installation Wizard (cont.) The MySQL.com account setup dialog

Page 39: 1 Session 1: Introduction to PHP & MySQL iNET Academy Open Source Web Development

39

Installing MySQL using Installation Wizard (cont.) Customizes the database settings

Page 40: 1 Session 1: Introduction to PHP & MySQL iNET Academy Open Source Web Development

40

Installing MySQL using Installation Wizard (cont.) Choose level of detail

Page 41: 1 Session 1: Introduction to PHP & MySQL iNET Academy Open Source Web Development

41

Installing MySQL using Installation Wizard (cont.) Howto start MySQL and setup the system

path

Page 42: 1 Session 1: Introduction to PHP & MySQL iNET Academy Open Source Web Development

42

Installing MySQL using Installation Wizard (cont.) Security setting for the database window

Page 43: 1 Session 1: Introduction to PHP & MySQL iNET Academy Open Source Web Development

43

Installing MySQL using Installation Wizard (cont.) Installation is completed

Page 44: 1 Session 1: Introduction to PHP & MySQL iNET Academy Open Source Web Development

44

Config PHP to connect to MySQL

Open the php.ini files Find the extension_dir directive and modify as follow

Find the extension directive and modify as follow

Append “;C:\php” to the system environment’s variable named Path. (MyComputer->Properties->Advanced->Environment Variables

Restart Windows then browse the phpinfo.php page.

Page 45: 1 Session 1: Introduction to PHP & MySQL iNET Academy Open Source Web Development

45

Config PHP to connect to MySQL (cont.)

Page 46: 1 Session 1: Introduction to PHP & MySQL iNET Academy Open Source Web Development

46

Practice: Installing MySQL and Configuring PHP In this practice, you will:

Install MySQL Config PHP to connect to MySQL Test the config’s result

Page 47: 1 Session 1: Introduction to PHP & MySQL iNET Academy Open Source Web Development

47

Open source tools

XAMPP: all-in-one installation package phpMyAdmin: admin MySQL using web-

based tool SQLyog: best GUI tool to administer MySQL Notepad++: PHP&other languages editor.

Page 48: 1 Session 1: Introduction to PHP & MySQL iNET Academy Open Source Web Development

48

Summary

PHP is usually used to develop web applications

PHP-based web applications always go together with Apache and MySQL