47
Getting Started with PHP on IBM i Mike Pavlak Solutions Consultant mike p@zend com mike.p@zend.com © All rights reserved. Zend Technologies, Inc.

Getting started with PHP on IBM i

Embed Size (px)

DESCRIPTION

COMMON Europe Congress 2012 - Vienna

Citation preview

Page 1: Getting started with PHP on IBM i

Getting Started with PHP on IBM i

Mike PavlakSolutions Consultantmike p@zend [email protected]

© All rights reserved. Zend Technologies, Inc.

Page 2: Getting started with PHP on IBM i

PHP Sessions PHP Sessions

• What’s New with Zend ServerSun 11:30 AM

• Business Value of PHPSun 1:30 PM

• Practical PHP by Example (Leth-Kjaer)Sun 4:00 PM

• PHP on IBM i: Getting StartedMon 10:00 AM • PHP on IBM i: Getting StartedMon 10:00 AM

• DB Standards in Zend PHP usage (Sielhorst)Mon 10:00 AM

• MySQL on IBM i, Open Source & DB2 Store Tue 10:00 AM

11 30 A© All rights reserved. Zend Technologies, Inc.| 2 Copyright © 2009 Zend Technologies, Inc, All rights

reserved 02/03/10

• PHP Arrays for the RPG ProgrammerTue 11:30 AM

Page 3: Getting started with PHP on IBM i

Audience Audience

• Are you looking to learn more about the what & how of PHP on IBM i?

• Have you done some PHP but new to IBM i?

• Are you already doing PHP but Looking for product refresh?

• Might you be looking to grow beyond PDM/RPG?

© All rights reserved. Zend Technologies, Inc.| 3 Geting Started with PHP on IBM i

Page 4: Getting started with PHP on IBM i

AgendaAgenda

• The Five Steps…

1. Understand the PHP universe

2. Understand the “stack” on IBM i

3. Install Zend Server

4. Install Zend Studio

5. Get productive!

© All rights reserved. Zend Technologies, Inc.| 4 Geting Started with PHP on IBM i

Page 5: Getting started with PHP on IBM i

1. Understand the PHP Universe

© All rights reserved. Zend Technologies, Inc.

Page 6: Getting started with PHP on IBM i

PHP is a Scripting LanguagePHP is a Scripting LanguagePHP Hypertext Pre-Processor

Developed initially by Rasmus Lerdorf in 1994: PHP/FI

Zeev Suraski and Andi Gutmans Contributing since1997+ (ZEev + aNDi = Zend)

Interpreted, not compiled

Forgiving and intuitive code structure (Short learning curve)

Immediate feedback during development

Operating model is similar to Net.Data, not as verbose

© All rights reserved. Zend Technologies, Inc.

PHP is to Java what RPG is to COBOL| 6 Geting Started with PHP on IBM i

Page 7: Getting started with PHP on IBM i

Who is Zend?Who is Zend?

• Guiding light for PHP

• Providers of stable, supported PHP distribution

• Providers of commercial tooling and support for PHP

Zend Server

Zend Studio

© All rights reserved. Zend Technologies, Inc.| 7 Geting Started with PHP on IBM i

Page 8: Getting started with PHP on IBM i

Zend and IBMZend and IBM

• Partnership began in 2005

• Renewed in 2008

• Zend selected by IBM to deliver PHP on IBM i

• Zend solutions pre-loaded with IBM i 6.1 and 7.1!

Just install the LP and go!

• You can still get products and updates at Zend.com

• IBM i7.1 includes Zend Server

© All rights reserved. Zend Technologies, Inc.

• Relationship expanded in 2012 to include MySQL| 8 Geting Started with PHP on IBM i

Page 9: Getting started with PHP on IBM i

Why Open Source?Why Open Source?• Tough economic times calls for innovation

Low cost of entry Low cost of entry

Applications of high quality

Lower TCO Lower TCO

Runs natively on IBM i, no need for additional hardware / OS

You are probably already using it! (Apache Eclipse etc ) You are probably already using it! (Apache, Eclipse, etc.)

We’re not the only ones talking about Open Source…

Look what IBM is saying in February ‘09 edition!

http://www.ibmsystemsmag.com/ibmi

© All rights reserved. Zend Technologies, Inc.| 9 Geting Started with PHP on IBM i

Page 10: Getting started with PHP on IBM i

The “Stack”The Stack

• Tested, business ready and supported distribution of PHP

• Runs Native Environment under PASE

• Home base for PHP modules like GD, PEAR, etc.

• Browser based admin console

• Accessible immediately after install

• Let’s look at the architecture of the stack

• And then installation on IBM i

• No charge LP Included with system maintenance

© All rights reserved. Zend Technologies, Inc.| 10 Geting Started with PHP on IBM i

Page 11: Getting started with PHP on IBM i

2. Zend Server for IBM i

© All rights reserved. Zend Technologies, Inc.

Page 12: Getting started with PHP on IBM i

What Is Zend Server?What Is Zend Server?• Production quality PHP stack

PHP ZF DB connectivity debugging extension PHP, ZF, DB connectivity, debugging extension, and more

• Two Editions - Free “Community Edition” provided by IBM & Full commercial edition p y Both are production ready

• Application monitoring and diagnostics (integrated with Zend Studio)(integrated with Zend Studio)

• Multi-level performance enhancement capabilities

S ft d t d it h t fi• Software updates and security hot fixes

• Easy and quick installation

• Zend Framework Integration

© All rights reserved. Zend Technologies, Inc.

g

| 12 Geting Started with PHP on IBM i

Page 13: Getting started with PHP on IBM i

Zend Server Under the CoversZend Server Under the CoversIBM i

i/OSILE Apache:10088 i/OSPHP filePASE

ILE Apache:10088• Default

configuration FastCGI

HTTP:10088Server PHP CGI *PGM

as CG

URL Request

Z d S

(FastCGI)CMD

HTML

Zend Server

DB2 UDB

© All rights reserved. Zend Technologies, Inc.| 13 Geting Started with PHP on IBM i

Page 14: Getting started with PHP on IBM i

Software Pre req'sSoftware Pre-req s

Please read the Installation Guide !!!

Description Product Option Licensed Program-------------------------------------- --------------- ----------------Portable App Solutions Environment 33 57XXss1Qshell 30 57XXss1S t O I l d 13 57XX 1System Openness Includes 13 57XXss1IBM Portable Utilities For I5/OS *base 5733sc1OpenSSH ,OpenSST,Zlib 1 5733sc1

Make sure they match your release!

© All rights reserved. Zend Technologies, Inc.| 14 Geting Started with PHP on IBM i

Make sure they match your release!

Page 15: Getting started with PHP on IBM i

3. Installing Zend Server

© All rights reserved. Zend Technologies, Inc.

Page 16: Getting started with PHP on IBM i

Install Zend ServerInstall Zend Server• Prerequisites:

S Z d S i t ll ti d t ti !!! See Zend Server installation documentation!!!

V5R4, i6.1, i7.1 (all interim releases, too)

Recent Cumulative PTF package PASE Qshell Group for HTTP Recent Cumulative PTF package, PASE, Qshell, Group for HTTP

• Software installation

Windows Installation or...

Upload *SAVF, Restore, and start coding!

Clean installation can start the stack automatically

• Bonus!

MySQL can be installed at the same time or can wait to install Zend DBi

© All rights reserved. Zend Technologies, Inc.| 16 Geting Started with PHP on IBM i

Page 17: Getting started with PHP on IBM i

Where do I get it? IBM LP or Zend comWhere do I get it? IBM LP or Zend.com

© All rights reserved. Zend Technologies, Inc.| 17 Geting Started with PHP on IBM i

Page 18: Getting started with PHP on IBM i

Start/stop Zend Server MySQL etcStart/stop Zend Server, MySQL, etc... Type GO ZENDSVR/ZSMENU, Option 5 then 1

© All rights reserved. Zend Technologies, Inc.| 18 Geting Started with PHP on IBM i

Page 19: Getting started with PHP on IBM i

Zend Server ConfigurationZend Server Configuration• Only two screens!

Use http://ibmiserver:2001 to administer IBM HTTP server Use http://ibmiserver:2001 to administer IBM HTTP server

Use Zend Admin to administer Zend/PHP options

© All rights reserved. Zend Technologies, Inc.| 19 Geting Started with PHP on IBM i

Page 20: Getting started with PHP on IBM i

Zend Server Port Change?Zend Server Port Change?

• Default proxy points to Port 10088Port 10088

Log in to IBM Admin Server and open up ZENDSVRZENDSVR

Go to General Server Configurationg

Click Apply & restart the server

© All rights reserved. Zend Technologies, Inc.| 20 Copyright © 2009 Zend Technologies, Inc, All rights reserved 02/03/10

| 20 Geting Started with PHP on IBM i

Page 21: Getting started with PHP on IBM i

Sample Scripts!Sample Scripts!

© All rights reserved. Zend Technologies, Inc.| 21 Copyright © 2009 Zend Technologies, Inc, All rights reserved 02/03/

10| 21 Geting Started with PHP on IBM i

Page 22: Getting started with PHP on IBM i

Sample Scripts!Sample Scripts!

© All rights reserved. Zend Technologies, Inc.| 22 Geting Started with PHP on IBM i

Page 23: Getting started with PHP on IBM i

Zend Server php ini changesZend Server php.ini changes

• Manage php.ini via GUI in Zend Serverin Zend Server

Log in with initial password, can reset in

S green screen Server Setup Directives

Administer all values in

Open SourceOpen Source

php.ini

Include path is one of many optionsmany options

Must restart PHP using new blue button!

© All rights reserved. Zend Technologies, Inc.| 23 Geting Started with PHP on IBM i

Page 24: Getting started with PHP on IBM i

4. Install Zend Studio

© All rights reserved. Zend Technologies, Inc.

Page 25: Getting started with PHP on IBM i

Zend Studio 9 for all!Zend Studio 9 for all!

• Included for IBM i customers w/1 year support & upgradesy pp pg

• Essential IDE for PHP on IBM i

• Syntax checker & code CompletionSyntax checker & code Completion

• JavaScript Library Support

• Debugger• Debugger

• Built on Eclipse framework

• Function directory• Function directory

• Templates

M ch m ch more

© All rights reserved. Zend Technologies, Inc.

• Much, much, more

| 25 Geting Started with PHP on IBM i

Page 26: Getting started with PHP on IBM i

Zend Studio 9 for IBM i InstallationZend Studio 9 for IBM i - Installation

• Download program from Zend.com/en/downloads (IBM i p g (Edition!)

• Install to workstation (Mac, Windows, Linux)

• Follow the prompts for licensing the product

• Zend.com with QSRLNBR to license product

• Start the IDE and begin coding PHP immediately

© All rights reserved. Zend Technologies, Inc.| 26 Geting Started with PHP on IBM i

Page 27: Getting started with PHP on IBM i

How do I access IFS files?How do I access IFS files?• Three methods I use

Netserver file associations (or a mapped local drive)

• Can be sluggish

Remote server configuration Remote server configuration

• Best for all purposes

WRKLNKWRKLNK

• Only for emergencies!

© All rights reserved. Zend Technologies, Inc.| 27 Geting Started with PHP on IBM i

Page 28: Getting started with PHP on IBM i

Remote Server OptionsRemote Server Options

• FTP

Familiar

Sluggish

Most systems support this

• SSH

More secure

More powerful

Easy to setup

Easier to setup on i6.1+

© All rights reserved. Zend Technologies, Inc.| 28 Geting Started with PHP on IBM i

Page 29: Getting started with PHP on IBM i

Configuring a remote serverConfiguring a remote server• Start Zend Studio for IBM i

Cli k th ti b tt d l t SSH• Click the new connection button and select SSH

• Enter system name or IP address

© All rights reserved. Zend Technologies, Inc.| 29 Geting Started with PHP on IBM i

Page 30: Getting started with PHP on IBM i

Navigate to filesNavigate to files• Expand the tree for your system

• Navigate to the directory /www/zendsvr/htdocs• Navigate to the directory /www/zendsvr/htdocs

• Enter user credentials and your in!

© All rights reserved. Zend Technologies, Inc.| 30 Geting Started with PHP on IBM i

Page 31: Getting started with PHP on IBM i

Host side changeHost side change• CHGFTPA NAMEFMT(*PATH) CURDIR(*HOMEDIR)

LISTFMT(*UNIX)( )

• Bounce FTP servers

ENDTCPSVR SERVER(*FTP)N C SV S V ( )

STRTCPSVR SERVER(*FTP)

• If you have concerns about the host side FTP change y gconsider the SSH method.

V5R4 - Will need to configure and start SSH.

i6.1+ uses STRTCPSVR command for SSHD

See http://wiki.midrange.com/index.php/SSH

© All rights reserved. Zend Technologies, Inc.

User ID must be 8 chars or less. (Sorry, IBM restriction)

| 31 Geting Started with PHP on IBM i

Page 32: Getting started with PHP on IBM i

|| 32 Geting Started with PHP on IBM i

Page 33: Getting started with PHP on IBM i

5. Get Productive!

Hello World

© All rights reserved. Zend Technologies, Inc.

Page 34: Getting started with PHP on IBM i

Sample Script Hello WorldSample Script – Hello World• Obligatory program when starting out

• Confirms correct setup of PHP• Confirms correct setup of PHP

• Sample code: (Shortest PHP Macro around!)

Save script in IFS /www/zendsvr/htdocs/helloworld php• Save script in IFS /www/zendsvr/htdocs/helloworld.php

• Browser URL: http://ibmisystem:10088/helloworld.php

<?php

echo “Hello World”;

?>

© All rights reserved. Zend Technologies, Inc.| 34 Geting Started with PHP on IBM i

Page 35: Getting started with PHP on IBM i

© All rights reserved. Zend Technologies, Inc.| 35 Geting Started with PHP on IBM i

Page 36: Getting started with PHP on IBM i

Open Source ToolkitOpen Source Toolkit•Collaboration with IBM and Zend•Built on ILE RPG Stored Procedures & pure PHP•Built on ILE RPG, Stored Procedures & pure PHP•Up to 10 times faster•Object Oriented but not too much!•Object Oriented, but not too much!•Old toolkit not going away, but support may be chargeableg

© All rights reserved. Zend Technologies, Inc.| 36 Geting Started with PHP on IBM i

Page 37: Getting started with PHP on IBM i

Now the program callNow the program call

Set parameters based on functionp

Call program

Output results I/

Leng

Comm

Var

n

Init/

Ogth

ent

name

val

© All rights reserved. Zend Technologies, Inc.37 Insert->Header & Footer

Page 38: Getting started with PHP on IBM i

PHP Data Access Example

© All rights reserved. Zend Technologies, Inc.

Page 39: Getting started with PHP on IBM i

Basic file listing scriptBasic file listing script• Connect to DB2 i

• Select records from a DB2 table• Select records from a DB2 table

• Load the records in an HTML table

Display the output• Display the output.

© All rights reserved. Zend Technologies, Inc. 02/03/10

| 39 Geting Started with PHP on IBM i

Page 40: Getting started with PHP on IBM i

Connection to DB2 for iConnection to DB2 for i• Need three things:

System Note: If your data sets have *PUBLICy

User ID

Password

Note: If your data sets have PUBLIC access, no user or password is required

// Standard DB connection to DB2...$conn = "*LOCAL"; $name = "";$pwd = "";

$i5link = db2_connect($conn, $name, $pwd);_ ( p )if (!$i5link) echo 'Connection failed: '.db2_stmt_error().' : '.db2_stmt_errormsg();

$sql = "SELECT * from zenddata.customer";$sql SELECT from zenddata.customer ;

$stmt = db2_exec($i5link,$sql)or die("Failed query:".db2_stmt_error().":".db2_stmt_errormsg());

© All rights reserved. Zend Technologies, Inc. 02/03/10

?>

| 40 Geting Started with PHP on IBM i

Page 41: Getting started with PHP on IBM i

Reading dataReading data...Loop through record set

<h1> Customer list for a company</h1><TABLE BORDER="10" BORDERCOLOR="blue"><TBODY BGCOLOR="DEB887"><TABLE BORDER= 10 BORDERCOLOR= blue ><TBODY BGCOLOR= DEB887 ><TR><TD>Customer Number</TD><TD>Customer Name</TD><TD>Address Line 1</TD><TD>Address Line 2</TD><TD>City</TD><TD>State</TD><TD>Zip Code</TD></TR>

<?php

while($row=db2_fetch_array($stmt)){list( $CUSTOMER_NUMBER, $CUSTOMER_NAME, $CUSTOMER_ADDRESS_LINE1, $CUSTOMER_ADDRESS_LINE2, $CUSTOMER_CITY, $CUSTOMER_STATE, $CUSTOMER ZIP)= $row;$CUSTOMER_ZIP) $row;

echo(“ <TR><TD> $CUSTOMER_NUMBER </TD><TD> $CUSTOMER_NAME </TD><TD> $CUSTOMER_ADDRESS_LINE1 </TD><TD>$CUSTOMER_ADDRESS_LINE2 </TD><TD> $CUSTOMER_CITY</TD><TD> $CUSTOMER_STATE </TD>

TD $CUSTOMER ZIP /TD /TR ")<TD> $CUSTOMER_ZIP </TD></TR> ");}echo ‘ </table> ';db2_close($i5link);

© All rights reserved. Zend Technologies, Inc. 02/03/10

?>

| 41 Geting Started with PHP on IBM i

Page 42: Getting started with PHP on IBM i

Basic file listing scriptBasic file listing script• Connect to DB2 i

• Select records from a DB2 table• Select records from a DB2 table

• Load the records in an HTML table

Display the output• Display the output.

© All rights reserved. Zend Technologies, Inc. 02/03/10

| 42 Geting Started with PHP on IBM i

Page 43: Getting started with PHP on IBM i

Getting Started with PHP on IBM iwww.zend.com

Wrap it up!

© All rights reserved. Zend Technologies, Inc.

Page 44: Getting started with PHP on IBM i

Where do I go next?Where do I go next?

• Get some HTML trainingg

Remember, HTML is to PHP what DDS is to RPG

• JavaScript won’t hurt p

Can add pizzazz to web pages, but not required

• Download free code – see online resource slide

• Play, have fun, discover

• Education, training more See zend.comEducation, training more See zend.com

• Practice, practice, practice!

© All rights reserved. Zend Technologies, Inc. 02/03/10

| 44 Geting Started with PHP on IBM i

Page 45: Getting started with PHP on IBM i

PHP ResourcesPHP Resources…

• Books

Sam’s teach yourself PHP, MySQL and Apache All in One (4th edition) ISBN:067232976X

Head First HTML with CSS and XHTML ISBN:059610197X

Zend Server Doc at Zend Website

© All rights reserved. Zend Technologies, Inc.

IBM i Programmer’s Guide to PHP on IBM i – MC Press02/03/10

| 45 Geting Started with PHP on IBM i

Page 46: Getting started with PHP on IBM i

Online ResourcesOnline Resources…• Support?

Zend com/forumsZend.com/forums

Zend.com/support-center

Z d / d tZend.com/products

php.net – on-line PHP manual

Midrange.com WEB400 forum

• Free code!

Sourceforge.net – free applications

phpclasses.org – free PHP code samples

© All rights reserved. Zend Technologies, Inc.

hotscripts.com – free PHP code02/03/10

| 46 Geting Started with PHP on IBM i

Page 47: Getting started with PHP on IBM i

Questions?

Thank you!!

Mike p@zend [email protected]

© All rights reserved. Zend Technologies, Inc.| 47 Geting Started with PHP on IBM i