Visual Studio Code, IBM i & PHP
Every post about Code for IBM i thus far has been how it can be used for writing RPG, CL, COBOL, etc. But what about other languages? Of course, PHP is another one of those very popular languages on IBM i. Calvin wrote a little while ago about how it’s possible to use RDi to write PHP code on the server, which is great. I think we can take it up a notch, which brings us to this post.
Before continuing, you should read our previous post about getting Code for IBM i installed and connected to your system on which you develop.
PHP on IBM i
As you likely know, people are running PHP on IBM i and have been doing it for a long time—that part is great. The sad part is the number of people I’ve come across using FTP to transfer files to and from their PC to edit, before re-uploading their changes to their IBM i. This is upsetting because it can be easier. Some write PHP in their editor and then connect to their IBM i over a drive-letter (e.g. Q:\) network share. In other environments, I’ve seen people use Notepad++, PHPStorm, and Eclipse.
Let’s add Visual Studio Code, with the Code for IBM i extension, to the list of popular IDEs for writing PHP.
Benefits of Visual Studio Code for PHP developers
Visual Studio Code’s features for PHP developers include PHP syntax coloring, code snippet suggestions, custom extensions, and debugging (see the Visual Studio Code section of our PHP debugging guide). To make editing on the IFS easy, install Code for IBM i and use the IFS Browser.
The IFS browser & your working directory
Once you have Code for IBM i installed and working with Visual Studio Code, you can edit your PHP code using the Code for IBM i IFS Browser. The initial listing you see is usually your home directory. The usual thing to do is to change that working directory to where your PHP app (or even better, your PHP repository!) is. You can do that with the ‘Change directory’ button.
From here you can browse any sub-directory or source code in that working directory.
The IFS browser makes it easy to save your changes onto your IBM i IFS by using File/Save or pressing CTRL-S (Command-S for Mac).
Source control
2023 Update
Git Client for IBM i is no longer needed due to improvements
in deployment for local development.
Did you know, as well as Code for IBM i being available, there is also a Git client for the remote server (e.g. your IBM i!)? Since the Git client works directly with Code for IBM i, installing the Git client will make new views show up in the Source Control view. It will assume that whatever your current working directory is will also be a git repository.
The Git Client for IBM i extension has the following functionality:
- Status of the working tree. Add, revert, and view diffs of your working tree before making commits
- Integrated log. See a diff of specific files at specific commits right in the editor
- File history. See the history of the file you currently have open
Visual Studio Code + Code for IBM i = Efficient, powerful PHP development
Some of my PHP developer friends have been looking for a way to edit PHP on IBM i with quick setup, fast loading and saving, at no cost, and with time-saving developer productivity features. I wrote this blog post for them. Code for IBM i adds ease of IFS editing to the power of Visual Studio Code. While you’re at it, if you wish to develop in RPG, COBOL, or CL, or run SQL statements, you can do that too, all from the same editor.
For more information about Code for IBM i, see Visual Studio Code for IBM i: A Resource Guide. For training, development services, or PHP, get in touch.
Leave a Reply
Want to join the discussion?Feel free to contribute!