06
Fri, Dec
6 New Articles

TechTip: Running PHP Scripts: WAMP/MAMP/LAMP

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

Running RPG programs once they're created is easy. But what about PHP? We created a class-oriented script, but how do we run it? And what kind of setup is required to have a functioning PHP environment?

 

We spent the last few tips talking about classes and gradually building a small script that was based in a class. But have you run the script? Do you know how to run a PHP script?

 

PHP isn't like RPG. It doesn't just run on the machine that you create it on. And you don't just do a "callphp" or something like that.

 

Over the next few months, we are going to look at how to run a PHP script from a number of different environments. Now I think I need to say that none of these methods includes running a script from an RPG program. We will look at that later in the year. But before you are running things from RPG, you need to develop and test out your PHP scripts by themselves, and the techniques we will go over in the next few months will target that.

 

Client Side/Server Side

Remember that web languages come in two flavors: client side and server side.

 

Client-side languages (like HTML, for example) run on the client machine. In HTML's case, that means on the browser that is on your PC. You set up the script in your PC, and then you run it on your PC's browser with no additional software required. The browser interprets the HTML markup.

 

Server-side languages, however, do not run in your client machine. They run on the server, and the results of that run are then sent down to your client machine to be displayed.

 

PHP is a server-side language. So any script that you write on your PC will not run there but instead must be sent to a server for interpretation. So the first question is, how do you get your script to a server?

 

Well, you could set up or buy (through Network Solutions or GoDaddy or someone) a website that you could then upload code to test on a server, but that seems like a lot of bother. Fortunately, there is an easier way. All you have to do is get some software on your PC that will create an instance of a server on your laptop. Then you need to put your script in a place where that server can see it and run it. And voila, you are done.

 

What software can you use?

 

Again, the good news is that there are many products out there that will create a server on your PC and pick up and run PHP scripts.

 

Server Software Options

The original is the use of WAMP/MAMP/LAMPone flavor for each of the three main operating systems: Windows, Mac, and Linux. (As you probably know, the acronym stands for Windows/Mac/Linux-Apache-MySQL-PHP.) You can download this onto your PC from a website for free and in a few minutes have a functional server running on your laptop. You can then create your scripts in a text editor and run them on the W/M/L server. Very simple yet very effective.

 

The other primary option is something that is popular for us IBM i'ers: Zend Server and Zend Studio. This is a combo product. Zend Server provides the server instance, and Zend Studio provides the IDE that you develop the scripts in. It is much more sophisticated and powerful than a text editor but also takes longer to figure out.

 

Over the next few TechTips, we will take a look at both of these options. I am going to start with WAMP/MAMP/LAMP because it is the easiest one to set up.

 

This software gives you a complete server stack defined by those products. You select the one for the platform you are on and install it from the web, and it will load an app onto your system that lets you start a local server that you can use for PHP testing.

 

Specifically, when you open the app, it will create a PHP stack and then open a browser page that will be a server browser page rather than one for your client machine. You can then enter the URL for your PHP script on that server browser page and it will run it.

 

Installing WAMP/MAMP/LAMP

There are a couple of ways to get the server software. One is to go to www.sourceforge.net and find WAMP, MAMP, or LAMP and then download. Sometimes, however, I find that site confusing, and the documentation is not always what I want it to be. It's sort of like going to a junk yard. The stuff is there, but you have to figure out where it is and how it works.

 

I am a Mac user, so I got my MAMP from www.mamp.info. They have a free version (MAMP) and a more sophisticated paid version (MAMP Pro) and all the info you need to download. Both editions provide MySQL, Apache, and PHP along with Python and Perl. Plus, if you have any questions, they have support (even for the free version) and will help you out. I have always used the free version and never needed the bells and whistles of the paid package. And their version of MAMP also runs on Windows (officially supported on 7.0, 8.0, 8.1, 10.0, and unofficially on XP). I would download from there. One thing to note is that it will be installed into a new directory (c:\MAMP), not into Program Files. There is a reason for thissome compatibility issuebut I am not going to go into that now. Or ever. 'Cause I don't care.

 

If you are on Linux, then I guess you are stuck with the junkyard.

 

Just follow the instructions, and you should be able to be up and running on this product (MAMP) in a very short time. Generally, starting this app will start MySQL and Apache and bring up a blank window on your browser that you will be able to test in. This is just a normal browser window except that technically it is running in your server instance rather than as a client browser session. Also, it is possible that when this window comes up it will say that the page cannot be found. Don't worry about this. It's not a real problem.

 

Setting Up Your Script

Once you get WAMP/MAMP/LAMP installed, now what do you do?

 

The first step is to create your script. If you are using W/M/L, then you can simply code it up in a text editor on your PC. You could use Notepad, but for a slightly more sophisticated experience, Google "Free text editors" and choose one that you can download and use. I use Text Wrangler, because it sounds kind of manly, and it works well for me.

 

Once you have keyed your script into the editor, the next step will be to save it. What is important here is that you have to put your script somewhere where the server can find it.

 

  • For WAMPc:\wamp\www\
  • For MAMP (Mac)/applications/MAMP/htdocs/
  • For MAMP (Windows)c:\MAMP\htdocs\
  • For LAMP/var/www/html (I am 90% sure this is correct)

 

Within the path, you can then create additional folders to organize your scripts.

 

Running Your Script

Once the script is positioned, running it is easy.

 

Start your server by using the icon that was installed as part of the download. This will start up the various services you need to define a server and display a web page that is running in the server environment.

 

To run your script, you will need to change the default URL that comes up with the server browser page to include the script name. If you have placed your script in the proper location as noted above, then all you need to do is append the script name to the "localhost:9999" verbiage. Be sure to start it with a slash (/) and include any qualifying folders if they are part of the script path.

 

So, for example, taking a Mac example, if the full path to the script is /applications/MAMP/htdocs/Project1/index.php, then to run that we would need to append /Project1/index.php after the local host:8888 that appears when the server browser page is displayed. Key that in and hit Enter and the script should run. If you have any echo or print commands in the script, then the output will appear on the web page.

 

And That's It

And that's all there is to it. This is one way to run PHP programs on your PC. It's simple, it's free, and you can do it today. Is it the best way? How would I know? Maybe not. So our next TechTip will start looking at using the Zend products: Zend Server and Zend Studio. Stay tuned.

 

David Shirey

David Shirey is president of Shirey Consulting Services, providing technical and business consulting services for the IBM i world. Among the services provided are IBM i technical support, including application design and programming services, ERP installation and support, and EDI setup and maintenance. With experience in a wide range of industries (food and beverage to electronics to hard manufacturing to drugs--the legal kind--to medical devices to fulfillment houses) and a wide range of business sizes served (from very large, like Fresh Express, to much smaller, like Labconco), SCS has the knowledge and experience to assist with your technical or business issues. You may contact Dave by email at This email address is being protected from spambots. You need JavaScript enabled to view it. or by phone at (616) 304-2466.


MC Press books written by David Shirey available now on the MC Press Bookstore.

21st Century RPG: /Free, ILE, and MVC 21st Century RPG: /Free, ILE, and MVC
Boost your productivity, modernize your applications, and upgrade your skills with these powerful coding methods.
List Price $69.95

Now On Sale

BLOG COMMENTS POWERED BY DISQUS

LATEST COMMENTS

Support MC Press Online

$

Book Reviews

Resource Center

  • SB Profound WC 5536 Have you been wondering about Node.js? Our free Node.js Webinar Series takes you from total beginner to creating a fully-functional IBM i Node.js business application. You can find Part 1 here. In Part 2 of our free Node.js Webinar Series, Brian May teaches you the different tooling options available for writing code, debugging, and using Git for version control. Brian will briefly discuss the different tools available, and demonstrate his preferred setup for Node development on IBM i or any platform. Attend this webinar to learn:

  • SB Profound WP 5539More than ever, there is a demand for IT to deliver innovation. Your IBM i has been an essential part of your business operations for years. However, your organization may struggle to maintain the current system and implement new projects. The thousands of customers we've worked with and surveyed state that expectations regarding the digital footprint and vision of the company are not aligned with the current IT environment.

  • SB HelpSystems ROBOT Generic IBM announced the E1080 servers using the latest Power10 processor in September 2021. The most powerful processor from IBM to date, Power10 is designed to handle the demands of doing business in today’s high-tech atmosphere, including running cloud applications, supporting big data, and managing AI workloads. But what does Power10 mean for your data center? In this recorded webinar, IBMers Dan Sundt and Dylan Boday join IBM Power Champion Tom Huntington for a discussion on why Power10 technology is the right strategic investment if you run IBM i, AIX, or Linux. In this action-packed hour, Tom will share trends from the IBM i and AIX user communities while Dan and Dylan dive into the tech specs for key hardware, including:

  • Magic MarkTRY the one package that solves all your document design and printing challenges on all your platforms. Produce bar code labels, electronic forms, ad hoc reports, and RFID tags – without programming! MarkMagic is the only document design and print solution that combines report writing, WYSIWYG label and forms design, and conditional printing in one integrated product. Make sure your data survives when catastrophe hits. Request your trial now!  Request Now.

  • SB HelpSystems ROBOT GenericForms of ransomware has been around for over 30 years, and with more and more organizations suffering attacks each year, it continues to endure. What has made ransomware such a durable threat and what is the best way to combat it? In order to prevent ransomware, organizations must first understand how it works.

  • SB HelpSystems ROBOT GenericIT security is a top priority for businesses around the world, but most IBM i pros don’t know where to begin—and most cybersecurity experts don’t know IBM i. In this session, Robin Tatam explores the business impact of lax IBM i security, the top vulnerabilities putting IBM i at risk, and the steps you can take to protect your organization. If you’re looking to avoid unexpected downtime or corrupted data, you don’t want to miss this session.

  • SB HelpSystems ROBOT GenericCan you trust all of your users all of the time? A typical end user receives 16 malicious emails each month, but only 17 percent of these phishing campaigns are reported to IT. Once an attack is underway, most organizations won’t discover the breach until six months later. A staggering amount of damage can occur in that time. Despite these risks, 93 percent of organizations are leaving their IBM i systems vulnerable to cybercrime. In this on-demand webinar, IBM i security experts Robin Tatam and Sandi Moore will reveal:

  • FORTRA Disaster protection is vital to every business. Yet, it often consists of patched together procedures that are prone to error. From automatic backups to data encryption to media management, Robot automates the routine (yet often complex) tasks of iSeries backup and recovery, saving you time and money and making the process safer and more reliable. Automate your backups with the Robot Backup and Recovery Solution. Key features include:

  • FORTRAManaging messages on your IBM i can be more than a full-time job if you have to do it manually. Messages need a response and resources must be monitored—often over multiple systems and across platforms. How can you be sure you won’t miss important system events? Automate your message center with the Robot Message Management Solution. Key features include:

  • FORTRAThe thought of printing, distributing, and storing iSeries reports manually may reduce you to tears. Paper and labor costs associated with report generation can spiral out of control. Mountains of paper threaten to swamp your files. Robot automates report bursting, distribution, bundling, and archiving, and offers secure, selective online report viewing. Manage your reports with the Robot Report Management Solution. Key features include:

  • FORTRAFor over 30 years, Robot has been a leader in systems management for IBM i. With batch job creation and scheduling at its core, the Robot Job Scheduling Solution reduces the opportunity for human error and helps you maintain service levels, automating even the biggest, most complex runbooks. Manage your job schedule with the Robot Job Scheduling Solution. Key features include:

  • LANSA Business users want new applications now. Market and regulatory pressures require faster application updates and delivery into production. Your IBM i developers may be approaching retirement, and you see no sure way to fill their positions with experienced developers. In addition, you may be caught between maintaining your existing applications and the uncertainty of moving to something new.

  • LANSAWhen it comes to creating your business applications, there are hundreds of coding platforms and programming languages to choose from. These options range from very complex traditional programming languages to Low-Code platforms where sometimes no traditional coding experience is needed. Download our whitepaper, The Power of Writing Code in a Low-Code Solution, and:

  • LANSASupply Chain is becoming increasingly complex and unpredictable. From raw materials for manufacturing to food supply chains, the journey from source to production to delivery to consumers is marred with inefficiencies, manual processes, shortages, recalls, counterfeits, and scandals. In this webinar, we discuss how:

  • The MC Resource Centers bring you the widest selection of white papers, trial software, and on-demand webcasts for you to choose from. >> Review the list of White Papers, Trial Software or On-Demand Webcast at the MC Press Resource Center. >> Add the items to yru Cart and complet he checkout process and submit

  • Profound Logic Have you been wondering about Node.js? Our free Node.js Webinar Series takes you from total beginner to creating a fully-functional IBM i Node.js business application.

  • SB Profound WC 5536Join us for this hour-long webcast that will explore:

  • Fortra IT managers hoping to find new IBM i talent are discovering that the pool of experienced RPG programmers and operators or administrators with intimate knowledge of the operating system and the applications that run on it is small. This begs the question: How will you manage the platform that supports such a big part of your business? This guide offers strategies and software suggestions to help you plan IT staffing and resources and smooth the transition after your AS/400 talent retires. Read on to learn: