11/30/2021

Apache Tomcat Php

In this article we look at how to run a php file in apache tomcat using Quercus. For those of you who have no clue why this article should exist, here is the complete story;

Apache tomcat php login

When Apache Tomcat 9.0.0.M1 to 9.0.28, 8.5.0 to 8.5.47, 7.0.0 and 7.0.97 is configured with the JMX Remote Lifecycle Listener, a local attacker without access to the Tomcat process or configuration files is able to manipulate the RMI registry to perform a man-in-the-middle attack to capture user names and passwords used to access the JMX interface. No - Tomcat is an application server based on Java, which is a different technology compared to PHP. Tomcat can run native Java code through war files, JSPs, JSFs. It doesn’t have the capability to process PHP code as PHP is non JDK compliant unlike Java. Hence, you can’t run PHP in tomcat. I installed PHP, Apache, Tomcat in Cent OS 5. Tomcat and Apache work fine together. The Source inside php is this php phpinfo;? //This works well only if the Filename is index.html but doesn't work if it's index.php. Running PHP applications in Tomcat 6 This guide shows how to install and run PHP applications like Moodle, mediaWiki, Joomla as Tomcat 6 web applications. And how to install PHP 5.x for all existing web applications. Download and install Java, Tomcat and PHP.

  • Apache Tomcat is a J2EE application server, which means, it can run web applications that have been written in java (J2EE)
  • If you ever want to run an application written in PHP in apache tomcat, you can’t with the default setup
  • Why would you want to run a PHP application on a J2EE server? Lets say, for example, you have a website that you have developed in J2EE but you want to add wordpress blog to it. There are multile ways to do it, but the one that we talk about here is using Quercus to process the php files (wordpress is all php)
Apache Tomcat PhpApache tomcat with phpTomcatApache Tomcat Php

So Here are the steps. we will start with a blank server on centos. For this tutorial we will install apache tomcat on /opt/server/. You will need to install gzip, wget and unzip for this tutorial. (yum install wget unzip gzip)

  • Step 1 : Install apache tomcat.

    cd /opt/server/
    wget http://www.carfab.com/apachesoftware/tomcat/tomcat-8/v8.0.9/bin/apache-tomcat-8.0.9.tar.gz (the latest version at the time of writing this post)
    gunzip apache-tomcat-8.0.9.tar.gz
    tar -xvf apache-tomcat-8.0.9.tar

    You should now have a folder called apache-tomcat-8.0.9 in /opt/server/
  • Step 2: Installing Quercus – We will install quercus in a way such that apache tomcat is able to process php files in the blog directory. i.e. http://yourserver.com/blog. Here are the steps

    cd /opt/server/apache-tomcat-8.0.9/webapps/
    mkdir blog
    cd blog
    wget http://caucho.com/download/quercus-4.0.39.war
    unzip quercus-4.0.39.war
    rm -f quercus-4.0.39.war
  • Step 3 : Starting apache tomcat

    cd /opt/server/apache-tomcat-8.0.9/bin/
    ./startup.sh

    In your browser type in http://yourserver/blog/ You should be able to see the quercus page. Now you can put your PHP files under blog directory and apache tomcat, with Quercus’ help, would be able to process them.
  • Step 4: Testing : Lets create a test page

    cd /opt/server/apache-tomcat-8.0.9/blog/
    vi test.php
    < ?phpphpinfo();?>

    Goto http://yourserver/blog/test.php

Apache Tomcat Php Login

The reason that we have used a blog directory is that in the next article we will look at how to install wordpress there. We will also
see how to write a Servlet Filter so that we can use a permalink that has only the postname. Till then….