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 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)
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
< ?php phpinfo(); ?>
Goto http://yourserver/blog/test.php
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….
Hi thank for your tuto.
I follow your instruction, until i see tomcat admin interface. But the php file didn’t walk.
thank you to answer me.