Why Scripting in a Box?To install WAMP stack (LAMP on Windows, that is), in the early days, you had to download each component individually (remember 2 kbit/sec?), then spend hours, even days, going through
.conf and
.ini files, reading the comments, hunting on Altavista for tips or hints, feeling lost and discouraged. Sometimes one would just give up and buy a Linux hosting instead, then start developing on the remote machine,
FTP-ing every little change to see if it worked. This scenario has changed now. First, all the components now have much better installation software. Additionally, projects such as XAMPP allow you to easily install (and configure!) a whole bunch of software from one simple package. This article is a bit of a review and a bit of a walk-through of installing and using one such project. It’s a new project called Scripting in a Box that is maintained by SAP.
SAP is the biggest European software shop and third in the world, according to
Wikipedia. It mainly provides Enterprise Resource Planning (ERP) applications, an enormous piece of software that can come in different modules, depending on each business’ needs—accounting, marketing, retail, HR, and so on. As a developer, chances are you may have to work with a SAP installation at some point in your career. The good news for you, as a PHP developer, is that you can use PHP to connect to the SAP system and do different things, ranging from retrieving data to display on the company’s web site, or more complicated tasks like initiating transactions that write to the SAP database.
SAP has recently released Scripting in a Box, a package that contains a number of pre-configured tools that let you start scripting in minutes. The package contains the usual suspects such as PHP, MySQL and Apache, but also phpMyAdmin, some PEAR libraries, Perl, Ruby, Python, the Eclipse editor, Java Runtime Environment, and a PHP extension that allows you to connect to the SAP system—SAPRFC. Let’s see how to get this package set up and start developing.
Download Scripting in a BoxThe first step to downloading the package from the
SAP Developers Network web site is to register to the web site (for free). Next, navigate to the
Downloads area, and click
Technologies in the list of
Available Downloads. Scroll the list to find the Scripting in a Box package and click the i (Information) icon.
Do not use the download icon, because it will download the initial 0.0.1. release of the package and you’d want the latest (v.0.1. at the time of writing this). Once you click the
Information icon, you’ll see a details about the package. Next, scroll down to
Download Releases and select the latest release. There might be also some patches you can download, in addition to the main package, but unless you plan to try out Ruby and Ruby on Rails, you can ignore them. Allow some time for the download as it’s 180+ Megs in size.
UnpackingThe RAR package includes a
readme file and a self-executable archive –
scriptbox_0.1.0.exe. Unpack and run the
.exe file, leaving the default C:\ drive as a destination. After the installation is complete, the default C:\
Development destination will include a number of folders that contain the different scripting tools.
If you want to install and run the whole environment off your USB stick (or iPod), copy the contents of the C:\
Development directory to, say,
W:\Development. To reconfigure the environment, you only need to run the
configure.vbs VBScript, found in the
Development root directory. The VBScript will take care of modifying the appropriate configuration files to point to your new destination. You also have the option of renaming the
Development directory to something else, such as ‘sib’ (for Scripting in a Box) for example. The VBScript will ask you if you’ve changed the default directory. In this case, leave the first prompt intact and type “sib” (or your preferred directory) in the second script prompt.
Directory layoutLet’s assume you left all the defaults. So you’ll have a directory C:\
Development that has the following layout (partial listing):
C:\
- Development
- Apache - Apache web server
- MySQL - MySQL database server
- Perl - ActivePerl for Windows
- PHP
- PEAR - a number of PEAR packages
- Archive
- Console
- ...
- XML
- Python
- Ruby (including Rails)
- Eclipse - The Eclipse application, packed with a number of plugins:
- EPIC (Perl plugin for Eclipse)
- PHPeclipse (PHP plugin for Eclipse)
- PyDev (Python plugin for Eclipse)
- RadRails (Ruby/Ruby on Rails plugin for Eclipse)
- htdocs - This is where all web applications will be located
- workspace - Eclipse-managed directory, where all your application
projects will be placed by default
- phpmyadmin
- ... SAP-related sample applications
- j2re1.4.2_03 - JAVA Runtime Environment, needed by Eclipse
- MySQL_data - All your MySQL databases and tables will be stored hereStarting the EnvironmentTo start the environment, run the start.bat file located in the C:\
Development root. (In case you used the configuration VBScript, the
start.bat file will be called automatically the first time). The start.bat actually sets a few environment paths and then starts Eclipse. The Eclipse environment includes icons to start Apache and MySQL.
The Scripting in a Box package works with the assumption that you’re going to be using Eclipse for development; so it comes with a PHP plugin for this purpose. However, you are free to use your favorite editor, like
TextPad or
EditPlus. In this case you’ll need to start Apache and MySQL yourself. To start Apache, run:
C:\Development\Apache\bin\Apache.exeYou can run the MySQL executable with the default
config file by running the command:
C:\Development\apache\mysql\bin\mysqld-nt.exe--
defaults-file=c:\development\apache\mysql\my.iniUsing EclipseScripting in a Box comes with the PHPeclipse plugin for Eclipse. This creates a very friendly environment for PHP development, with features such as code completion, syntax and error highlighting, and a preview in the built-in web browser. If you’ve never used Eclipse, it’s a great way to get acquainted with it; give it a spin for a few days and decide whether you like it or not.
Eclipse features the so-called perspectives. So the first thing you need to do is to activate the PHP perspective, by selecting the menu option Window->Open Perspective->Other->PHP. Then you can start Apache and MySQL using the appropriate toolbar icons. To access your web server in your browser, go to http://localhost:8080.
Setup summaryLet’s quickly summarize what you do to setup your environment with all the defaults and start coding as quickly as possible:
1. Download Scripting in a Box from
http://sdn.sap.com2. Unpackage into C:\
3. Run C:\
Development\start.bat. This starts Eclipse.
4. Switch to PHP perspective, using Window->Open Perspective
5. Start Apache and MySQL from the Eclipse toolbar
6. Code away!
Start a New ProjectLet’s see how you can create a simple PHP project using your new shiny environment. The project will consist of only one PHP script that reads
php.net's RSS feed and displays it on a web page.
1.
Create a New Project: create a new PHP project by rightclicking in the Navigator area (the top-left panel) and selecting New->Project. Select ‘PHP’ as the type of project and click Next. In the next screen, enter your project a name, for example “myproject” (yeah, I know it’s not too original) and click
Finish.
In the last screen (before you click
Finish), there is a checkbox that says that you’ll be using the default directory to store the project files, which is C:\
Development\htdocs\workspace\myproject. This means that the application you’re creating can be accessed at http://localhost:8080/workspace/myproject
2.
Create a new PHP file: you can view the new project in the Navigator pane. Right-click on the project name and select New->PHP File. Give the file the name
hello.php (leave the container field intact) and click
Finish.
3.
Do the actual coding: let’s just take a simple PEAR example to test if all is fine with the PEAR setup. I took some code from the
PEAR Manual to read an RSS feed using the XML_RSS package and changed the URL to read the news from the
php. net site. Here’s the slightly modified code:
require_once “XML/RSS.php”;
$rss =& new XML_RSS(“http://www.php.net/news.rss”);
$rss->parse();
echo “<h1>Headlines from <a href=\”http://php.net\”>PHP.net</a></h1>\
n”;
echo “\n”;
foreach ($rss->getItems() as $item) {
echo “
*<a href=\”” . $item[‘link’] .
“\”>” . $item[‘title’] . “</a>
\n”;
}
echo “
\n”;4.
Save and view results: once you hit Save (CTRL+S), the script is saved and loaded in Eclipse’s internal browser.
SummaryNow you know how to install and start using the Scripting in a Box tool to do PHP development. You can use the tool for your development needs, or just to quickly try out other scripting languages such as Ruby or Python. Even if you’re an experienced developer and have set up your development environment to suit your requirements, you now have one more answer to all your friends that ask you “OK, how do I go about installing PHP on my Windows machine?”