Wednesday, September 15, 2010

Updating Zend Framework on IBM i

Several IBM i customers have asked me about Zend Framework. Everything from should we adopt to how do we do it? I will talk about updating ZF in this piece but for a lack of sounding impertinent I have to reply to their inquiries about adoption with “It depends…”

It is no secret that the brass ring of PHP coders is framework based development. It’s not so much that Zend purports this approach as it is the community. The Zend Framework team has done an admirable job responding to the community with an enterprise grade solution. If you look at what solutions were around before Zend Framework you can easily see the need for such a solution. In its early stages, Zend Framework was created to address the plethora of frameworks that were being developed concurrently and were grossly incompatible. In other words, applications built with Cake would have to be modified in order to seamless integrate with Smarty. What’s even more concerning is the number of PHP developers out there who insist on creating their own framework for each company they work for. Since each company is different, they should get their own framework is the rationale. The reality is, however, a generic Framework that has attributes like modular design principles and a use at will architecture may very well be the right approach. But at which time? Many i5 shops are still kicking the tires of PHP and that’s OK. When they hear about Zend Framework they want to know more. I do not try to discourage folks from looking at Zend Framework, but do try to enlighten them as to the realities. And the reality is that you can use Zend Framework with just a cursory knowledge of PHP. But to understand Zend Framework you need a little more background in PHP and OOP. This is where RPG programmers get into trouble. Believe me, after 15 years developing RPG programs I too struggle with ZF and OOP. But that is because I feel I have to understand all the code before I use it. If you wait until you understand all of ZF before you use it, you may never get the chance to start taking advantage of its principles. So, let’s start in the beginning, updating your ZF implementation.

ZF upgrade process for IBM i

Zend Framework, the fabulously useful framework for building applications with PHP comes with Zend Server. But, the current version of Zend Server that installs on IBM i may not be as current as the version you wish to install. Or, maybe you would prefer to back-level the current version of ZF to be compliant with an applications requirement. Most users of the Zend Framework are far more interested in a more contemporary version of ZF as the development team is running fast and furious on new features. So, as there may be various ways to perform the update, the method identified here strikes me as the most efficient. As I try to maintain my position as one of the laziest programmers in New Lenox, techniques like this help me maintain a significant distraction rate while the computer does all of the heavy lifting! If you would like to share your favorite approach, please feel free to comment! This article will discus, in detail, the steps you can use to update the ZF library on your IBM i. In case you were wondering, this short snippet of ZF code can show you what version of ZF you have installed:
Let’s get a little housekeeping squared away. First, you will need to download the most current "stable" distribution from the ZF home page (http://www.zendframework.com/download/latest). As of this writing, 1.10.8 is stable. I chose 1.10.8 because I like things that are stable. That's why I am on an IBM i! If you prefer an older release you can check those out at the Zend Framework Archive . I brought this file down using the tar.gz option and not the .zip. I’ll explain why in a bit. You will also need all of the prerequisite License Programs as indicated by the Zend Server for IBM i Installation Guide available as a no-charge download at Zend.com. Last but not least, BACKUP YOUR WORK! Anyone who assumes all will be well with the universe when treading new ground has never met Murphy. As a ¼ Irishman I must acknowledge that little bugger and pay him his due. So, even a measly save file in QGPL is better than nothing. It sure wouldn’t hurt to dust off those operations skills and see if you can run the tape drive or at least make sure operations has backed up the IFS in the last few days (weeks, months, years?). The directory we will be messing with is ‘/usr/local/zend’ I would heartily recommend using the SAV command and saving that entire directory to a save file and then copying the save file somewhere. Tape is preferable; a network file share is OK too, as long as it gets backed up!


OK, with the housekeeping done I can climb down from my operations soap box and we can get busy. First you need the download file. This file can be brought down in either the windows .zip format or the Linux/Unix tar.gz. Since I am going to leverage the PASE environment to do my dirty work I chose the tar.gz format. But let’s explore what the heck that really means. Tar is a Unix command that stands for, believe it or not, Tape Archive. This is a method supported by nearly all Unix based systems and since PASE is an AIX runtime, it is no exception. PASE appears to fully supports the tar command and most of its options. Ok, that explains the .tar extension, but what the heck is the .gz mean to me? Ah, this is a little more interesting. In windows land we typically use a utility like PKZip to archive and compress all at the same time. In Unix land, we have two steps. I indicated that the tar command archives the files into a single tape file. The .gz stand for GNU-Zip which then compresses the file. So, since the file was archived first and then compressed, you need to do the reverse when opening up the files for access. As I indicated I like PKZip for getting rid of the .gz extension. Oh, and do not trust Windows to tell you the extension. You may need a DOS prompt to show you the real file name is: ZendFramework-1.10.8PL1.tar.gz.


So, chose your favorite PC based compression utility, open the GNU-Zip and extract the tar to a local directory. With the file in a local directory it is possible to FTP the file to a temporary directory like, /usr/local/zendsvr/share/ZFtemp on the i. That should be all you need your PC for! You can use an FTP utility if you like but I am still pretty comfortable with the command line options. Here is my script for FTP from the DOS prompt on my PC and I typically put things I need to FTP in a directory off C: called temp:

cd /usr/local/zendsvr/share/ZFtemp
lcd c:\temp

put ZendFramework-1.10.8.tar


With the file on the IFS we can now take advantage of the IBM i and let it rock through the rest of the process. So let’s rename the current ZF directory. It should be located in /usr/local/zendsvr/share/ and is called, simply enough, Zend Framework. From the i5 command line issue the WRKLNK command for the /usr/local/zendsvr/share/* directory and page down till you see Zend Framework. Take option 7 to rename the directory to something useful like ZendFramworkOldVersion or something like that. This technique may come in VERY handy should you need to back out the upgrade for any particular reason. Now take that temp directory and rename it to the proper Zend directory, or something you prefer.
From here you may start a PASE Shell by using the CL command CALL QP2TERM. This will start a PASE shell interface and any Unix command line loving geek out there will start to feel right at home since you are now, essentially, at an AIX command line interface. Remember that PASE is an AIX runtime so while it supports MANY AIX commands it may not necessarily support all of them. Check out the PASE command reference on the IBM website. From here, navigate to the directory where you wish to install Zend Framework. I chose the same directory it was already in so I would not have to adjust any hardcoded scripts or includes in the PHP.ini. The command would look something like cd /usr/local/zendsvr/share/ZendFramework and then issue the command to unzip the ZF file system. There are MANY files that make up ZF and to use netserver to do the drag and drop might be cumbersome. Ultimately, it’s up to you.

To unzip the file, or actually untar, the command is: tar -xvf ZendFramework-1.10.8PL1. let’s look at this command as it is a little different than your typically CL command. The –xvf represents switches that control the behavior of the command. x means extract the contents, v means give detailed messages about the extraction and f means the next parameter in the command is the file name of the archive. More information about tar can be found on the GNU website and also the manual .
Now that the unzip is complete there is only one step left to update the php.ini file. If you plan to use Zend Server for IBM i to load the path to the Zend Framework library, then update the path directive via the Zend Server Admin Interface. Log in to Zend Server and Navigate to the Server Setup tab and then the directives sub-tab. Click the twistie for Paths and Directories to reveal the php.ini directive for “include_path”. There should already be an entry for Zend Server in there. There is no change necessary as long as the new ZF files in the same directory. If another directory is selected, simply edit the value in the box to the right of the directive, click save changes and restart Zend Server. You are off to the races!