TechTip: What Do You Need to Get Set Up to Do PHP on the IBM i?

Web Languages
Typography
  • Smaller Small Medium Big Bigger
  • Default Helvetica Segoe Georgia Times

 

PHP doesn't run in RSE or PDM, so how do you set up scripts (not programs) or do your testing? Do you need a PC? Or can you do it from the i?

 

RPG runs natively on the i. You create your program in a source file using PDM or RSE and then compile. Everything that RPG needs to do its thing is already built into the IBM i. PHP isn't like that. You need to do a little bit of work to get it to function.

 

I know you'd prefer to just dive into things. But you can't do that with PHP on the i because some effort is required to get it to work. So pay attention: this is important stuff.

 

Where Do You Work?

Let's start by discussing where you'll do your work. No one is hard-connected to an i anymore. We all work on either a desktop or a laptop that has some connection, generally a VPN connection, to an i. And when we do our work, it's done via an emulator that runs in Windows or whatever to create an environment in which we can work.

 

There are a couple of environments we'll use to do our PHP work: one to develop our programs in and one to run them with.

 

Where Do You Write the Program?

Let's start with where you write your PHP programs, although they're not generally called "programs." They're more often called "scripts" or "apps," where an app is a herd of scripts.

 

You do not create a QPHPSRC in PDM. Instead, you'll create your scripts using a basic text editor. Since you're working on a laptop whose operating system is a Mac (yes, correct answer), Windows (seriously?), or Linux (ya got your geek on), you'll have access to many different text editors. There will be a default one that comes with the operating system, but there are also lots of free ones out there that you can use.

 

Or you can buy one. Here's a hint: if you buy one for money, you'll probably get more functionality than if it were free. I use Text Wrangler, not because it's the best, but because it's free and I think the name is so cool. There are plenty of text editors that are better than this. What makes one text editor better than another? Mostly it's stuff that's oriented around one particular web language. For example, the ability to put end tags for an HTML document when you type in the starting tag. Or something similar for PHP. Google "text editors for PHP" and have a ball.

 

Oh, and I guess I should mention that Zend Studio is an excellent PHP text editor.

 

Bottom line, and this is very important, don't use Notes or Text Editor but don't spend too much time figuring out what text editor to use. None of them are going to write the code for you, and there are more important things to worry about.

 

So, what we know at this point is that you're going to need a text editor in which you will write your scripts.

 

Where Will You Run Your Scripts?

The first thing you need to remember is that PHP is a server-side language.

 

Web languages are either client-side or server-side languages. And the differentiation is based on where the language is interpreted. You can argue this and that, but PHP is, compared to RPG, an interpretive language. When it's time to run, the system figures out what it's supposed to do.

 

HTML, for example, is a client-side language. When the HTML script hits your browser, the browser figures out what needs to be done. PHP, on the other hand, is a server-side language. It's interpreted and processed when the script is received at the web server. The results are then sent back down to the client browser to be displayed. But the PHP thinking has occurred at the server.

 

I'm not about to go into all the reasons why some languages are client-side and some are server-side. That's a controversial and boring topic, but suffice to say that it's often a question of resources. PHP generally does more than HTML, for example, and doing that at the server-side, where there are more resources available, seems like a good idea.

 

I'm Sorry, Dave, but Is There a Point to This?

Of course. The point is that you can't just code PHP scripts and run them from your PC the way you would an HTML script. You need to set your PC up as a server because PHP is a server-side language, and that's where it runs. So you have to run it in a web server, not a PC client. The question then becomes, how do you convert your PC to a server? There are two basic ways.

 

The first is to download MAMP, WAMP, or LAMP onto your PC, depending on whether your operating system is Mac, Windows, or Linux. You can Google whichever version you need and download it for free. It's not hard; even I have done it. Works pretty well. Once you have it installed, all you have to do is start the app and then use the web page that it creates to test your scripts.

 

The second is to download Zend Server to the i you're working with.

 

Obviously, these two different options have different requirements. If you don't have access to the i (i.e., you're doing your PHP work on the down-lownot sure if anyone says that anymore; my street contact just started laughing when I texted it to him), then you can do all of this using MAMP, WAMP, or LAMP. Oh, did I mention that each of these is free? I like that myself and have used MAMP for a number of years.

 

But, if you have permission to download something to the i, then your best bet is Zend Server.

 

But isn't the Zend Server fabulously expensive? No, actually it's not. I'm not sure why, considering they have the exclusive with IBM, but it's really very reasonable because they offer several options. I believe I've covered their plans in other MC Press articles, and if I haven't, sue me. You can get a free copy of Zend Server, and it comes with a free year of upgrades and help line support. After that, you're on your own (and with PHP 6.0 coming up, you might want to have full support), but the free edition will get you going. And their help line is great at helping you get the whole thing set up, whereas with MAMP/WAMP/LAMP, you have to figure it out yourself.

 

Where Do We Go from Here?

Where we go next is to write an actual PHP script that you can run in your server environment and do something with. So your homework for the next month is to get yourself set up as a web server, either with MAMP/WAMP/LAMP or the Zend Server. I know, that's a rip-off because it should only be a couple of days work to get it set up, but it will be a month before the next TechTip. Sorry, but Lido sets the schedule, and you don't want to mess with that.

 

BLOG COMMENTS POWERED BY DISQUS