d~l
10-24-2004, 05:25 AM
See shorter description of PHP installation posted further down this thread .. 14-03-2005.
...............
Summary
Following research into ways of using PHP with Laszlo, these are notes of my installation of PHP 5.0.2 on Tomcat 5.0.28 to integrate wth Laszlo 2.2 for running Pre-Processed Requests.
There are other methods of connecting Apache to Tomcat server via mod_jk2 connector.
But for running Pre-Processed hello.php.lzx Requests in Laszlo apps, PHP must coexist with LPS on the Tomcat server.
Pre Reading
Read LPS document on Request types here .. LPS Request Types (http://www.laszlosystems.com/lps/docs/lzx-developers-guide/lps-request-types.html)
Preprocessed Requests
The LPS also supports using dynamic, server-side back-end processors (e.g., PHP, JSP) to generate LZX application source code before the LPS compiles and serves it. For URLs that end in .lzx for which the LPS can not find a matching source file on disk, the LPS will strip off the .lzx suffix and run attempt to get the content of the modified URL via an HTTP GET. The contents returned
should be a properly formatted LZX file. The LPS will then compile and server an application based on the dynamically generated source code. For example see the hello.jsp file in the examples
directory. This example generates a Laszlo application that contains information about the current time and session. You can see the generated LZX source at:
http://localhost:8080/lps-2.2/examples/hello.jsp.lzx?lzt=source
and the generated application at:
http://localhost:8080/lps-2.2/examples/hello.jsp.lzx
Related Threads
Laszlo and PHP (http://www.laszlosystems.com/developers/community/forums/showthread.php?threadid=1254)
Installation of PHP 5.0.2 on Tomcat Server
Shut down Tomcat server.
If PHP is not already installed, download and install binary version of PHP 5.0.2 into c:\php\
PHP downloads page (http://www.php.net/downloads.php#v5)
PHP 5.0.2 zip package (http://www.php.net/get/php-5.0.2-Win32.zip/from/a/mirror)
Also download separately ..
Collection of PECL modules (http://www.php.net/get/pecl-5.0.2-Win32.zip/from/a/mirror)
Download PHPServlet (http://tools.herberlin.de) from http://www.herberlin.de/index.html
Install PHPServlet as a normal Tomcat webapp (drop PHPServlet.war into %TOMCAT_HOME%\webapps\).
In text editor, open installed %TOMCAT_HOME\webapps\PHPServlet\WEB-INF\web.xml
and set the path to the PHP 5.0.2 executable ...
<init-param>
<param-name>php.executable</param-name>
<param-value>c:/php/php-cgi.exe</param-value>
</init-param>
Note: the path must be to the PHP 5.0.2 CGI executable php-cgi.exe and not php.exe.
Also in PHPServlet\WEB-INF\web.xml, if you plan to access MySQL from PHPServlet/Tomcat you
must uncomment the web.xml configuration as below.
<!-- uncomment for MySQL connection -->
<!-- Seems that PHP 4.3 on Win32 needs this environment variable
to connect to MySql. Uncomment this if you have problems with
php and mysql on windows. (set to: c:/winnt/ if needed.)
-->
<init-param>
<param-name>SystemRoot</param-name>
<param-value>c:/windows/</param-value>
</init-param>
Otherwise, when attempting to access MySQL you will see a "Can't connect to MySQL - tcp/ip socket error (10106)" message.
The reason for this error is that PHP is working in CGI mode.
The CGI module option to send environment variables to CGI scripts is off by default.
This prevents PHP on Tomcat from obtaining the %SystemPath% and access to various dll's.
Therefore the path has to be set explicitly (by uncommenting the above web.xml configuration).
Ensure that phpservlet.jar is in your Java classpath.
To be sure, move phpservlet.jar (we only need one copy of phpservlet.jar in Tomcat) ..
from %TOMCAT_HOME%\webapps\PHPServlet\phpservlet.jar
into %TOMCAT_HOME%\common\lib\phpservlet.jar
Now open Control Panel | System | Advanced | Environment Variables
and insert into CLASSPATH ..
%TOMCAT_HOME%\common\lib;%TOMCAT_HOME%\common\lib\ phpservlet.jar
You will need to reboot server after changing Environment Variables.
Testing PHP 5.0.2 with PHPServlet/Tomcat
Startup Tomcat server. and watch logs for any errors in startup.
Check that PHPServlet has been installed as a new webapp.
Test that PHPServlet works by launching ..
http://localhost:8080/PHPServlet/
and then ..
http://localhost:8080/PHPServlet/phpinfo.php
to display PHP report
If no phpinfo report shows, you cannot go much further until this is seen to show that PHP is running on Tomcat.
At this point in the process, PHP is running as a separate application to Laszlo and if PHP applications
require to be used from within Laszlo apps they must be called via http://localhost:8080/PHPServlet/<phpapp>.
Building an Integrated LPS/PHPServlet Application
Shut down Tomcat server.
For test purposes create a clone of webapps\lps-2.2 into webapps\ and rename to lps-php
Startup Tomcat server.
Running webapps should now be:-
webapps\lps-2.2\ Laszlo apps only
webapps\lps-php\ clone of Laszlo apps only
webapps\PHPServlet\ PHP apps only
Shut down Tomcat server.
Rename webapps\PHPServlet\index.html to webapps\PHPServlet\index-php.html
Copy the entire contents of webapps\PHPServlet\*.* into webapps\lps-2.2\*.* (including sub-folders)
You will find a file management utility such as Total Commander (http://www.ghisler.com) to be useful for this.
Ensure that all sub-folders are copied / merged into classes and libs folders.
Now the webapps\lps-2.2\WEB-INF\web.xml file will need to be edited into a new merged web.xml.
The new web.xml will contain the servlet mappings from the two merged webapps (lps-2.2 and PHPServlet).
To make this easier, a sample WEB-INF\web.xml is included in the zip attachment.
Also take the \php\*.* folder in the zip attachment and copy into webapps\lps-php\examples\
This will create two files to test pre-processed requests - hello.php.lzx format.
webapps\lps-php\examples\php\hello.html
webapps\lps-php\examples\php\hello.php
Startup Tomcat server.
Test the new integrated Laszlo/PHP installation by launching the following
http://localhost:8080/lps-php/examples/hello.html to display hello.jsp.lzx
http://localhost:8080/lps-php/examples/hello.jsp.lzx to display hello.jsp.lzx
http://localhost:8080/lps-php/phpinfo.php to display PHP report
http://localhost:8080/lps-php/examples/php/hello.html to display hello.php.lzx
http://localhost:8080/lps-php/examples/php/hello.php.lzx to display hello.php.lzx
Final Deployment
The net result of this exercise:-
http://localhost:8080/lps-2.2/ for Laszlo and JSP applications only
http://localhost:8080/PHPservlet/ for PHP applications only
http://localhost:8080/lps-php/ for Laszlo, PHP and JSP applications
For test purposes, it is easier to keep these as separate webapps so that any webapp can be deleted as required.
Pros
dynamic scripting of Laszlo content using pre-processed requests.
access to rich features of PHP 5.0.2 including XML management (SimpleXML)
access to MySQL (or other) databases for importing/exporting XML files and Laszlo applications/resources.
access to a wide range of PHP applications to embed in Laszlo as the presentation layer
Cons
See Laszlo warning in this thread which suggests that pre-processed requests may not be supported in future.
pre processed requests (http://www.laszlosystems.com/developers/community/forums/showthread.php?threadid=1319)
Kranking simple hello.php.lzx application seems to go on ad infinitum.
Concluding
read related thread here .. (http://www.laszlosystems.com/developers/community/forums/showthread.php?s=&threadid=1319)
Bloch wrote ..
The compiler is too slow. That's the main problem with this idiom for now. But you can use .php and .lzx together and we do. It's simply better practice to leave the .lzx fixed and have the program make runtime data requests back for session related information.
So on balance it seems that integrating PHP/LZX is not such a good move, because dynamic lzx script has to be re-compiled.
Better to call the php applications separately from static lzx.
d~l
...............
Summary
Following research into ways of using PHP with Laszlo, these are notes of my installation of PHP 5.0.2 on Tomcat 5.0.28 to integrate wth Laszlo 2.2 for running Pre-Processed Requests.
There are other methods of connecting Apache to Tomcat server via mod_jk2 connector.
But for running Pre-Processed hello.php.lzx Requests in Laszlo apps, PHP must coexist with LPS on the Tomcat server.
Pre Reading
Read LPS document on Request types here .. LPS Request Types (http://www.laszlosystems.com/lps/docs/lzx-developers-guide/lps-request-types.html)
Preprocessed Requests
The LPS also supports using dynamic, server-side back-end processors (e.g., PHP, JSP) to generate LZX application source code before the LPS compiles and serves it. For URLs that end in .lzx for which the LPS can not find a matching source file on disk, the LPS will strip off the .lzx suffix and run attempt to get the content of the modified URL via an HTTP GET. The contents returned
should be a properly formatted LZX file. The LPS will then compile and server an application based on the dynamically generated source code. For example see the hello.jsp file in the examples
directory. This example generates a Laszlo application that contains information about the current time and session. You can see the generated LZX source at:
http://localhost:8080/lps-2.2/examples/hello.jsp.lzx?lzt=source
and the generated application at:
http://localhost:8080/lps-2.2/examples/hello.jsp.lzx
Related Threads
Laszlo and PHP (http://www.laszlosystems.com/developers/community/forums/showthread.php?threadid=1254)
Installation of PHP 5.0.2 on Tomcat Server
Shut down Tomcat server.
If PHP is not already installed, download and install binary version of PHP 5.0.2 into c:\php\
PHP downloads page (http://www.php.net/downloads.php#v5)
PHP 5.0.2 zip package (http://www.php.net/get/php-5.0.2-Win32.zip/from/a/mirror)
Also download separately ..
Collection of PECL modules (http://www.php.net/get/pecl-5.0.2-Win32.zip/from/a/mirror)
Download PHPServlet (http://tools.herberlin.de) from http://www.herberlin.de/index.html
Install PHPServlet as a normal Tomcat webapp (drop PHPServlet.war into %TOMCAT_HOME%\webapps\).
In text editor, open installed %TOMCAT_HOME\webapps\PHPServlet\WEB-INF\web.xml
and set the path to the PHP 5.0.2 executable ...
<init-param>
<param-name>php.executable</param-name>
<param-value>c:/php/php-cgi.exe</param-value>
</init-param>
Note: the path must be to the PHP 5.0.2 CGI executable php-cgi.exe and not php.exe.
Also in PHPServlet\WEB-INF\web.xml, if you plan to access MySQL from PHPServlet/Tomcat you
must uncomment the web.xml configuration as below.
<!-- uncomment for MySQL connection -->
<!-- Seems that PHP 4.3 on Win32 needs this environment variable
to connect to MySql. Uncomment this if you have problems with
php and mysql on windows. (set to: c:/winnt/ if needed.)
-->
<init-param>
<param-name>SystemRoot</param-name>
<param-value>c:/windows/</param-value>
</init-param>
Otherwise, when attempting to access MySQL you will see a "Can't connect to MySQL - tcp/ip socket error (10106)" message.
The reason for this error is that PHP is working in CGI mode.
The CGI module option to send environment variables to CGI scripts is off by default.
This prevents PHP on Tomcat from obtaining the %SystemPath% and access to various dll's.
Therefore the path has to be set explicitly (by uncommenting the above web.xml configuration).
Ensure that phpservlet.jar is in your Java classpath.
To be sure, move phpservlet.jar (we only need one copy of phpservlet.jar in Tomcat) ..
from %TOMCAT_HOME%\webapps\PHPServlet\phpservlet.jar
into %TOMCAT_HOME%\common\lib\phpservlet.jar
Now open Control Panel | System | Advanced | Environment Variables
and insert into CLASSPATH ..
%TOMCAT_HOME%\common\lib;%TOMCAT_HOME%\common\lib\ phpservlet.jar
You will need to reboot server after changing Environment Variables.
Testing PHP 5.0.2 with PHPServlet/Tomcat
Startup Tomcat server. and watch logs for any errors in startup.
Check that PHPServlet has been installed as a new webapp.
Test that PHPServlet works by launching ..
http://localhost:8080/PHPServlet/
and then ..
http://localhost:8080/PHPServlet/phpinfo.php
to display PHP report
If no phpinfo report shows, you cannot go much further until this is seen to show that PHP is running on Tomcat.
At this point in the process, PHP is running as a separate application to Laszlo and if PHP applications
require to be used from within Laszlo apps they must be called via http://localhost:8080/PHPServlet/<phpapp>.
Building an Integrated LPS/PHPServlet Application
Shut down Tomcat server.
For test purposes create a clone of webapps\lps-2.2 into webapps\ and rename to lps-php
Startup Tomcat server.
Running webapps should now be:-
webapps\lps-2.2\ Laszlo apps only
webapps\lps-php\ clone of Laszlo apps only
webapps\PHPServlet\ PHP apps only
Shut down Tomcat server.
Rename webapps\PHPServlet\index.html to webapps\PHPServlet\index-php.html
Copy the entire contents of webapps\PHPServlet\*.* into webapps\lps-2.2\*.* (including sub-folders)
You will find a file management utility such as Total Commander (http://www.ghisler.com) to be useful for this.
Ensure that all sub-folders are copied / merged into classes and libs folders.
Now the webapps\lps-2.2\WEB-INF\web.xml file will need to be edited into a new merged web.xml.
The new web.xml will contain the servlet mappings from the two merged webapps (lps-2.2 and PHPServlet).
To make this easier, a sample WEB-INF\web.xml is included in the zip attachment.
Also take the \php\*.* folder in the zip attachment and copy into webapps\lps-php\examples\
This will create two files to test pre-processed requests - hello.php.lzx format.
webapps\lps-php\examples\php\hello.html
webapps\lps-php\examples\php\hello.php
Startup Tomcat server.
Test the new integrated Laszlo/PHP installation by launching the following
http://localhost:8080/lps-php/examples/hello.html to display hello.jsp.lzx
http://localhost:8080/lps-php/examples/hello.jsp.lzx to display hello.jsp.lzx
http://localhost:8080/lps-php/phpinfo.php to display PHP report
http://localhost:8080/lps-php/examples/php/hello.html to display hello.php.lzx
http://localhost:8080/lps-php/examples/php/hello.php.lzx to display hello.php.lzx
Final Deployment
The net result of this exercise:-
http://localhost:8080/lps-2.2/ for Laszlo and JSP applications only
http://localhost:8080/PHPservlet/ for PHP applications only
http://localhost:8080/lps-php/ for Laszlo, PHP and JSP applications
For test purposes, it is easier to keep these as separate webapps so that any webapp can be deleted as required.
Pros
dynamic scripting of Laszlo content using pre-processed requests.
access to rich features of PHP 5.0.2 including XML management (SimpleXML)
access to MySQL (or other) databases for importing/exporting XML files and Laszlo applications/resources.
access to a wide range of PHP applications to embed in Laszlo as the presentation layer
Cons
See Laszlo warning in this thread which suggests that pre-processed requests may not be supported in future.
pre processed requests (http://www.laszlosystems.com/developers/community/forums/showthread.php?threadid=1319)
Kranking simple hello.php.lzx application seems to go on ad infinitum.
Concluding
read related thread here .. (http://www.laszlosystems.com/developers/community/forums/showthread.php?s=&threadid=1319)
Bloch wrote ..
The compiler is too slow. That's the main problem with this idiom for now. But you can use .php and .lzx together and we do. It's simply better practice to leave the .lzx fixed and have the program make runtime data requests back for session related information.
So on balance it seems that integrating PHP/LZX is not such a good move, because dynamic lzx script has to be re-compiled.
Better to call the php applications separately from static lzx.
d~l