Skip to main content

By clicking Submit, you agree to the developerWorks terms of use.

The first time you sign into developerWorks, a profile is created for you. Select information in your profile (name, country/region, and company) is displayed to the public and will accompany any content you post. You may update your IBM account at any time.

All information submitted is secure.

  • Close [x]

The first time you sign in to developerWorks, a profile is created for you, so you need to choose a display name. Your display name accompanies the content you post on developerworks.

Please choose a display name between 3-31 characters. Your display name must be unique in the developerWorks community and should not be your email address for privacy reasons.

By clicking Submit, you agree to the developerWorks terms of use.

All information submitted is secure.

  • Close [x]

Spice up PHP applications with OpenLaszlo, Part 1: Create interactive interfaces

Your first OpenLaszlo application

Nicholas Chase (ibmquestions@nicholaschase.com), Freelance writer, Backstop Media
Nicholas Chase has been involved in Web-site development for companies such as Lucent Technologies, Sun Microsystems, Oracle, and the Tampa Bay Buccaneers. Nick has been a high school physics teacher, a low-level radioactive waste facility manager, an online science fiction magazine editor, a multimedia engineer, an Oracle instructor, and the Chief Technology Officer of an interactive communications company. He is the author of several books, including XML Primer Plus (Sams).

Summary:  This "Spice up PHP applications with OpenLaszlo" tutorial series shows you how to use OpenLaszlo to create a more interactive interface for your PHP applications and how to use PHP to create more dynamic OpenLaszlo applications. It requires a basic understanding of -- or willingness to learn -- XML, JavaScript, and PHP. Each is well worth knowing for its own merits, plus they plug and play together nicely, since they're all based on synergistic open standards.

View more content in this series

Date:  14 Mar 2006
Level:  Intermediate PDF:  A4 and Letter (1503 KB | 46 pages)Get Adobe® Reader®

Activity:  12269 views
Comments:  

Getting ready

Before doing anything else, you need to get the development environment in place. If you already have Apache and PHP installed, feel free to skip ahead to Configuring Apache.

Installing PHP

Start by installing PHP, including the free mod_php module, which extends the Apache Web server so it can execute PHP scripts efficiently. The following steps assume you are installing on Windows, but the process is essentially the same for other platforms:

  1. Download the zip file distribution (see Prerequisites). This tutorial was tested with php-5.1.2-Win32.zip.
  2. Extract the zip file into your destination directory, such as C:\php5. (Feel free to choose another directory, but just make sure it doesn't have spaces in it and modify the following directions accordingly.)
  3. Make a copy of C:\php5\php.ini-dist and rename it C:\php5\php.ini.
  4. Edit C:\php5\php.ini. Search for doc_root and change it to "C:\public_html". (Again, you may substitute accordingly.) Don't forget the quotes.
  5. Create a directory for your HTML files called C:\public_html, where you will put the files you want to publish on the Web.

Next, install the Web server.


Installing Apache

Apache will act as a Web server for the PHP files and as a proxy for the OpenLaszlo applications. Download the Apache installer and run it (see Prerequisites).

In the Apache HTTP Server V2.0 Installation Wizard screen, set the following values:


Listing 1. Setting the values for Apache HTTP Server V2.0
                    
Network Domain: localhost
Server Name: localhost
Administrator's Email Address: admin@localhost
Install Apache HTTP Server 2.0 programs and shortcuts:
for All Users, on Port 80, as a Service - Recommended.

Don't configure Apache to use port 8080 because that's the one OpenLaszlo is going to use. If you're running IIS or another Web server on port 80, you'll have to disable it or configure PHP to run with that Web server, instead of Apache.

Select the setup type "Typical" and install Apache HTTP Server V2.0 to the folder: C:\. Note that the installer always makes a subdirectory called Apache2, so if the installation directory is C:\, Apache will be installed in C:\Apache2. You can install it anywhere you like, but it's a good idea never to install PHP or Apache under a directory with spaces in its name (avoid C:\Program Files, for example).


Configuring Apache

Before installing OpenLaszlo, you need to make a few changes to the Apache configuration to enable it to run PHP more efficiently, as well as to act as a proxy so users who can't access the OpenLaszlo application on port 8080 can access it through Apache on port 80:

  1. Make a backup copy and edit the file C:\Apache2\conf\httpd.conf.
  2. Search for DocumentRoot and change it to the name of your HTML directory, C:\public_html.
  3. Search for LoadModule and uncomment the following lines (by deleting the leading pound sign) to enable the following modules:
    LoadModule proxy_module modules/mod_proxy.so 
    LoadModule proxy_http_module modules/mod_proxy_http.so
    LoadModule rewrite_module modules/mod_rewrite.so
    

  4. Configure the rewrite rules by adding the following lines to the end of the httpd.conf file:
    RewriteEngine on
    RewriteRule ^/lzxnet(.*)$ http://localhost:8080/lps-3.1.1$1 [p]
    RewriteRule ^/lps-3\.1\.1(.*)$ http://localhost:8080/lps-3.1.1$1 [p]
    


    The RewriteEngine command enables the rewrite rules. The first RewriteRule command proxies all requests for localhost://lzxnet/* to localhost:8080//lps-3.1.1/*. The second RewriteRule command proxies all requests for localhost://lps-3.1.1/* to localhost:8080//lps-3.1.1/*. These two rewrite rules are required to support OpenLaszlo development with Tomcat on port 8080, and they should be updated to reflect the version of LPS you have installed and the socket Tomcat is listening on.
  5. To load and configure mod_php, add the following lines to the end of the httpd.conf file: LoadModule php5_module "C:/php5/php5apache2.dll"
    AddType application/x-httpd-php .php
    PHPIniDir "C:/php5"
    

  6. The LoadModule command loads mod_php. The AddType command configures files ending with ".php" to be handled by mod_php. The PHPIniDir command tells mod_php where to find its configuration file. Save the file.
  7. Restart Apache. Look for the Apache Service Monitor icon on the right side of the taskbar (it looks like a red feather). If it's not there, you can start it with the Start menu > All Programs > Apache HTTP Server > Configure Apache Server > Monitor Apache Servers. Open the Apache Monitor window and click Restart to restart Apache with the new configuration.

Now let's test the PHP integration.


Test the Apache installation

To test the actual Apache configuration, open your browser to http://localhost. Depending on how you have security configured and what files are present, you will see the Test Page for Apache Installation or a Forbidden 403 error. Don't panic because it means the server is running.

To test PHP, create a file, save it as C:\public_html\testphp.php, and add the following line:

<? print phpinfo(); ?>

Open the URL http://localhost/testphp.php. It should display the PHP information page, describing the PHP version and configuration.


Figure 1. PHP test page
PHP test page


Installing OpenLaszlo

OpenLaszlo is available as a binary installer, as a source code archive, or from the Subversion repository. You will use the binary installer, which includes everything you need, including demos, documentation, examples, libraries, and the Tomcat Web server, which hosts the OpenLaszlo server.

Double-click the installer to start it and install OpenLaszlo into C:\openlaszlo. After the installer finishes, it will start the OpenLaszlo server, which you'll see in a command window. You can start and stop the OpenLaszlo server later with Start menu > All Programs > OpenLaszlo Server > Start OpenLaszlo Server and Stop OpenLaszlo Server.

The installer should also open your browser to a demo page. If it doesn't, point your browser to http://localhost/lzxnet to browse the index of Laszlo documentation and demos. The Laszlo Explorer is an interactive introduction that demonstrates what OpenLaszlo can do, including a hands-on tutorial called "Laszlo in 10 Minutes." You can run it by opening http://localhost/lzxnet/laszlo-explorer.


Figure 2. OpenLaszlo Explorer
OpenLaszlo Explorer

2 of 11 | Previous | Next

Comments



static.content.url=http://www.ibm.com/developerworks/js/artrating/
SITE_ID=1
Zone=Open source
ArticleID=105174
TutorialTitle=Spice up PHP applications with OpenLaszlo, Part 1: Create interactive interfaces
publish-date=03142006
author1-email=ibmquestions@nicholaschase.com
author1-email-cc=dwxed@us.ibm.com