So far, we have sort of assumed that our scripts are all kept on your PC, and that was all well and good. But we live in the i world, so it’s reasonable to expect that’s where we’ll keep our scripts.
Up to this point, all of the scripts that we have written and debugged and otherwise fooled around with have been kept on your PC in a folder that your browser could access, and that depended on your operating system.
If you’re using MAMP/WAMP/LAMP, then you need to know where these files must be placed—that is, you have to know what folder your browser will look in to run them. For example, if you’re on a Mac and using MAMP, then you will have put your script in sites/MAMP/htdoc and then what ever subfolder structure you want. When you try to run these, you’ll use the browser URL file:///Applications/MAMP/htdocs/filename.php.
Of course, if you’re using Zend Studio as your IDE, then you don’t need to worry about where things go. Zend will create a default work space within the Zend folder that’s created when you load Studio. All of the projects and scripts that you create when logged into Zend will be stored in this workspace. You can always go out and look for it, but there’s no need because Studio will keep track of things, and rather than using your browser to display the results of running a script, it will show up in Studio.
But we’re in the IBM i arena, so we really want to keep our scripts on the i. So how do we reconcile that?
The easiest way is to develop your script in Studio using either your default or a special workspace to keep similar things together. Remember, you can have as many work spaces as you can think of names.
When you’ve done the coding and the unit testing on the script, it can then be placed in a special folder on the IFS. Now you might be tempted to think you can do that with some variation on the CPYTOIMPF command, but there’s a much easier way using Studio.
So, first thing, create your PHP script in the workspace defined in Studio.
Next, you need to create an SSH connection from Studio to your i. You could always do FTP, but SSH is faster and just totally cooler.
To do this, open up Studio, and then go to File > New > Other and on the Select a Wizard window, click on Remote Server Connection.
Figure 1: This is the Select a Wizard window used in setting up remote system connection.
Then click on the Connection option and you’ll get a second window opened up.
Figure 2: This window allows you to select the type of connection you want to set up.
Now on this one, click on SSH Only and bring up the third window.
Figure 3: This window allows you to specify connection details for remote connection.
On this screen, we enter the Host Name, the name we want to assign to this connection, and a brief description of what the connection does. When you hit Finish here, you finally get the screen on which you can see the connection.
So what we have done at this point is to create an SSH connection between the copy of Zend Studio on your computer and the IBM i where you want to run those scripts.
Obviously, this means you can essentially develop your PHP scripts offline, without being connected to the i. But when you want to move your completed script to the I, you can do so by means of this SSH connection. Of course, it also means that you need to have the SSH environment up and running on your i, but most sites probably have that up as a matter of course.
Actually Connecting with the i
Once you set up the connection, then you’re ready to go. If you’re in the PHP mode, then your Studio screen should look something like this.
Figure 4: This is a typical PHP Explorer perspective screen shot.
I know this might be a little hard to see, but on the left side we’re in the PHP Explorer mode and it shows the project DWS1 and what that contains. In the middle, we have an open edit session for one of the scripts from the work space, in this case 201606.php. And on the right side is an outline form of this script, although it doesn’t show much because the script is pretty simple.
What I want to zero in on is the other tab in the left window, the one that says Remote. Click on this, and while the center window stays the same, the one on the left changes, and we see the following.
Figure 5: This is a screen shot of the Remote System Explorer perspective.
This screen shows three basic connections. The first is to the local file structure—that is, to the work space that’s contained on your PC. The other two are true remote system connections that I have at various times created, the middle one just a few minutes ago for this article.
To connect, all you have to do is click on My Home of whatever remote system you want to connect to. This will bring up a new window where you can enter the credentials to sign on to the system.
Figure 6: This login screen allows you to connect to a remote connection.
Once you’ve signed on, you can easily move your script from the workspace where it currently lives in Studio to a folder on the IFS of the machine you have signed on to.
If you want a more automatic connection, there’s one more thing you can do. Once you have created your remote connection, you can connect a project to a connection and have things flow more automatically.
To do this, start on the PHP Explorer window and right-click on the project your scripts are under. Yes, that’s right. We are going to do this to the project, not to a script. After you right-click on the project, go down to Properties and click on that. It will open the following window.
Figure 7: A magic window allows you to relate a project to a remote connection for auto upload.
In order to get this set up, you must first check Enable Automatic Upload, which will open the Remote Connection box, and then select the remote connection you want to use. You can even specify a particular directory on that remote site.
Summing It Up
And that’s about it. For now. But there are other things to discover about using Studio, and we’ll pick that up next month.