PHP and MySQL on IBM i New Stacks and New Solutions Erwin Earley (erwin.earley@us.ibm.com) IBM i Technology Center Open Community Technologies Center of Competency 8 Copyright IBM Corporation, 2009. All Rights Reserved. This publication may refer to products that are not currently available in your country. IBM makes no commitment to make available any products referred to herein. Agenda Introduction The iamp Stack Deploying Open Source Solutions on IBM I Zend Core MySQL The iadp Stack Developing IBM i centric applications with PHP Zend Core Zend Studio 5250 Bridge Zend Framework 1
Web Development/Deployment Stacks L A M P i n u x p a c h e y S Q L H P W i n d o w s I M P I S y S Q L H P i B M i A D P p a c h e B 2 H P i B M i A M P p a c h e y S Q L H P Introduction The LAMP stack (Linux, Apache, MySQL, PHP) is being used by a growing number of developers to provide a low-cost, reliable platform for web-based applications. The iamp stack (IBM i, Apache, MySQL, PHP) is the IBM i native variant of the LAMP stack it allows for development of web-based applications integrated with the MySQL open source database. iamp is well suited for those customers/environments that wish to leverage existing open source applications based on PHP and MySQL. The iadp stack (IBM i, Apache, DB/2, PHP) is another IBM i native variant of the LAMP stack it allows for development of web-based applications integrated with the DB/2 database and other native IBM i resources iadp is well suited for those customers/environments that wish to develop customized web applications that provide the ability to access and manipulate IBM i resources 2
What is the LAMP Stack? LAMP refers to a set of tools (Linux, Apache, MySQL, and PHP) that facilitates rapid development and deployment of software applications LAMP is often defined as the open source web platform. Evolution of web applications Every 7 seconds a new wiki or blog is created Next wave of programmers: folks who create content are now empowered to create applications New platforms being established providing simple, feature rich environments for editing and contributing content. Content is handled with a simple WYSIWYG editor that makes editing accessible to anyone Main content accompanied with discussion tabs, history tabs, version tabs, mailing list tabs 3
The LAMP Stack Open Source Software Components used as a "toolkit" by web developers for deploying robust webcontent complete with data access and manipulation Application PHP Has become a major development platform for the enterprise Used by such enterprises as Amazon, Friendster, Google, and Yahoo Apache Linux MySQL What is LAMP? Linux Windows MySQL SQLite PostgreSQL Apache PHP Python Perl Open-source software stack with a strong focus on: Affordability Perceived zero to low cost Ease of development, ease-of-use Community Building solutions. Large body of single-click install & auto-configure solutions and libraries (http://www.hotscripts.com/) L = Linux A = Apache web server M = MySQL P = PHP Perl Python 4
The LAMP components Linux Free UNIX-type operating system Has become firmly established as an enterprise-class alternative to proprietary UNIX and Microsoft products Commercial entities, such as IBM, have extended the free Linux kernel and created the support and services infrastructure essential to enterprise customers Apache Traces its roots to the public domain HTTP daemon developed at the National Center for Supercomputing Applications Apache has been the most popular web server every year since 1996 MySQL World's most popular open source database Many large corporations including Sabre Holdings, Cox Communications, The Associate Press, and NASA are using MySQL to power web-sites, businesscritical enterprise applications and packaged software PHP Widely used general-purpose scripting language Especially suited for web development Can be embedded in HTML It has become one of the most popular languages on the web What's driving LAMP (and open-source related development stacks) Constant pressure on developers to do more, faster, and with less as firms strive to reduce costs, improve returns on IT investments, and accelerate time-to-value Growing adoption of SOA environments for enterprise integration Allows wider choice of application development & implementation technologies by allowing heterogeneous systems to interact freely at the service level Faster pace of open source software improvement relative to proprietary products Facilitated by active participation of global user communities Availability of polished developer tools for the LAMP environment Example: Zend's integrated development and production environments for PHP applications 5
Speed and Simplicity The language component (PHP) of the LAMP stack (as well as iadp and iamp) has been created specifically to simplify, streamline, and accelerate programming tasks typical of Web development. PHP is particularly well suited for text handling as well as database access for dynamic content generation. PHP features a simple, clear syntax that makes it easy to learn. What can be done with LAMP an Example Wikipedia: >8,000 HTTP requests per second >25,000 SQL requests per second 12 database servers 15 application servers in 'external storage' role 20 application servers in 'object cache' role 6
The iamp Stack Application PHP Apache MySQL IBM i Web Server IBM i Apache Flexible, Easy to configure Serves over 50% of all websites Secure, efficient, extensible server Many extensions available 7
MySQL: World s Most Popular Open Source Database Founded in 1995; operations in 24 countries Adoption of Open Source Over 11,000,000 installations; 65,000 downloads/day Part of a rapidly growing open source LAMP stack Used by IT organizations to implement scale-out architecture More Data & Analysis Community Growth Maturation of Web Architecture Commoditization MySQL Very easy to setup and use Most popular open source database Has gained popularity in the web application world and is used in most of the leading PHP applications. Open Source, but also commercially backed Used in more the 11 million installations Cross-platform (over 20 including IBM i, Windows, Linux, OS/X, HP-UX, AIX, Netware) 8
iamp Components: MySQL IBM and MySQL Plans for IBM i and DB2 MySQL is the leading open source database with over 11 million installations MySQL is the most popular database to use with PHP applications Step 1: MySQL database supported on IBM i Enables customers to deploy MySQL-based applications on IBM i Step 2: Integrate integrate MySQL with DB2 on IBM i Enables MySQL-based applications to store data in DB2 on IBM i IBM i customers get the benefit of being able to use thousands of new open source applications while continuing to have one easy to use data store with DB2. MySQL for IBM i MySQL database available and supported on IBM i5.4 and i6.1 MySQL Enterprise MySQL Enterprise MySQL Enterprise MySQL Community Server for IBM i Free download from mysql.com No Support MySQL Enterprise for IBM i Download from mysql.com Annual Subscription 3 support levels Silver $1995.00 /Server/Year Business Hours 4 Hours* Gold $2995.00 /Server/Year 24x7 2 Hours* Advisory Services and Consultant Support Options Platinum $4995.00 /Server/Year 24x7 1 Hour* Available directly from MySQL on 7/24 Can also be ordered from IBM http://www.ibm.com/systems/i/software/mysql/ * Max Initial Response Time MySQL US List Prices https://shop.mysql.com/enterprise/ 9
MySQL in IBM i High Level Architecture Integrated File System MySQL Database TCP/IP PASE Environment mysqld MySQL Server Process Socket TCP/IP ODBC (localhost) mysql PHP Client Process Client Process TCP/IP PHP MySQL Pre-Requisites Licensed program Option Description test 5722SS1 5722SS1 5722SS1 5722SS1 5722SC1 *BASE 13 30 33 *BASE IBM i Version 5 Release 4 (i5.4) IBM i Version 6 Release 1 (i6.1) System Openness Includes 1 Qshell Portable Application Solutions Environment (PASE) IBM Portable Utilities for i5/os 2 1. System Openness Includes is not completely necessary but may be useful. This licensed program provides all source includes for APIs shipped with IBM i 2. IBM Portable Utilities for i5/os is not completely necessary but may be useful. 10
PHP Web Scripting language by design Easy to learn Flexible and powerful Cross-platform Easily extended Zend: The PHP Company High-quality, cost-effective, fast-to-market web applications Know-how / best practices PHP products with support Zend Core Certified PHP & Maintenance Zend Platform PHP Application Servers Zend Studio Developer productivity, quality Community Steward PHP core team Zend Framework Eclipse PDT project Zend Developer Zone Partner enablement 11
Zend Products for IBM i Zend Core for i PHP runtime environment Zend Toolkit for IBM i MySQL Community Edition Zend Framework Zend Studio for Eclipse, i Edition Integrated Development Environment on Windows, Linux, or Mac Zend Platform for i PHP monitoring and optimization Includes 5250 Bridge and Java Bridge Support for Zend Products Zend provides support for IBM i based products through the Zend Network Zend Core for i5/os and Zend Studio for Eclipse i5 Edition support includes: Product downloads including current and previous versions Software updates and information Knowledge Base access Web-based support including unlimited support tickets Gold and Platinum Support options are available Gold: phone support, Monday through Friday, eight hours a day Platinum: phone support, seven days a week, twenty-four hours a day http://www.zend.com/core/network/ 12
Zend Forums A Vibrant IBM i Community http://www.zend.com/forums/ Zend in the News Recent Announcements Zend Core 2.5 Features MySQL (Community Edition) delivered and installed Extensions to the language added to provide the ability to connect PHP applications running in IBM i to a SQL server database running under Windows Windows based installer 13
Zend in the News Recent Announcements Zend Studio for Eclipse i5 Edition Combines features of Zend Studio with the Eclipse PHP Developer Tools (PDT) Integrated with Zend Core and Zend Platform Built in database connectivity Code Generation Zend Framework Integration Profiling Code Coverage Advanced Debugging WYSIWYG editor for HTML FTP, Source, Control, Database Support Zend Core Now Preloaded with IBM i Delivering popular open source software stack with IBM i Zend Core 2.6 includes PHP Runtime Toolkit for IBM i Zend Framework MySQL Community Edition AMP stack for i Apache PHP MySQL IBM i Installation image preloaded with IBM i 5.4 and i 6.1 With new systems and with new operating system shipments Effective 2/6/09 Zend Core needs to be installed Licensed and supported by Zend 14
What are IBM i Customer's Doing with iamp? Leveraging PHP portfolio: Run commercial or opensource PHP applications on IBM i Application PHP Apache MySQL IBM i Web Server IBM i IBM i Requirements for Zend Core for i5/os IBM i5.4, IBM i6.1 i5/os V5R3 Zend Core for i5/os Version 1.6 or later required i5/os V5R3 database PTF SI25802 is required Zend Core for IBM i does not support remote debugging from a Zend Studio client Plus Portable App Solutions Environment 33 5722ss1 IBM Portable Utilities For i5/os *base 5733sc1 OpenSSH,OpenSST,Zlib 1 5733sc1 Crypto Access Provider 128 bit *base 5722ac3 Qshell 30 5722ss1 System Openness Includes 13 5722ss1 Digital Certificate Manager 34 5722ss1 IBM i servers that run i5.3, i5.4, or i6.1 15
Obtaining Zend Core & Zend Studio for i5/os Zend.com Registration Download (to your PC) Zend Core for i5/os & Zend Studio for i5/os Zend Core Now Preloaded with IBM i Delivering popular open source software stack with IBM i Zend Core 2.6 includes PHP Runtime Toolkit for IBM i Zend Framework MySQL Community Edition AMP stack for i Apache PHP MySQL IBM i Installation image preloaded with IBM i 5.4 and i 6.1 With new systems and with new operating system shipments Effective 2/6/09 Zend Core needs to be installed Licensed and supported by Zend 16
MySQL + PHP on IBM i Applications Examples on IBM I www.zend.com/forums MySQL (Open Source DB) on IBM i - http://www.zend.com/forums/index.php?t=msg&goto=3004 MediaWiki (Open Source Wiki) on Zend Core for IBM i - http://www.zend.com/forums/index.php?t=msg&th=3134 SugarCRM (Open Source Customer Relationship Management (CRM)) on Zend Core for IBM i - http://www.zend.com/forums/index.php?t=msg&th=3111 Joomla! (Open Source Content Management System) on Zend Core for IBM i - http://www.zend.com/forums/index.php?t=msg&th=3068 Zen Cart (Open Source Online Store) on Zend Core for IBM i - http://www.zend.com/forums/index.php?t=msg&th=3041 PmWiki (Open Source Wiki) on Zend Core for IBM i - http://www.zend.com/forums/index.php?t=msg&goto=8085 PHP-Nuke (Open Source Content Management System) on Zend Core for IBM i - http://www.zend.com/forums/index.php?t=msg&goto=3541 Content Management Wiki E-Commerce Bug Tracking CRM Joomla! (Open Source Content Management System) MySQL + PHP on IBM i Application Website: http://joomla.org/ Description: http://en.wikipedia.org/wiki/joomla How To: www.zend.com/forums/index.php?t=msg&th=3068 Running on IBM i: http://sei5a2.rchland.ibm.com:89/joomla 17
SugarCRM (Open Source Customer Relationship Management (CRM)) MySQL + PHP on IBM i Application Website: www.sugarcrm.com Description: http://en.wikipedia.org/wiki/sugarcrm How To: www.zend.com/forums/index.php?t=msg&th=3111 Running on IBM i: http://sei5a2.rchland.ibm.com:89/sugarcrm/ SugarCRM Supports for IBM i SugarCRM is a leading provider of commercial open source customer relationship management (CRM) software for companies of all sizes Sugar Enterprise available for IBM i Runs with Zend Core and MySQL http://www.sugarcrm.com/crm/ 18
Leveraging MySQL Data with DB2 Web Query SugarCRM is a PHP application written to MySQL DB2 Storage Engine enables SugarCRM data to be stored in DB2 DB2 WebQuery can access SugarCRM data Using DB2 Web Query SDK and Report Broker you can integrate reporting into SugarCRM SugarCRM MySQL Writes to Data stored in DB2 for i DB2 Web Query Accesses Data ZenCart (Open Source Shopping Application) MySQL + PHP on IBM i Application Website: http://www.zen-cart.com/ Description: http://en.wikipedia.org/wiki/zen_cart How To: www.zend.com/forums/index.php?t=msg&th=3041 Running on IBM i: http://sei5a2.rchland.ibm.com:89/zencart-v1.3.7/ 19
Deploy Opensource Applications on IBM i Solution IBM i offers an integrated and open web application deployment environment based on Apache, MySQL, and PHP on IBM i Value Deploy applications faster, maintain systems easier IBM i provides a leading integrated and complete environment for LAMP-based applications. Delivers enterprise scalability from one to 64-way POWER5 processors. The integrated IBM i architecture is secure and virus resistant by design IBM i delivers industry leading availability and reliability. IBM i provides ability to easily integrate web apps with business apps on the same server IBM i has a proven track record of delivering the lowest TCO and highest customer satisfaction Access IBM i applications and data easier and faster PHP applications have direct and easy access to business apps and data running on IBM i Run MySQL applications Objections for Opensource Applications Why should we deploy a LAMP application on IBM i? IBM i provides leading reliability, security, and scalability for web applications. The Zend toolkit for IBM i provides easy and fast access to IBM i applications and data. Support of MySQL in IBM i provides the ability to run PHP/MySQL applications unchanged in IBM i. Is the IBM i community embracing PHP? Yes, the IBM i community is an active participant in the PHP community. The Zend forum for IBM i is 3x more active than the Zend forum for Oracle. Who provides support for the open-source (PHP, MySQL) components of the web development stack? Zend offers a range of support options for their PHP development and deployment products. MySQL provides support for the enterprise deployment of MySQL 20
The iadp Stack Application PHP Apache IBM i web Server DB/2 IBM i How does iadp Work? Port 89 Port 8000 Port 6077 I5_COMD IBM i IBM i IBM i http://servername:2001/httpadmin http://servername:89/zendcore 21
What are IBM i Customer's Doing with iadp? Consolidation: Moving PHP applications that are running on Windows or Linux that access data in DB2 to run in IBM i to speed up or reduce complexity of the application Modernization: Using iadp to web-enable green-screen applications New application development: Creating new applications with iadp including applications for the intranet, reporting, websites, and extranets. PHP Integration with IBM i Zend Core for i5/os includes Extensions and Toolkit so PHP applications can access: DB2 for IBM i SQL and Native Program call Procedure call Data Area Data Queue Message Queue Commands System values Spool files 22
iadp it's all about the API toolkit Are shipped with Zend products Zend core for i5/os Zend Platform for i5/os Geared towards accessing IBM i data and resources from PHP Similar in purpose to the IBM Toolbox for Java Note: the I5_COMD job must be running in the ZEND subsystem Use the Zend menu to start: GO ZENDCORE/ZCMENU Option 5 (Service Management menu) Option 8 (Start I5_COMD service) PHP Toolkit for i5/os list of functions Connection management i5_connect i5_close i5_adopt_authority i5_error i5_errno i5_errormsg Command calls i5_command Program calls i5_program_prepare i5_program_prepare_pcml i5_program_call i5_program_close Data retrieval i5_fetch_array i5_fetch_assoc i5_fetch_object i5_fetch_row i5_info i5_field_len i5_field_name i5_field_scale i5_field_type i5_list_fields i5_num_fields i5_result Native file access i5_open i5_addnew I5_edit I5_delete i5_cancel_edit i5_setvalue i5_update i5_range_from i5_range_to i5_range_clear i5_data_seek i5_seek i5_bookmark i5_free_file i5_new_record i5_update_record i5_get_keys 23
PHP Toolkit functions System values i5_get_system_value Data areas i5_data_area_prepare i5_data_area_receive i5_data_area_send i5_data_area_close Print/Get spooled file i5_spool_list i5_spool_list_read i5_spool_list_close i5_spool_get_data i5_spool_from_file Job logs i5_joblog_list i5_joblog_list_read i5_joblog_list_close Active jobs i5_job_list i5_job_list_read i5_job_list_close Objects list i5_object_list i5_object_list_read i5_object_list_close User space i5_userspace_crearte i5_userspace_prepare i5_userspace_get i5_userspace_put Data Queue i5_dtaq_prepare i5_dtaq_recieve i5_dtaq_send i5_dtaq-close Accessing DB2/400 Server/connection db2_bind_param db2_client_info db2_close db2_connect db2_cursor_type db2_exec db2_execute db2_prepare db2_pconnect db2_server_info db2_statistics Result db2_free_result db2_next_result db2_result Commit/Rollback db2_autocommit db2_commit db2_rollback Fetch db2_fetch_array db2_fetch_assoc db2_fetch_both db2_fetch_object db2_fetch_row Field information db2_field_display_size db2_field_name db2_field_num db2_field_precision db2_field_scale db2_field_type db2_field_width Key information db2_foreign_keys db2_primary_keys Statement db2_free_stmt Errors db2_conn_error db2_conn_errormsg db2_stmt_error db2_stmt_errormsg Column/Procedure db2_column_privileges db2_columns db2_procedure_columns db2_procedures db2_special_columns Table information db2_num_fields db2_num_rows db2_table_privileges db2_tables All of these APIs are documented online at php.net - Preferred db2_ SQL statement execution APIs (performance) - Non-preferred db2_ SQL statement execution API 24
Server connection db2_connect API There are few connections options in PHP db2_connect(,, ) local server The database connection job is create under the same user as the Apache httpd server profile NOBODY (*USER). db2_connect( *LOCAL", SAM", PASSWROD") local server The database connection job is created under the user profile SAM/PASSWROD. db2_connect( 10.1.1.33", SAM", PASSWROD") remote remote database connection job is created under the user server The profile SAM/PASSWROD. Tip: Use WRKRDBDIRE to get the database name on the remote i5 ToolKit vs. DB2 Extensions The i5 Toolkit represents functions for accessing native IBM i resources The toolkit is specific to the Zend products for IBM i The toolkit functions can only access local resources (i.e., resources on the same IBM i partition as Zend Core) unless you setup remote connections (such as DDM) outside of the Zend Core environment. All i5 Toolkit functions begin with the characters i5_ The DB2 functions represent an extension to the PHP language The DB2 extensions can access both local and remote DB2 resources through established network connections All DB2 functions begin with the characters db2_ 25
i5 Toolkit vs. DB2 Extensions Zend Core PASE IBM i i5_* I5_COMD db2_* IBM i Resource TCP/IP db2_* IBM i Resource IBM i Zend Studio for Eclipse, IBM i Edition Integrates with Rational Developer for IBM i 7.5 (RDi, RDi SOA) One advanced development environment for RPG, PHP, and Java Both based on Eclipse 3.4 Provides instant online debugging and error fixing against Zend Core for IBM i Customizable and smart context sensitive templates for IBM i Toolkit functions Create/generate PHP Toolkit code quickly Call RPG/CL/COBOL program, execute CL command, retrieve Spooled file entries, access Data Area, Data Queue and User Space, etc 26
Zend Studio for Eclipse, IBM i Edition Zend Studio for Eclipse What s New? Based on PDT & Zend Studio Features/Technology Out of the Box Solution Refactoring PHP Unit Testing Code Generation Zend Framework Integration Profiling, Code Coverage, Advanced Debugging HTML WYSIWYG FTP, Source Control, DB Support 27
Zend Studio for Eclipse The Professional PHP Development Environment Integrated Development Environment that encompasses: Development Debugging Management Deployment Zend Framework Web App Framework 10+ Million downloads Wide adoption by large corporate customers 500+ contributors 1,800,000 1,600,000 1,400,000 1,200,000 1,000,000 800,000 600,000 400,000 200,000 0 Zend Framework: Raw Downloads Q206 Q306 Q406 Q107 Q207 Q307 Q407 Q108 Q208 Q308 28
Zend 5250 Bridge The 5250 Bridge is a PHP based solution for running interactive applications in the IBM i environment Zend 5250 Bridge Diagram Browser 5250 Program 5250 Program Business Logic UI Processing DB Access 1. PHP sends a 'start session' request to the 5250 Program using the 5250 Bridge. HTML 2. The 5250 Bridge returns a confirmation to PHP that the session has started. 3. The 5250 Bridge sends current screen information in XML format to PHP (e.g. format name, input and output fields and current cursor position). 4. The input values can be automatically entered into the program or sent on in an html format for user input. Zend Core XML Workstation Function Manager zend_5250_open zend_5250_connect zend_5250_get_output_fields zend_5250_get_input_field zend_5250_set_input_field zend_5250_submit. 5250 Bridge 29
Zend Framework 8 Copyright IBM Corporation, 2009. All Rights Reserved. This publication may refer to products that are not currently available in your country. IBM makes no commitment to make available any products referred to herein. Zend Framework Zend Framework is a collection of pre-canned objects (classes and function calls) to facilitate the building of modern applications and web services Examples of components included in the framework: Zend_Acl: provides access control list (ACL) functionality and privileges management Zend_Config: simplifies the use of configuration data for web applications Zend_Controller and Zend_View: provides the infrastructure for Model-View-Controller (MVC) websites. Zend_Feed: provides a simple way to work with life syndicated feeds Zend_Filter and Zend_Validate: facilitates the development of secure websites by providing basic tools necessary for filtering and validation. Zend_Gdata: Google Data APIs that provide read/write access to services hosted at google.com such as Spreadsheets, Calendar, Blogger, and CodeSearch Zend_Mail and Zend_Mimi: creates email messages and sends them Zend_PDF: Create or read PDF documents from PHP applications. Can also modify existing PDF documents. 30
Zend Framework Installation Download Zend Framework from http://framework.zend.com Zend Framework is bundled with Zend Core for i5/os version 2.5.x Unpack the resulting zip file Upload the library directory to a directory in the include_path for Zend Core /usr/local/zend/core/include/zend/include NOTE: The download of Zend Framework includes a number of examples/sample-code that leverage the framework. Examples include: Feeds (for working with items such as RSS feeds) Gdata (for accessing google services) Mail (for facilitating the generation and sending of email) Pdf (for reading, generating, and even changing PDF files Questions 31