14 Replies Latest reply on Dec 4, 2008 5:45 PM by Billy Murphy

    PHP on TOMCAT

    Billy Murphy Newbie

      Its crazy time, at least for me anyway.

      Centos 4
      Tomcat 5
      PHP 5

      Are there any copies of libphp5servlet.so and libphp5.so floating around. On the off chance that they will drop in.

      The download area provided at the url below is inaccesible and the build.sh depends on multilpe libraries and invariably runs into trouble.

      http://www.jboss.org/file-access/default/members/jbossweb/freezone/modules/php/index.html

      Thanks in advance for any input

        • 1. Re: PHP on TOMCAT
          Billy Murphy Newbie

          The above link is accessible, apologies for that, i'll try and drop in that version.

          As a bit more background and for anyone else who wanders down this path, I have an apache ( 2.0.52) / tomcat ( 55sar bundled with jboss AS 4.0..2 ) installation on CENTOS(4.4). PHP (4.* - 5.*, 5-preferable)

          I can get my php working as a dso mudule or cgi by dropping it in the httpd document root.

          I want it to work like jsp though and am looking to package the php into my web application alongside the jsp as it seems easier to distribute notwithstanding the *.so module dependancies.

          Im finding it a lot of work, enjoyable as it is, and thus far the the only reward. I've come across some other postings which has provided me the evidence that its possible and also implemented it in a windows environment without too much trouble.

          Is there a good reason not to do it, excepting dependancy on libphp5servlet.so being available and enabled.

          • 2. Re: PHP on TOMCAT
            Eric H Novice

            You can run PHP without even needing to use any of the PHP binaries. Check out http://www.caucho.com/resin-3.0/quercus/

            I'm about to try it out to see if I can get pgAdmin running in it.

            • 3. Re: PHP on TOMCAT
              Eric H Novice

               

              "EricJava" wrote:
              You can run PHP without even needing to use any of the PHP binaries. Check out http://www.caucho.com/resin-3.0/quercus/


              And I just now tried it out in Tomcat 6.0.18, and it was super-simple.

              1. Download Resin. I grabbed Resin 3.1.8.

              2. Unzip it

              3. Grab two JARS from the resin/lib file: quercus.jar and resin-util.jar. Put them in WEB-INF/lib of your app

              4. Put in a servlet mapping:

              <servlet>
               <servlet-name>quercus</servlet-name>
               <servlet-class>com.caucho.quercus.servlet.QuercusServlet</servlet-class>
               </servlet>
              
               <servlet-mapping>
               <servlet-name>quercus</servlet-name>
               <url-pattern>*.php</url-pattern>
               </servlet-mapping>
              


              5. Create a simple test file:

              <?php
              
              echo "Hello world!"
              
              for($i = 1; $i < 10; $i++)
               echo " $i ";
              
              ?>
              


              6. View it in your browser. It works.

              I'm now testing out pgAdmin

              • 4. Re: PHP on TOMCAT
                Eric H Novice

                With some difficulty, I got Quercus to talk to the Postgres JDBC. It requires a very precise JNDI config. Anyway, it works, and I feel that any PHP app that requires only one database to interact with would have a very good shot at running smoothly in Quercus under JBoss or Tomcat.

                Unfortunately phpPgAdmin needs to use pg_connect to switch around to various databases, and Quercus only allows it to access one database, through a JNDI specification, so no luck on that until Quercus somehow lets pg_connect bypass using JNDI. If they could do that, phpPgAdmin would work.

                But that's an unusual application. Most normal PHP apps only need to connect to one database.

                And once it is running within Quercus it's pretty easy to let it work with Java code, EJBs, etc.

                • 5. Re: PHP on TOMCAT
                  Jean-Frederic Clere Master

                  JBoss propose a php extension via a php-servlet see http://www.jboss.org/jbossweb/modules/php/index.html
                  postgresql is included in the bundle.

                  • 6. Re: PHP on TOMCAT
                    Eric H Novice

                     

                    "jfrederic.clere@jboss.com" wrote:
                    JBoss propose a php extension via a php-servlet see http://www.jboss.org/jbossweb/modules/php/index.html
                    postgresql is included in the bundle.


                    That's cool, but I would much rather use Quercus if possible. PHP's binaries have had enough security holes over the years I would rather not touch them. Also Quercus lets me access Java code from within a PHP script in a very nice way.

                    • 7. Re: PHP on TOMCAT
                      Billy Murphy Newbie

                       

                      "jfrederic.clere@jboss.com" wrote:
                      JBoss propose a php extension via a php-servlet see http://www.jboss.org/jbossweb/modules/php/index.html
                      postgresql is included in the bundle.


                      Thanks jfrederic, I found this page earlier and have been using it as a guideline.

                      The pre compiled libphp5servlet files i come across on my treks complain about various missing resources so Ive been compiling using the buildphp.sh on my machine to get the right file.

                      For me, buildphp.sh executes fine right up to the end, right to where its going to create libphp5servlet and then....skips it...dohh and double dohh or dratt and double dratt as the saying goes.

                      Maybe its automagic on later jbossAS, the 5 series, I see that ruby has just come out with a similiar integration, http://oddthesis.org/theses/jboss-rails.

                      Anyway, I've got my base functionality working by executing the php as cgi but integrating my php tighter with jboss, is still ongoing, im hoping that one of these days i will get by that last unsatisfied link error and explode into a world of tightly coupled php and jsp.

                      Do i really want to though ?? Are there security concerns with PHP ?

                      Also, it looks like you might have some competition in the AS space.

                      Plus, you can follow this discussion in stereo at you can also follow this discussion in stereo at http://www.techienuggets.com/Comments?tx=60362


                      • 8. Re: PHP on TOMCAT
                        Billy Murphy Newbie

                         

                        "EricJava" wrote:
                        Check out http://www.caucho.com/resin-3.0/quercus/


                        Thanks EricJava, that looks an interesting out of the box solution

                        • 9. Re: PHP on TOMCAT
                          Jean-Frederic Clere Master




                          For me, buildphp.sh executes fine right up to the end, right to where its going to create libphp5servlet and then....skips it...dohh and double dohh or dratt and double dratt as the saying goes.


                          Use ant to build the output and error will go in files where you should find what went wrong.

                          • 10. Re: PHP on TOMCAT
                            Billy Murphy Newbie

                            Thanks Again jfrederic,
                            i had been trying to pipe the output to a file, thats a very useful suggestion. I've pasted what looks relevant to my eye for convenience from the output.

                            According to John Q Logfile, theres no php5servlet directory in the build and no source file, php5servlet.c, so the compiler has no input.

                            .
                            .
                            .
                            [exec] Installing PDO headers: /home/tomcat/Linux_i686_tools/PHP/include/php/ext/pdo/
                            [exec] ./buildphp.sh: line 892: cd: php5servlet: No such file or directory
                            [exec] gcc: php5servlet.c: No such file or directory
                            [exec] gcc: no input files
                            [exec] ld: php5servlet.o: No such file: No such file or directory
                            [exec] libphp5servlet.so wasn't build, aborting...
                            [exec] ./buildphp.sh: line 913: php5servlet/Make.sh: No such file or directory
                            [exec] Result: 1
                            .
                            .
                            .


                            Should this have been created in the PHP make ? Im using the buildphp.sh from the jboss web site, theres no version number on it, its installing php version 5.2.3, if thats useful at all.

                            the PHP configure command looks like this ( id post the full file but dont think the forum supports it )

                            (cd php-${PHPVER}
                            ./configure --prefix=$TOOLS/PHP \
                            --cache-file=$CACHE \
                            --with-tsrm-pthreads --enable-shared \
                            --enable-embed=shared \
                            --enable-maintainer-zts \
                            \
                            --with-kerberos \
                            --with-imap-ssl \
                            --with-zlib-dir \
                            --with-ttf \
                            --with-bz2 \
                            --enable-bcmath \
                            --enable-calendar \
                            --enable-dbase \
                            --enable-dba \
                            --enable-exif \
                            --enable-filepro \
                            --enable-ftp \
                            --with-gettext \
                            --enable-mbstring \
                            --enable-shmop \
                            --enable-soap \
                            --enable-sockets \
                            --enable-sysvmsg \
                            --enable-sysvsem \
                            --enable-sysvshm \
                            --enable-wddx \
                            --with-xmlrpc \
                            \
                            --without-pear \
                            --with-ncurses=no \
                            --with-fbsql=no \
                            --with-fdftk=no \
                            --with-gmp=no \
                            --with-hwapi=no \
                            --with-informix=no \
                            --with-interbase=no \
                            --with-ming=no \
                            --with-mssql=no \
                            --with-oci8=no \
                            --with-pdo-oci=no \
                            --with-pdo-dblib=no \
                            --with-pdo-firebird=no \
                            --with-pdo-odbc=no \
                            --with-libedit=no \
                            --disable-reflection \
                            --with-snmp=no \
                            --disable-spl \
                            --with-sybase=no \
                            --with-sybase-ct=no \
                            --with-recode=no \
                            --with-mcrypt=no \
                            --with-mhash=no \
                            \
                            --with-msql=no \
                            \
                            ${ADDCONF}



                            • 11. Re: PHP on TOMCAT
                              Jean-Frederic Clere Master

                              exec] ./buildphp.sh: line 892: cd: php5servlet: No such file or directory

                              You have to checkout the whole http://anonsvn.jboss.org/repos/jbossreflex/trunk/php/ it contains a subdirectory named php5servlet.

                              I have arranged the doc it should be more easy to follow now.

                              • 12. Re: PHP on TOMCAT
                                Billy Murphy Newbie

                                Thanks JFrederic,
                                Previously, I had been trying to get the libphp5 files from PHP binaries with axps2 configured and thought buildphp.sh was doing something similiar.

                                Consequently, I was running buildphp on its own. You made it too easy by including the php5servlet directory in the project directory. It was pretty clear all along, in truth, the more I go through the process and
                                learn, the more straightforward it becomes.

                                So, I compiled succesfully. untarred in $JBOSS_HOME and added the descriptions to web.xml.

                                On start up, I have trouble with libxml2.so, i think....undefined symbol: xmlTextReaderSchemaValidate .

                                I tried setting the LD_LIBRARY_PATH different ways, i tried it in run.sh just in case run.conf wasnt picked up and I also copied the files from the tarball into the /usr/lib/jdk1.5../.../server

                                I have spent some time trying to cajole it into seeing the libxm2.so group but im hitting a dead end

                                Here's the path setting from my run.sh and the error from the server startup ?

                                I greatly appreciate the help, You can forget how painful it was to learn to walk when you do it every day. Then you try something new on the computer and oh boy, the bruises may be mental but you are glad of the time spent when you are walking around on two legs.

                                run.sh :

                                LD_LIBRARY_PATH=/jboss/jboss-4.0.2/PHP/lib:jboss/jboss-4.0.2/bin/native;
                                export LD_LIBRARY_PATH;


                                server.log :
                                2008-11-24 13:38:34,846 DEBUG [org.jboss.web.tomcat.filters.ReplyHeaderFilter] Adding header name: X-Powered-By='Servlet 2.4; JBoss-4.0.2 (build: CVSTag=JBoss_4_0_2 date=200505022023)/Tomcat-5.5'
                                2008-11-24 13:38:34,915 DEBUG [org.jboss.invocation.http.servlet.InvokerServlet] localInvokerName=jboss:service=invoker,type=http
                                2008-11-24 13:38:35,044 ERROR [org.apache.catalina.core.ContainerBase.[jboss.web].[localhost].[/invoker]] StandardWrapper.Throwable
                                java.lang.UnsatisfiedLinkError: /usr/lib/jdk1.5.0_15/jre/lib/i386/server/libphp5servlet.so: /usr/lib/jdk1.5.0_15/jre/lib/i386/server/libphp5.so: undefined symbol: xmlTextReaderSchemaValidate, no libphp5servlet in java.library.path(/usr/lib/jdk1.5.0_15/jre/lib/i386/server:/usr/lib/jdk1.5.0_15/jre/lib/i386:/usr/lib/jdk1.5.0_15/jre/../lib/i386:/jboss/jboss-4.0.2/PHP/lib:/jboss/jboss-4.0.2/bin/native)
                                at org.jboss.web.php.Library.<init>(Library.java:65)
                                at org.jboss.web.php.Library.initialize(Library.java:104)


                                • 13. Re: PHP on TOMCAT
                                  Jean-Frederic Clere Master

                                   

                                  LD_LIBRARY_PATH=/jboss/jboss-4.0.2/PHP/lib:jboss/jboss-4.0.2/bin/native;
                                  export LD_LIBRARY_PATH;

                                  and
                                  java.lang.UnsatisfiedLinkError: /usr/lib/jdk1.5.0_15/jre/lib/i386/server/libphp5servlet.so: /usr/lib/jdk1.5.0_15/jre/lib/i386/server/libphp5.so: undefined symbol: xmlTextReaderSchemaValidate, no libphp5servlet in java.library.path(/usr/lib/jdk1.5.0_15/jre/lib/i386/server:/usr/lib/jdk1.5.0_15/jre/lib/i386:/usr/lib/jdk1.5.0_15/jre/../lib/i386:/jboss/jboss-4.0.2/PHP/lib:/jboss/jboss-4.0.2/bin/native)


                                  That looks fishy: The libphp5.so is in one place and you set LD_LIBRARY_PATH to another one. Follow the doc and don't try to put the bundle insde the JVM installation path.

                                  1 - Check if you have a libxml2.so in the php bundle. If not something went wrong will building.
                                  2 - Use ldd libphp5.so and LD_LIBRARY_PATH to find the right value for LD_LIBRARY_PATH
                                  3 - Use nm on libxml2.so to check that xmlTextReaderSchemaValidate is an exported symbol.

                                  • 14. Re: PHP on TOMCAT
                                    Billy Murphy Newbie

                                     

                                    X-Powered-By='Servlet 2.4; JBoss-4.0.2 (build: CVSTag=JBoss_4_0_2 date=200505022023)/Tomcat-5.5'

                                    2008-11-25 17:33:33,485 INFO [org.apache.catalina.core.ContainerBase.[jboss.web].[localhost].[/php-examples]] php: init: loglevel set to 0

                                    2008-11-25 17:33:33,487 INFO [org.apache.catalina.core.ContainerBase.[jboss.web].[localhost].[/php-examples]] demophp: init: loglevel set to 0


                                    Ahhhhhhh, the sweet type of Sucesss !!

                                    Yes, My dependancies were messed up, no doubt from my installation attempts prior to coming to the forum.

                                    An ldd showed that libphp5 was referencing /usr/local/lib/libxml2.so. Plus this was an older copy of the libxml2.so ( libxml2.so.2.6.11 ) which must not have had xmlTextReaderSchemaValidate.

                                    So after changing the LD_LIBRARY_PATH, and getting the same problem i copied the libxml2.so.2.6.32, generated from the succesful compile, along with the links into usr/local/lib/ and along with the aforementioned changes to LD_LIBRARAY_PATH to include /usr/local/lib, I am walking on two legs ! I will reinstall everything from scratch to make a cleaner installation. Thank heavens for virtual machines.

                                    I do not know that i will use a lot of php, but now that I can....it makes my jboss more versatile particularly at hosting applciations that want to drop in web2.0 dodads and whatsits. Hurrah. Onward !

                                    This process brought me a little deeper into linux than i have been. I think with stronger knowledge to start, this installation would have gone a lot quicker on my part.

                                    JFrederic, you are the man.