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

Preview:

Citation preview

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

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

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

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

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

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

8

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

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

9

Requesting data from a web page

10

Requesting data from a web page (cont.)

11

Installation

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

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

13

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

configuration

14

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

15

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

16

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

17

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

18

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

installation files

19

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

20

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

21

Configuring Apache

Choose Edit Apache httpd.conf

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

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

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

24

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

25

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

26

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

27

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

28

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

29

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

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

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

32

Installing PHP manually (cont.)

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

and SaveAs “php.ini” Restart the Apache server

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

34

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

Install PHP manually Test the installation

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

36

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

37

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

38

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

39

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

40

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

41

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

path

42

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

43

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

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.

45

Config PHP to connect to MySQL (cont.)

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

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.

48

Summary

PHP is usually used to develop web applications

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