Installing Community PHP on IMB i
January 8, 2020

Installing Community PHP on IBM i

PHP Development
Modernization
Back to top

How to Install Community PHP on IBM i

Now that community PHP is available for IBM i, you may be wondering how to set up the open source operating system on the platform. Unlike the single-step install (RSTLICPGM) that delivers a certified PHP stack as part of Zend Server setup, community PHP requires installation and configuration of multiple packages.

This blog will provide a step-by-step approach to the installation of a development/solution stack based on community PHP, related packages, and extensions. Along the way, commands will be used to validate the various components of the community stack. For purposes of this blog, we used a container on an IBM i system. See Getting Started with Community PHP blog for details on how to establish a container.

Steps to Set Up the Community PHP Stack

  1. Define package repository (log for further instruction).
  2. Installation of the php-core package.
  3. Installation/Configuration of Web Server.
  4. Configuration (and possibly installation) of database drivers.

Community PHP Installation Instructions

As mentioned above, community PHP and its extensions are provided as a number of separate RPMs. The first two RPMs to install are php-common and php-cli. The base packages for community php are 'php-common' and 'php-cli'. The 'yum install' command will be used to install these packages:

yum install php-common php-cli

The system will output messages indicating the actions that will be taken:

Setting up Install Process

Resolving Dependencies

--> Running transaction check

---> Package php-cli.ppc64 0:7.3.12-0 will be installed

---> Package php-common.ppc64 0:7.3.12-0 will be installed

--> Finished Dependency Resolution

 

Dependencies Resolved

 

=======================================

 Package       Arch     Version        Repository           Size

=======================================

Installing:

 php-cli       ppc64    7.3.12-0    repos.zend.com_ibmiphp     12 M

 php-common    ppc64    7.3.12-0    repos.zend.com_ibmiphp    290 k

 

Transaction Summary

==========================================

Install       2 Packages

 

Total download size: 12 M

Installed size: 57 M

Is this ok [y/N]:

Type 'y' and press the <ENTER> key to install the specified packages.  Diagnostic messages such as the following will be output to indicate the actions taken and the completion of the installation:

Downloading Packages:

php-cli-7.3.12-0.ibmi7.2.ppc64.rpm                          |  12 MB  00:00    

Running Transaction Check

Running Transaction Test

Transaction Test Succeeded

Running Transaction

  Installing : php-common-7.3.12-0.ppc64                     1/2

  Installing : php-cli-7.3.12-0.ppc64                        2/2

Installed:

  php-cli.ppc64 0:7.3.12-0           php-common.ppc64 0:7.3.12-0            

Complete!

Installation of PHP can be confirmed by running the 'php' command with the '-v' flag:

php -v

The version information for php should be displayed:

PHP 7.3.12 (cli) (built: Dec  1 2019 17:37:53) ( NTS )

Copyright (c) 1997-2018 The PHP Group

Zend Engine v3.3.12, Copyright (c) 1998-2018 Zend Technologies

The installation shown above installed the core PHP engine as well as the Command Line Interface (CLI).  At this point, enough has been installed that we can now validate the functionality of PHP. One way to validate would be write a short PHP script and include the path to the php executable:

#!/QOpenSys/pkgs/bin/php -q

<?php

   echo "Hello World';

?>

If you have explored PHP in the past, then you may recognize the starting php tab (<?php) as well as the close tag (?>). The 'echo' statement is used to generate output. The first line in the example, and more specifically the first two characters, which is the remainder of the line provides a path to the executable to be used to interpret the rest of the file. When the file is executed it will generate the indicated output (i.e., 'Hello World').

If you don't want to create a file, then you can use the CLI directly by entering:

/QOpenSys/pkgs/bin/php -q

The above will place you in the CLI of PHP and everything entered will be interpreted by the PHP engine until the <CTRL><D> key sequence is entered.  At this point you can simply enter the equivalent of a PHP script such as the one shown above (If you want to get a little more creative with the validation, instead of a simple 'hello world' string, execute the 'phpinfo()' function to output a variety of information related to the PHP environment.

While the Command Line Interface of PHP can be useful for certain tasks, it is likely that you will actually want to use PHP with a web server. 

Back to top

Next Steps

Stay tuned for our next blog on the guidelines to the configuration of Apache for PHP and configuration of NGINX for PHP. If you’d like to go through this process with an expert, the team at Zend by Perforce is ready to help you!

Contact Us

Additional Resources


 

Back to top