83
© Proximity 2015

Running open source PHP applications on you IBM i

Embed Size (px)

Citation preview

Page 1: Running open source PHP applications on you IBM i

© Proximity 2015

Page 2: Running open source PHP applications on you IBM i

© Proximity 2015

About us

Page 3: Running open source PHP applications on you IBM i

© Proximity 2015

Agenda

• What is open source?

• PHP for open source

• PHP on IBM i

• Live install of Zend Server

• Live install of Zend DBi

• What are Zend Server applications?

• Hands-on install from a .zpk

• Hands-on install from source

• Zend Server - A brief tour

• Configuring Zend Server – top tips

• Q & A

Page 4: Running open source PHP applications on you IBM i

© Proximity 2015

Objectives – what are yours?

• What is your experience of open source applications?

• What is your experience of PHP, MySQL or Zend Server?

• Would you run an open source application on IBM i for your business?

• Are you interested in any specific open source applications?

Page 5: Running open source PHP applications on you IBM i

© Proximity 2015

Objectives – what are ours?

• An understanding of open source applications on IBM i

• Implementation of Zend Server and Zend DBi

• Installation of an open source application of your choice

• Basic configuration of your open source application

• An open source application up and running

Page 6: Running open source PHP applications on you IBM i

© Proximity 2015

What is open source?

Page 7: Running open source PHP applications on you IBM i

© Proximity 2015

Free like a puppy

Page 8: Running open source PHP applications on you IBM i

© Proximity 2015

Open source solutions

• Source code made available for free under license

• License provides rights to study, change and distribute

• Core code is free, but expect to pay for anything beyond this• Extra features

• “Skins” for CMS systems

• Support

• Cost of maintaining the software• Your time

• Backups etc.

Page 9: Running open source PHP applications on you IBM i

© Proximity 2015

Open source solutions

• Can use any language or database, but PHP and MySQL is a popular combination

• PHP and MySQL are available on IBM i

Page 10: Running open source PHP applications on you IBM i

© Proximity 2015

Open source solutions

• We will install the following• Zend Server – PHP engine, Apache web server

• Zend DBi – MySQL database

• This gives us our iAMP “stack”• i = IBM i

• A = Apache

• M= MySQL

• P = PHP

IBM i

Apache MySQL

PHP

Applications

Page 11: Running open source PHP applications on you IBM i

© Proximity 2015

PHP on IBM i

• A great choice for web development• Easy to learn, especially for RPG developers

• PHP itself is open source and free to use

• Widely used

• Strong PHP community• Extensive resources and tools available

• Wealth of education materials

• Runs on IBM i• Integrates and works well with existing applications

• SQL database access, RPG / COBOL / CL program calls

• No 3rd party hardware required

Page 12: Running open source PHP applications on you IBM i

© Proximity 2015

PHP on IBM i

HTTP request

HTML, CSS, JS etc.

CSS, JavaScript

Page 13: Running open source PHP applications on you IBM i

© Proximity 2015

Installing Zend Server

Page 14: Running open source PHP applications on you IBM i

© Proximity 2015

Installing Zend Server – who are Zend?

• Founded by Andi Gutmans and Zeev Suraski in 1999

• Provides products and services relating to PHP• Zend Server

• Zend DBi

• Zend Studio

• Zend Framework

Page 15: Running open source PHP applications on you IBM i

© Proximity 2015

Installing Zend Server – what is Zend Server?

• The PHP engine (and not just on IBM i)

• Complete application server, including web server

• Brought to IBM i thanks to collaboration between IBM and Zend

• Basic version is free for IBM i (with forum support)

• Uses IBM HTTP Server (Apache)

• Comes complete with XML Toolkit to access native resources

Page 16: Running open source PHP applications on you IBM i

© Proximity 2015

Installing Zend Server – prerequisites

• Folder /usr/local exists

• Ports 10080 - 10083 are available

• Licensed programs and PTFs appropriate to the OS version are installed

• Zend Server not already installed• I will install on to a clean partition, you can verify it works

Page 17: Running open source PHP applications on you IBM i

© Proximity 2015

Installing Zend Server – prerequisites

For IBM i 6.1

• Current PTF Group for 5761DG1 (minimum SF99115 Group 13)

• FastCGI PTFs• 5761SS1 – SI36005

• 5761DG1 – SI36027

Licensed Program Product Option Description

5761SS1 33 Portable App Solutions Environment

5761SS1 30 Qshell

5761DG1 *BASE IBM HTTP Server for i

5733SC1 *BASE IBM Portable Utilities for i

5733SC1 1 OpenSSH, OpenSSL, zlib

Page 18: Running open source PHP applications on you IBM i

© Proximity 2015

Installing Zend Server – prerequisites

For IBM i 7.1

• Current PTF Group for 5770DG1 (minimum SF99368 Group 1)

Licensed Program Product Option Description

5770SS1 33 Portable App Solutions Environment

5770SS1 30 Qshell

5770DG1 *BASE IBM HTTP Server for i

5733SC1 *BASE IBM Portable Utilities for i

5733SC1 1 OpenSSH, OpenSSL, zlib

Page 19: Running open source PHP applications on you IBM i

© Proximity 2015

Installing Zend Server – prerequisites

For IBM i 7.2

• No additional PTFs required

Licensed Program Product Option Description

5770SS1 33 Portable App Solutions Environment

5770SS1 30 Qshell

5770DG1 *BASE IBM HTTP Server for i

5733SC1 *BASE IBM Portable Utilities for i

5733SC1 1 OpenSSH, OpenSSL, zlib

Page 20: Running open source PHP applications on you IBM i

© Proximity 2015

Installing Zend Server – installing the software

• Download the appropriate SAVF from the Zend website,

and FTP to the IBM i

• Choose your installation mode• Silent (a.k.a. Batch)

• Interactive

• We will choose interactive

RSTLICPGM LICPGM(6ZSVRPI) DEV(*SAVF) SAVF(QGPL/ZSVRSAVF6)

• Skip Zend DBi for now

Page 21: Running open source PHP applications on you IBM i

© Proximity 2015

Straw Poll

• What IBM i version are you running?

• Do you have Zend Server installed?

• Do you have any PHP / web development skills?

• Is your business using Open Source PHP applications on other platforms?

• Do you run Zend Server on Windows or Linux?

?

Page 22: Running open source PHP applications on you IBM i

© Proximity 2015

Installing Zend Server – completing the installation

• Zend Server Console• Web based UI for configuration and monitoring of Zend Server

• Navigate to http://<your_server_IP>:10081/ZendServer

• First time in there will be initial configuration to do • Accept the license agreement

• Select the appropriate launch profile

• Development

• Production

• Set the admin and developer user passwords

• Deploy source libraries

Page 23: Running open source PHP applications on you IBM i

© Proximity 2015

Exercise 1

Page 24: Running open source PHP applications on you IBM i

© Proximity 2015

Installing Zend Server

• Validate the installation• Navigate to http://<your_server_IP>:10080

• Zend Server Test Page should be displayed

• Check the subsystem on the IBM i• For ease, we will use Presto to provide 5250 access via a browser

• Navigate to http://<your_server_IP>:8022/presto/presto

• Log in with QSECOFR / Proximity!!

• GO ZENDSVR6/ZSMENU > 5 > 3 > Enter

Page 25: Running open source PHP applications on you IBM i

© Proximity 2015

Installing Zend DBi

Page 26: Running open source PHP applications on you IBM i

© Proximity 2015

Installing Zend DBi – what is Zend DBi?

• MySQL binaries, compiled to run on IBM i

• Functionally identical to MySQL

• Popular, widely used open source database

• The database of choice for many open source applications

• Zend DBi is the IBM i implementation of MySQL, delivered by Zend

Page 27: Running open source PHP applications on you IBM i

© Proximity 2015

Installing Zend DBi – installing the software

• Can be done as a second stage of the initial Zend Server installation

GO ZENDSVR6/ZSMENU

then take option 6 – ZendDBi Management menu and installation will start

• NOTE: QSECOFR privileges are required!

Page 28: Running open source PHP applications on you IBM i

© Proximity 2015

Installing Zend DBi – verifying the installation

• A new subsystem and daemon job are created, so check that the

subsystem is running

WRKACTJOB SBS(ZENDDBI)

• Can also access the command line interface via QSH or QP2TERM

QSH

thencd /usr/local/mysql/bin

mysql –u root

> show databases;

> use mysql;

> show tables;

Page 29: Running open source PHP applications on you IBM i

© Proximity 2015

Installing Zend DBi – verifying the installation

• After installation, the root user password should be set

> set password for ‘root’@’localhost’ = password(‘Proximity!!’)

> quit

• To access the command line interface, we now need to enter

mysql –u root --pass=‘Proximity!!’

Page 30: Running open source PHP applications on you IBM i

© Proximity 2015

Exercise 2

Page 31: Running open source PHP applications on you IBM i

© Proximity 2015

Installing Zend DBi

• Verify the installation• Navigate to http://<your_server_IP>:8022/presto/presto

• Log in with QSECOFR / Proximity!!

• GO ZENDSVR6/ZSMENU > 6 > 2

• Access the command line interface• QSH

• cd /usr/local/mysql/bin

• mysql –u root --pass=‘Proximity!!’

• > show databases;

• > use mysql;

• > show tables;

• > select * from user;

Page 32: Running open source PHP applications on you IBM i

© Proximity 2015

Zend Server Applications

Page 33: Running open source PHP applications on you IBM i

© Proximity 2015

Zend Server applications – what are they?

• Any software that you run using Zend Server• Open source applications

• Packaged, e.g. Magento, Drupal

• From Source, e.g. MediaWiki, Adminer

• Your own developed applications

• STREAM (delivery and transport management) in our case

• Once an application is configured, you can• View statistics and logging information relating to the application

• Define monitoring rules specific to the application

• Define caching rules specific to the application

Page 34: Running open source PHP applications on you IBM i

© Proximity 2015

Zend Server applications – how to define an application

• Applications are created automatically when you deploy from a package

• You can also manually define an application for• Your manually developed code

• Other applications installed from source

• We will cover this in detail shortly

Page 35: Running open source PHP applications on you IBM i

© Proximity 2015

Installing from a .zpk

Page 36: Running open source PHP applications on you IBM i

© Proximity 2015

Installing an application from a .zpk – overview

• Zend provide a number of pre-packaged Open Source applications that can be

installed directly from the Zend Server console• Magento – e-commerce

• Drupal – content management

• WordPress – content management / blog

• Joomla – content management

• phpMyAdmin – database admin tool

• phpBB – forum

• We have successfully deployed all of these, and use Drupal running on IBM i for all

our company websites

Page 37: Running open source PHP applications on you IBM i

© Proximity 2015

Installing an application from a .zpk – example

• We use Drupal extensively, so we will us this as an example• Access the Zend Server Console > Guide Page > click the Drupal icon

Page 38: Running open source PHP applications on you IBM i

© Proximity 2015

Installing an application from a .zpk – download

Page 39: Running open source PHP applications on you IBM i

© Proximity 2015

Installing an application from a .zpk – readme

Page 40: Running open source PHP applications on you IBM i

© Proximity 2015

Installing an application from a .zpk – app details

Page 41: Running open source PHP applications on you IBM i

© Proximity 2015

Installing an application from a .zpk – license

Page 42: Running open source PHP applications on you IBM i

© Proximity 2015

Installing an application from a .zpk – prerequisites

Page 43: Running open source PHP applications on you IBM i

© Proximity 2015

Installing an application from a .zpk – parameters

Page 44: Running open source PHP applications on you IBM i

© Proximity 2015

Installing an Application from a .zpk – summary

Page 45: Running open source PHP applications on you IBM i

© Proximity 2015

Installing an application from a .zpk – manual download

• Alternative approach, if you already have the .zpk file

• Access the Zend Server Console• Applications > Apps > Deploy Application

• Specify the location of the .zpk

• Remaining steps are as before

• Some config tweaks may be needed to ensure upload does not time out• Configurations > PHP > Filesystem and Streams

• Set default_socket_timeout to e.g. 300 seconds

• Configurations > PHP > Resource Limits and Tuning

• Set max_input_time to e.g. 300 seconds

Page 46: Running open source PHP applications on you IBM i

© Proximity 2015

Installing an Application from a .zpk – under the covers

• Source is deployed in /usr/local/zendsvr6/var/apps/http/__default__/0

• A .conf file is generated and saved in /usr/local/zendsvr6/etc/sites.d/http/__default__/0

• The .conf files are included within the Apache config file

• Provides the necessary alias information to let Apache locate the application

• Any staging and activation scripts defined in the package are executed

• Application config based on the supplied parameters

• Generation of MySQL database if required

Page 47: Running open source PHP applications on you IBM i

© Proximity 2015

Exercise 3

Page 48: Running open source PHP applications on you IBM i

© Proximity 2015

Installing an application from a .zpk

• Access the Zend Server Console• Navigate to http://<your_server_IP>:10081/ZendServer

• Log in with admin / Proximity!!

• Deploy an application• Click on the Guide Page tab

• Click on the application you want to deploy

• Follow the steps defined on the crib sheet provided for the application

• Launch the application and have a wander around

• In the Zend Server Console, check the application specific statistics

Page 49: Running open source PHP applications on you IBM i

© Proximity 2015

Installing from source

Page 50: Running open source PHP applications on you IBM i

© Proximity 2015

Installing an application from source – overview

• Any application written in PHP that uses MySQL for the database can be

implemented on IBM i

• The examples we will look at today are• Adminer – database admin tool

• SugarCRM – CRM tool

• Mantis BT – bug tracker

• Media Wiki – wiki

• We have successfully deployed and use Adminer and SugarCRM on IBM i

Page 51: Running open source PHP applications on you IBM i

© Proximity 2015

Installing an application from source – archives

• Typically, source will be provided in a .zip or .tar archive for ease of downloading

• Both of these types can be unpacked on the IBM i

Page 52: Running open source PHP applications on you IBM i

© Proximity 2015

Installing an application from source – unpacking .zip files

• Download the .zip file to the IFS, go into QSH or QP2TERM and enter

jar tf <myFilePath>

to list the contents of the archive

• Navigate to the location that you want to extract to and enter

jar xf <myFilePath>

to extract the contents

Page 53: Running open source PHP applications on you IBM i

© Proximity 2015

Installing an application from source – unpacking .tar files

• Download the .tar file to the IFS, go into QSH or QP2TERM and enter

tar -tf <myFilePath>

to list the contents of the archive

• Navigate to the location that you want to extract to and enter

tar -xf <myFilePath>

to extract the contents.

• If you have a .tar.gz file, extract the .tar file from it before transferring to the server

Page 54: Running open source PHP applications on you IBM i

© Proximity 2015

Installing an application from source – unpacking .tar files

• The native tar command can be problematic, as file paths are limited to 100 characters

• If you get a @longlink file after unpacking, the path limit has been exceeded and some files will be

missing or wrongly named

• There are two ways to address this …

• The easy approach – save the .tar file to the IFS root and unpack, then move to the correct location

• This will only work if the file paths are now less than 100 characters

• The hard approach – install the Open Source binary for the GNU version of the tar command

• More information on how to do this is available at …

• http://www-01.ibm.com/support/docview.wss?uid=nas8N1011528

• http://www.youngiprofessionals.com/wiki/index.php/PASE/OpenSourceBinaries

Page 55: Running open source PHP applications on you IBM i

© Proximity 2015

Installing an application from source – example

• Adminer is a lightweight MySQL management tool

• Single script file, so easy to install

Page 56: Running open source PHP applications on you IBM i

© Proximity 2015

Installing an application from source – create folder

Page 57: Running open source PHP applications on you IBM i

© Proximity 2015

Installing an application from source – create folder

Page 58: Running open source PHP applications on you IBM i

© Proximity 2015

Installing an application from source – authority

Page 59: Running open source PHP applications on you IBM i

© Proximity 2015

Installing an application from source – upload

Page 60: Running open source PHP applications on you IBM i

© Proximity 2015

Installing an application from source – definition

• Access the Zend Server Console > Applications > click Define Application

Page 61: Running open source PHP applications on you IBM i

© Proximity 2015

Installing an application from source – definition

Page 62: Running open source PHP applications on you IBM i

© Proximity 2015

Installing an application from source – definition

Page 63: Running open source PHP applications on you IBM i

© Proximity 2015

Installing an application from source – launch

Page 64: Running open source PHP applications on you IBM i

© Proximity 2015

Exercise 4

Page 65: Running open source PHP applications on you IBM i

© Proximity 2015

Installing an application from source

• Create a folder within htdocs for the application and set the folder authority• Navigate to http://<your_server_IP>:8022/presto/presto

• Log in with QSECOFR / Proximity!!

• wrklnk '/www/zendsvr6/htdocs/*‘

• mkdir ‘/www/zendsvr6/htdocs/<your_folder_name>’

• Take option 9=Work with Authority against the new folder

• Grant user QHTTPSVR *RWX data and *ALL object authority

• Upload the source• Use FileZilla to transfer the source, .zip or .tar to the new folder

Page 66: Running open source PHP applications on you IBM i

© Proximity 2015

Installing an application from source

• Unpack the source (if necessary)• For .zip files

• In QSH or QP2TERM

• cd /www/zendsvr6/htdocs/<your_folder_name>

• jar xf <your_file_name>

• For .tar files

• In QSH or QP2TERM

• cd /www/zendsvr6/htdocs/<your_folder_name>

• tar –xf <your_file_name>

Page 67: Running open source PHP applications on you IBM i

© Proximity 2015

Installing an application from source

• Define the Application within Zend Server• Navigate to http://<your_server_IP>:10081/ZendServer

• Log in with admin / Proximity!!

• Click on the Applications tab

• Click Define Application

• Follow the steps defined on the crib sheet provided for the application

• Launch the application and have a wander around

• In the Zend Server Console, check the application specific statistics

Page 68: Running open source PHP applications on you IBM i

© Proximity 2015

Troubleshooting

• Most common problems are authority related

• Try granting QTMHHTTP full authority to the application folder and all contents

• Check the logs!

• PHP log in Zend Server console

• Apache logs in /www/zendsvr6/logs

• For specific applications refer to user documentation, or Google

Page 69: Running open source PHP applications on you IBM i

© Proximity 2015

Zend Server Console

Page 70: Running open source PHP applications on you IBM i

© Proximity 2015

Zend Server Console – overview – dashboard

• Default landing page when you log into the console

• Displays overview information for the server• Server statistics

• System events

• Information can also be filtered per application

Page 71: Running open source PHP applications on you IBM i

© Proximity 2015

Zend Server Console – applications

• Lists defined and deployed applications

• Displays information for individual applications• Application status

• Summary information

• Provides access to application monitoring and caching rules

• Provides access to virtual host configuration and PHP library management

Page 72: Running open source PHP applications on you IBM i

© Proximity 2015

Zend Server Console – configurations

• Configuration of various aspects of Zend Server

• Components – enable/disable and configure Zend Server Components

• Deployment – required for us!

• Important for app performance – Data Cache, OPCache, Page Cache

• Important for monitoring – Code Tracing, Monitor, Statistics

• PHP – configure installed PHP components

• Z-Ray – fantastic tool for developers – more later

• IDE Integration – allows close coupled debugging from Zend Studio

• Monitor – additional configuration for the Zend Monitor component

Page 73: Running open source PHP applications on you IBM i

© Proximity 2015

Zend Server Console – administration

• Day-to-day administration of Zend Server

• Servers – allows restart of server and shows any server level errors

• Audit Trail – shows log of changes made to the server

• Users – change passwords for admin and developer users

• Web API – maintenance of Web API keys, used in Zend Studio integration and when

accessing the server via its API layer (e.g. from Jenkins or other CI tools)

• License – shows license information

• Settings – server level configuration

Page 74: Running open source PHP applications on you IBM i

© Proximity 2015

Zend Server Console – Z-Ray Live

• Developer tool that gives insight into PHP code by delivering detailed

information into a browser component

• Information includes• PHP functions

• SQL queries

• Request variables

• Errors and warnings

• Server events

• Memory usage

• Z-Ray Live allows this data to be viewed for requests from devices where browser

component is not appropriate, e.g. mobile applications, API calls

Page 75: Running open source PHP applications on you IBM i

© Proximity 2015

Configuring Zend Server

Page 76: Running open source PHP applications on you IBM i

© Proximity 2015

Configuring Zend Server – top tips

• As seen on PowerWire.eu

• Character Set Configuration

• Multibyte Support

• Compression

• Bonus Tip! Memory Pools and Run Priorities

• Available on our website: http://proximity.co.uk/php-on-i

Page 77: Running open source PHP applications on you IBM i

© Proximity 2015

Configuring Zend Server – character sets

Get this right now and you’ll never have character set problems

In /www/zendsvr6/conf/httpd.conf

DefaultFsCCSID 00285

CGIJobCCSID 00285

DefaultNetCCSID 01208

AddCharset UTF-8 .htm .html .xml

In /www/zendsvr6/conf/fastcgi.conf

SetEnv=“CCSID=1208” SetEnv=“LANG=C”

Page 78: Running open source PHP applications on you IBM i

© Proximity 2015

Configuring Zend Server – character sets

In /usr/local/zendsvr6/share/ToolkitAPI/toolkit.ini

encoding = “UTF-8”

In the console, go to Configurations > PHP > ibm_db2

ibm_db2.i5_dbcs_alloc – set to use expanded allocations

Page 79: Running open source PHP applications on you IBM i

© Proximity 2015

Configuring Zend Server – multibyte support

Means you’re not limited to ASCII

In the console, go to Configurations > PHP > mbstring

mbstring.http_output – set to UTF-8

mbstring.internal_encoding – set to UTF-8

mbstring.encoding_translation – set to On

mbstring.http_input – set to Pass

mbstring.language – set to neutral

Page 80: Running open source PHP applications on you IBM i

© Proximity 2015

Configuring Zend Server – compression

A very quick win – speeds up response times of web pages

In /www/zendsvr6/conf/httpd.conf

LoadModule deflate_module /QSYS.LIB/QHTTPSVR.LIB/QZSRCORE.SRVPGM

AddOutputFilterByType DEFLATE application/x-httpd-php

application/json text/css application/x-javascript

application/javascript text/html

Page 81: Running open source PHP applications on you IBM i

© Proximity 2015

Configuring Zend Server – memory pools and run priorities

Worth considering for Production systems where resources are shared with legacy applications

Use WRKSHRPOOL to define one of the shared pools as “Zend”

Use CHGSBSD to allocate the pool to subsystem ZENDSVR6

Change the Zend Server Class using WRKCLS ZENDSVR6/*ALL to set Run Priority to 20,

equivalent to interactive jobs

Change the HTTP Server Class using WRKCLS QHTTPSVR/QZHBHTTP to set Run

Priority to 20, equivalent to interactive jobs

Page 82: Running open source PHP applications on you IBM i

© Proximity 2015

Any questions?

Page 83: Running open source PHP applications on you IBM i

© Proximity 2015

Thanks

• i-UG for the opportunity

• Steve Bradshaw for the hardware and support

• You for attending