Published on System iNetwork (http://systeminetwork.com)
Open-Source Web Dev Stack in i5/OS
By tzura
Created Feb 1 2008 - 08:00

By:
Erwin Earley [1]

The ability to deploy web-based applications continues to be a major focus of many organizations. The deployment stack based on open-community applications is the LAMP stack (LAMP stands for the Linux operating system, Apache Web Server, MySQL database server, and PHP scripting language). The LAMP stack, sometimes referred to as the open-source web platform, has gained popularity among web developers as a low-cost, reliable platform for web-based applications. A large body of LAMP-based applications is available in the open community to provide functions such as blogs, bulletin boards, e-commerce, portals, and customer relationship management.

Until now, System i customers who wanted to deploy LAMP-based solutions had to implement a Linux partition. Last year's incorporation of PHP into i5/OS and this year's announcement of MySQL for i5/OS mean that System i customers can now implement an i5/OS variant of the LAMP stack, referred to as iAMP (i5/OS, Apache, MySQL, PHP). With iAMP, customers can leverage the wide portfolio of open-community applications directly in i5/OS.

This article takes you through the steps required to implement the iAMP stack in i5/OS. In addition to setting up the iAMP stack, I show you how to install an open-community application.

Structure and Prerequisites

To help you understand what needs to be installed, let's look at the structure of the iAMP stack (Figure 1 [2]). As you can see, Apache, MySQL, and PHP need to be set up in the Portable Application Solutions Environment (PASE) environment.

The iAMP stack can be implemented only in V5R4 and requires a number of LPPs installed in i5/OS, as Figure 2 [3]shows. Note that the requirement for V5R4 is because only V5R4 supports MySQL. If you intend to use only the PHP support (typically to develop your own applications against i5/OS resources), you can also implement on V5R3 — Zend Core is supported on both releases.

Install Zend Core

Zend Core is the engine that provides the ability to execute PHP applications in i5/OS. The Zend Core installation includes the following:

  • installation of Apache in the PASE environment
  • installation of Zend Core in the PASE environment
  • configuration of port 89 to be forwarded to Apache in the PASE environment; you can think of port 89 as the PHP port for i5/OS
  • installation of the I5_COMD process in i5/OS to satisfy requests for server-side resources from PHP applications

"PHP Installation, Configuration [4], and Setup," page ProVIP 33, provides details about Zend Core. For the purposes of this article, let me summarize the Zend Core installation here:

  • Obtain Zend Core from Zend's website (zend.com).
  • Extract the Zend Core save file from the downloaded zip file.
  • Upload the save file to i5/OS.
  • Execute the RSTLICPGM command against the save file.
  • Answer the installation prompts.

Implement MySQL in i5/OS

Installing Zend Core in i5/OS provides us with half of the iAMP stack (i.e., Apache and PHP). At this point, you could develop your own web-based applications against i5/OS resources. However, if you want to deploy existing open-community applications without change, you must install MySQL, because most open-community PHP applications use MySQL as the data repository for the application.

As with PHP, MySQL for i5/OS runs in the PASE environment. Figure 3 [5] shows an overview of this architecture. The steps for installing MySQL are similar in many respects to the steps for installing Zend Core. To begin with, you need to download MySQL for i5/OS. There are two versions, a community server version and an enterprise version. The difference between these two versions is in the support model and licensing of the product. This article discusses the implemention of the community server version, a freely available version of the open-community database engine.

The download page for the MySQL Community Server is at dev.mysql.com/downloads/mysql/5.0.html [6]. Perform the following steps to download the MySQL package:

  1. Click the Download button under MySQL Community Server.


  2. Scroll down the platform list until "IBM i5/OS (SAVF packages)" is displayed. Click the link.


  3. Click "Pick a mirror" for "i5/OS (POWER, 64-bit)."


  4. Choose a mirror site and download the package.

Installing MySQL in i5/OS

After you have downloaded the zip file to your PC, you are ready to perform the MySQL installation. You need to upload the MySQL save file to i5/OS, restore the MySQL installation library, and then perform the actual MySQL installation. First, upload the save file to i5/OS:

  1. Start an FTP session to i5/OS.


  2. Enter binary mode (bin).


  3. Change the name format (quote site namefmt 1).


  4. Upload the file (put mysql.savf /qsys.lib/qgpl.lib/mysql.savf).


  5. Exit FTP (quit).

The uploaded zip file contains an i5/OS library that includes a tar file of the MySQL files along with an installation program. You use the RSTLIB command to restore the library. As an example:

RSTLIB SAVLIB(MYSQLINST) DEV(*SAVF)
   SAVF(MYSQL) MBROPT(*ALL) ALLWOBJDIF(*ALL) 

After you restore the library, you are ready to perform the actual installation of MySQL by issuing the following command:

MYSQLINST/INSMYSQL

Press F4 to display the following prompts for the MySQL installation (Figure 4 [7]). The responses provided to the prompts represent the following information to the installation program:

  • Installation Directory: the IFS directory in which the MySQL files will be written
  • Data Directory: the IFS directory in which MySQL data files (databases and tables) will be written
  • Owning User Profile: an i5/OS user profile that will be created as part of the installation and will be set as the owning profile for the installation files

A typical MySQL installation uses the default responses to the prompts. On most i5/OS systems, the installation runs for several minutes without any messages or user interaction. After the installation is completed, a number of diagnostic messages are displayed.

Start the MySQL Server

Remember that MySQL runs in the PASE environment. Perform the following steps to start the MySQL server:

  1. Enter the PASE environment (call QP2TERM).


  2. Change directory to the directory in which the binary files for the MySQL server were written (cd /usr/local/mysql/bin).


  3. Start the MySQL server (./mysqld_safe -u root &).

Enable Support for PHP MySQL Extensions

To execute PHP programs that use the MySQL database engine, you need to enable the MySQL extensions in Zend Core. You can do this in one of two ways — either by editing the Zend Core configuration file directly or by using the web-based administration interface.

First, let's look at making the changes directly to the configuration file. By default, the Zend Core configuration file (named php.ini) is in the \usr\local\Zend\core\etc directory. You need to edit the file and look for the following two entries:

;extension=mysql.so
;extension=mysqli.so 

The first extension is for MySQL, and the second extension is for MySQL Improved. You need to enable both extensions by removing the semicolon at the start of the line. After the extensions have been enabled, restart Zend Core through the Zend Core Setup Utility (GO ZENDCORE/ZCMENU).

The other way to enable the extensions is with the web-based Zend Core Administration interface. You can start the interface by directing a web browser to http://iseries:89/ZendCore. After you provide the password for the administration interface, select Configuration|Extensions and scroll down the list until you see the MySQL extensions (Figure 5 [8]).

To enable the extensions with this interface, click the extension icon (it's the second icon on the right side). The extension indicator needs to be at the top of the extension indicator. When the extension has been enabled, save the settings by clicking Save Settings and restart the server by clicking Restart Server.

Implement Open-Community Applications

At this point, you have actually implemented your own i5/OS variant of the LAMP stack. The three components — Apache, MySQL, and PHP (Zend Core) — are all installed in the PASE environment and ready for you to use to deploy applications. Let's spend the rest of the article taking a look at how to use the stack to deploy open-community applications.

A large number of open-community applications are just waiting for you to deploy them in i5/OS. They are available from such sites as PHPFreeks (phpfreeks.com [9]), SourceForge (sourceforge.net [10]), HotScripts (hotscripts.com [11]), PHPJunkyard (phpjunkyard.com [12]), and PHPFreebies (php-freebies.com [13]). Open-community applications fall into a large number of categories, including blogs (in which entries are entered in chronological order and displayed in reverse chronological order), portals (which offer a broad array of resources and services), e-commerce sites (which facilitate purchase of products across the Internet), and wikis (which let users freely create and edit web page content), just to name a few.

The method for implementing open-community applications using the iAMP stack can generally be broken into the following steps:

  1. Download the application to your PC.


  2. Use a zip utility to unzip the application's tar file.


  3. Copy the tar file (resulting from the previous step) into the IFS (typically into the /www/zendcore/htdocs directory).


  4. Enter the PASE environment (call QP2TERM).


  5. Navigate to the directory in which the uploaded file resides.


  6. Expand the archive file (tar -xvf application.tar).


  7. Point a web browser to the application's setup/configuration program (http://systemi:89/application).

Keep in mind that many of the files that you download for the open-community applications will have two levels of compression. Typically, you will have to uncompress the first level of compression before you upload it to the IFS. Many compression utilities are available — one that I recommend is 7ZIP (7-zip.org/download.html [14]).

Let's finish our discussion by looking at deployment of an actual open-community application. As an example, let's install the phpMyAdmin program (Figure 6 [15]), which you can use to manage the MySQL environment from a web browser. Here are the steps to implement the application:

  1. Download the phpMyAdmin application to your PC (phpmyadmin.net/home_page/downloads.php).


  2. Uncompress the downloaded file.


  3. Upload the resulting tar file to the IFS in the root of the Apache web server (/www/zendcore/htdocs).


  4. Start a 5250 session and enter the PASE environment (call QP2TERM).


  5. Untar the file (tar -xvf phpMyAdmin-2.11.1-english.tar).


  6. Create a symbolic link to give an easier-to-remember name to the application (ln -s phpMyAdmin-2.11.1-english phpMyAdmin).


  7. Create a directory for local configuration information:

  8. cd /www/zendcore/htdocs/phpMyAdmin
    mkdir config
    chmod o+rw config

  9. From a web browser, run the phpMyAdmin setup script http://systemi:89/phpMyAdmin/scripts/setup.php.


  10. Use the setup utility to add a server definition by clicking Add under Servers.

At this point, you are ready to access the phpMyAdmin application by pointing a browser to http://systemi:89/phpMyAdmin.

iAMP in Under an Hour

This article has walked through the steps for establishing your own open-community web development/deployment stack with Zend Core and MySQL. Additionally, I covered the installation of an open-community application to show the ease with which this support lets you leverage the wide collection of readily available open-community applications that you can now implement directly in i5/OS. If you follow these steps, it is likely that you can have your own iAMP stack running on your system in less than 60 minutes.

Erwin Earley is an advisory software engineer in the IBM lab located in Rochester, Minnesota, and heads up the Open Source Technologies Center of Competency for System i within the System i Technology Center. At that center, he provides education and enablement services for open-source-related technologies on System i, including Linux, MySQL, and Zend's PHP.

© 2010 Penton Media, Inc.

Source URL: http://systeminetwork.com/article/open-source-web-dev-stack-i5os

Links:
[1] http://systeminetwork.com/author/erwin-earley
[2] http://systeminetwork.com/artarchiveImages/2008/feb/21153-fig1.gif
[3] http://systeminetwork.com/artarchiveImages/2008/feb/21153-fig2.gif
[4] http://systeminetwork.com/article.cfm?id=21143
[5] http://systeminetwork.com/artarchiveImages/2008/feb/21153-fig3.gif
[6] http://dev.mysql.com/downloads/mysql/5.0.html
[7] http://systeminetwork.com/artarchiveImages/2008/feb/21153-fig4.gif
[8] http://systeminetwork.com/artarchiveImages/2008/feb/21153-fig5.gif
[9] http://www.phprocket.com/?forward_domains=1
[10] http://sourceforge.net/
[11] http://www.hotscripts.com/
[12] http://phpjunkyard.com/
[13] http://www.php-freebies.com/
[14] http://7-zip.org/download.html/
[15] http://systeminetwork.com/artarchiveImages/2008/feb/21153-fig6.gif