Save your fingers when using PHP-CLI

2021 Update

The instructions in this blog post contain outdated paths and file names.

To learn the modern way to “save your fingers”—plus additional tips for setting up PHP on IBM i—refer to these two articles in our Open Source Documentation library.

In Batch PHP I showed how to call PHP from a command line. For example, with Zend Server 6 or 7 on IBM i, one would launch a PASE command line using the command CALL QP2TERM, or launch QShell using QSH, then type a command such as this:

For those of us who use PHP-CLI often, the above command can be a finger-buster. Let’s shorten the path by creating a symbolic link:

I created the symbolic link in /usr/bin, a directory that is likely to be in any user’s path.

Now try the shortened command:

To test the shortcut without a PHP script, use the -v switch, which requests version information (‘v’ for version) about your PHP installation.

The above command will return version information that starts out something like this:

By creating a symbolic link to the PHP-CLI binary, practitioners of PHP can speed their work while saving their fingers.

For more about symbolic links, see my article Link up with QShell.