A PHP ‘Hello World’ Script Using Zend Core for i5

September 23, 2009

Tutorials

You’ve successfully installed the Zend Core for i5. Now what? The process of developing PHP scripts may not be obvious to System i developers familiar with RPG and COBOL. Let’s take a look at the basic steps needed to start writing PHP scripts on System i.

See Where Zend Core is Located

  1. Open iSeries Navigator. You will need all components of iSeries Navigator installed so you can access the IFS.
  2. Navigate to /www/zendcore. This is the home of Zend Core.
  3. Navigate to /www/zendcore/htdocs. This is where you put all HTML and PHP files to be viewed in a browser.

Make Sure the Zend Core is Running

  1. Open a browser and navigate to http://myas400name:89/. Replace myas400 with either the network name or the URL of your System i.
  2. If you see the welcome page, Zend Core is running.
  3. If you don’t see the welcome page, stop and re-start the Zend Core.
    • Sign on to your System i.
    • Enter the command GO ZENDCORE/ZCMENU.
    • Take option 5 Service Management menu.
    • Take option 9 End i5_COMD service. Wait for the messages.
    • Take option 5 Stop Apache server instances. Wait for messages.
    • Take option 2 Stop Zend Core Subsystem. Wait for messages.
    • Take option 1 Start Zend Core Subsystem. Wait for messages.
    • Take option 4 Start Apache server instances. Wait for messages.
    • Take option 8 Start i5_COMD service. Wait for messages.
    • You don’t always need to stop all three services and then re-start them. When you become more familiar with the services, you can start and stop each service as needed.

Set Up Zend Studio i5 Edition

  1. Register to create an account with Zend: https://www.zend.com/en/user/login. Click on the “Create a Zend Account” link.
  2. Download the Zend Studio i5 Edition: http://www.zend.com/en/products/studio/downloads. Click the “Zend Studio i5 Edition” radio button and select the “Windows x86″ package.
  3. Download and install the studio. Take default options (if any).
  4. Sign on to your System i.
  5. Enter the command DSPSYSVAL QSRLNBR.
  6. Open Zend Studio.
  7. Click the “purchase license” link in the Help menu.
  8. Use the serial number of your System i to create a license (say yes to the email option).
  9. Enter your license in Zend Studio.

Set Up Your System i for SSH Connections

You can get detailed instructions for setting up SSH at http://kb.zend.com/index.php?View=entry&EntryID=389. You can also find the instructions by going to the Zend Support Center and searching for “SSH i5″.

Create a Personal Development Space

  1. Create an SSH Only connection to myas400.
    • Click the Remote Systems tab.
    • Click the “Define a connection to a remote system” icon. Or, you can right click inside the Remote Systems area and choose “New Connection.”
    • Click the SSH Only option to highlight it, then click the Next button.
    • Enter your System i name for host name, connection name, and description. You might need to use a URL if your network doesn’t recognize your System i by name.
    • Click the Finish button. Say yes to creating or accepting keys.
  2. Click on the new connection and sign in to your System i.
  3. Navigate to /www/zendcore/htdocs.
  4. Right click on htdocs and select the option to create a new folder (e.g., myfolder).
  5. Open a browser and navigate to your development folder: http://myas400name:89/myfolder/

Create Hello World Scripts

Hello World Script. Save this script as hello_world.php in /www/zendcore/htdocs/myfolder. To view the page, open a browser and navigate to http://myas400name:89/myfolder/hello_world.php.

<?php
  Print ("Hello, World! This is my first PHP script on the System i.");
?>

Hello DB2 script. Save this script as hello_db2.php in /www/zendcore/htdocs/myfolder. To view the page, open a browser and navigate to http://myas400name:89/myfolder/hello_db2.php. Obviously, the script provided here is only a template.

<html>
  <head></head>
  <body>
  <table border = "1">
    <tr>
      <th>Column Name 1</th>
      <th>Column Name 2</th>
      <th>Column Name 3</th>
    </tr>
    <?php
        $conn = i5_connect("myas400name", "myusername", "mypassword");
        $query = i5_query("SELECT * FROM MYLIB/MYFILE");
        if($query) {
            while ($values = i5_fetch_row($query, I5_READ_NEXT)) {
                $row_count++;
                print ("<tr><td>$values[0]</td><td>$values[1]</td><td>$values[2]</td></tr>");
            }
        }
    ?>
  </table>
</body>
</html>

What Next?

Learn the Basics

Make Use of Zend Resources

Check Out the WEB400 List

Get the IBM Redbook

3 Responses to “A PHP ‘Hello World’ Script Using Zend Core for i5”

  1. m_sergey_p Says:

    I See i can expabd my knowledge got in http://phpforms.net/tutotials

  2. Jonathanz Says:

    thanks very much.