Install Php On Tomcat 8 Manager

This practical can be completed in a 3-hour session.

  1. Tomcat 8 Download
  2. Install Tomcat 8 Ubuntu
  3. Install Php On Tomcat 8 Managerial Functions
  4. Running Php On Tomcat Server
  5. Php On Tomcat 7

This installation and configuration guide is applicable to Tomcat 9, and possibly the earlier versions. Take note that Tomcat 9 requires JDK 8 and later.

As a starter guide, this article explains how to install Apache Tomcat 8, the latest stable version of Apache Tomcat, onto a Vultr CentOS 7 server instance. Prerequisites Before further reading, you need to. As a starter guide, this article explains how to install Apache Tomcat 8, the latest stable version of Apache Tomcat, onto a Vultr CentOS 7 server instance. Before further reading, you need to. In order to use the 'Manager App' and the 'Host manager' in the Apache Tomcat web interface, you need to create an admin user for. In this tutorial we will show you how to install and configuration of Apache Tomcat 8 on your Ubuntu 16.04 server. For those of you who didn’t know, Apache Tomcat is an open source web server and servlet container developed by the Apache Software Foundation. This tutorial shows you how to install Tomcat 8.5 on CentOS 7. Tomcat is an open source implementation of the Java Servlet, JavaServer Pages, Java Expression Language and Java WebSocket technologies.

Introduction

Web Application (Webapp)

A web application (or webapp), unlike standalone application, runs over the Internet. Examples of webapps are google, amazon, facebook and twitter.

A webapp is typically a 3-tier (or multi-tier) client-server database application run over the Internet as illustrated in the diagram below. It comprises five components:

  1. HTTP Server: E.g., Apache HTTP Server, Apache Tomcat Server, Microsoft Internet Information Server (IIS), nginx, Google Web Server (GWS), and others.
  2. HTTP Client (or Web Browser): E.g., Internet Explorer (MSIE), FireFox, Chrome, Safari, and others.
  3. Database: E.g., Open-source MySQL, PostgreSQL, Apache Derby, mSQL, SQLite, OpenOffice's Base; Commercial Oracle, IBM DB2, SAP SyBase, Microsoft SQL Server, Microsoft Access; and others.
  4. Client-Side Programs: Could be written in HTML Form, JavaScript, and others.
  5. Server-Side Programs: Could be written in Java Servlet/JSP, ASP, PHP, Perl, Python, JavaScript, and others.

A typical use case is:

  1. A user, via a web browser (HTTP client), issues a URL request to an HTTP server to start a webapp.
  2. The HTTP server returns an HTML form (client-side program), which is loaded and renderred in the client's browser.
  3. The user fills up the query criteria inside the form and submits the form.
  4. The client-side program sends the query parameters to a server-side program.
  5. The server-side program receives the query parameters, queries the database based on these parameters, and returns the query result to the client-side program.
  6. The client-side program receives the query result and displays on the browser.
  7. The process repeats for the next request-response.

Hypertext Transfer Protocol (HTTP)

  • HTTP is an application layer protocol runs over TCP/IP. The IP provides support for routing and addressing (via an unique IP address for machines connected to the Internet); while TCP supports multiplexing via 64K ports from port number 0 to 65535. The default port number assigned to HTTP is TCP port 80. (Notes: TCP Port numbers below 1024 are reserved for popular protocols such as HTTP, FTP, SMTP; Port numbers 1024 and above could be used for applications.)
  • HTTP is an asynchronous request-response application-layer protocol. A client sends a request message to the server. The server then returns a response message to the client. In other words, HTTP is a pull protocol, a client pulls a page from the server (instead of server pushes pages to the clients).
  • The syntax of the message is defined in the HTTP specification.

Apache Tomcat HTTP Server

Apache Tomcat is a Java-capable HTTP server, which could execute special Java programs known as 'Java Servlet' and 'Java Server Pages (JSP)'. Tomcat is an open-source project, under the 'Apache Software Foundation' (which also provides the most use, open-source, industrial-strength Apache HTTP Server). The mother site for Tomcat is http://tomcat.apache.org. Alternatively, you can find tomcat via the Apache mother site @ http://www.apache.org.

Tomcat was originally written by James Duncan Davison (then working in Sun) in 1998, based on an earlier Sun's server called Java Web Server (JWS). It began at version 3.0 after JWS 2.1 it replaced. Sun subsequently made Tomcat open-source and gave it to Apache.

The various Tomcat releases are:

  1. Tomcat 3.0 (1999): Reference Implementation (RI) for Servlet 2.2 and JSP 1.1.
  2. Tomcat 4.1 (Sep 2002): RI for Servlet 2.3 and JSP 1.2.
  3. Tomcat 5.0 (Dec 2003): RI for Servlet 2.4 and JSP 2.0.
  4. Tomcat 6.0 (Feb 2007): RI for Servlet 2.5 and JSP 2.1.
  5. Tomcat 7.0 (Jan 2011): RI for Servlet 3.0, JSP 2.2 and EL 2.2.
  6. Tomcat 8.0 (Jun 2014): RI for Servlet 3.1, JSP 2.3, EL 3.0 and WebSocket 1.0. Tomcat 8.5 (June 2016) supports HTTP/2, OpenSSL, TLS virtual hosting and JASPIC 1.1.
  7. Tomcat 9.0 (Jan 2018): RI for Servlet 4.0, JSP 2.3, EL 3.0, WebSocket 1.0, JASPIC 1.1.
  8. Tomcat 10.0 (???):

How to Install Tomcat and Get Started with Java Servlet Programming

STEP 0: Create a Directory to Keep all your Works

I shall assume that you have created a directory called 'c:myWebProject' (for Windows) or '~myWebProject' (for Mac OS X) in your earlier exercises. Do it otherwise. This step is important; otherwise, you will be out-of-sync with this article and will not be able to find your files later.

STEP 1: Download and Install Tomcat

For Windows

  1. Goto http://tomcat.apache.org ⇒ Under 'Tomcat 9.0.{xx} Released', where {xx} is the latest update number ⇒ Click 'Download' ⇒ Under '9.0.{xx}' ⇒ Binary Distributions ⇒ Core ⇒ 'zip' (e.g., 'apache-tomcat-9.0.{xx}.zip', about 11 MB).
  2. UNZIP the downloaded file into your project directory 'c:myWebProject'. Tomcat shall be unzipped into directory 'c:myWebProjectapache-tomcat-9.0.{xx}'.
  3. For EASE OF USE, we shall shorten and rename this directory to 'c:myWebProjecttomcat'.

Take note of Your Tomcat Installed Directory. Hereafter, I shall refer to the Tomcat installed directory as <TOMCAT_HOME>.

For Mac OS X

  1. Goto http://tomcat.apache.org ⇒ Under 'Tomcat 9.0.{xx} Released', where {xx} is the latest update number ⇒ Click 'Download' ⇒ Under '9.0.{xx}'⇒ Binary distribution ⇒ Core ⇒ 'tar.gz' (e.g., 'apache-tomcat-9.0.{xx}.tar.gz', about 10.5 MB).
  2. To install Tomcat:
    1. Double-click the downloaded tarball (e.g., 'apache-tomcat-9.0.{xx}.tar.gz') to expand it into a folder (e.g., 'apache-tomcat-9.0.{xx}').
    2. Move the extracted folder (e.g., 'apache-tomcat-9.0.{xx}') to your project directory '~/myWebProject'.
    3. For EASE OF USE, we shall shorten and rename this folder to 'tomcat', i.e., '~/myWebProject/tomcat'.

Take note of Your Tomcat Installed Directory. Hereafter, I shall refer to the Tomcat installed directory as <TOMCAT_HOME>.

For Ubuntu

Read 'How to Install Tomcat on Ubuntu'. You need to switch between these two articles.

For academic learning, I recommend 'zip' (or 'tar.gz') package, as you could simply delete the entire directory when Tomcat is no longer needed (without running any un-installer). You are free to move or rename the Tomcat's installed directory. You can install (unzip) multiple copies of Tomcat in the same machine.

Tomcat's Sub-Directories

Take a quick look at the Tomcat installed directory. It contains the these sub-directories:

  • bin: contains the binaries and scripts (e.g., startup.bat and shutdown.bat for Windows; startup.sh and shutdown.sh for Unixes and Mac OS X).
  • conf: contains the system-wide configuration files, such as server.xml, web.xml, and context.xml.
  • webapps: contains the webapps to be deployed. You can also place the WAR (Webapp Archive) file for deployment here.
  • lib: contains the Tomcat's system-wide library JAR files, accessible by all webapps. You could also place external JAR file (such as MySQL JDBC Driver) here.
  • logs: contains Tomcat's log files. You may need to check for error messages here.
  • work: Tomcat's working directory used by JSP, for JSP-to-Servlet conversion.

STEP 2: Create an Environment Variable JAVA_HOME

(For Windows)

You need to create an environment variable (system variable available to all applications) called 'JAVA_HOME', and set it to your JDK installed directory.

Follow the steps HERE!

(For Mac OS)

Skip this step. No need to do anything.

STEP 3: Configure the Tomcat Server

The Tomcat configuration files, in XML format, are located in the 'conf' sub-directory of your Tomcat installed directory, e.g. 'c:myWebProjecttomcatconf' (for Windows) or '~/myWebProject/tomcat/conf' (for Mac OS X). The important configuration files are:

  1. server.xml
  2. web.xml
  3. context.xml

Make a BACKUP of the configuration files before you proceed!!!

Step 3(a) 'confserver.xml' - Set the TCP Port Number

Use a programming text editor (e.g., Sublime Text, Atom) to open the configuration file 'server.xml'.

The default TCP port number configured in Tomcat is 8080, you may choose any number between 1024 and 65535, which is not used by existing applications. We shall choose 9999 in this article. (For production server, you should use port 80, which is pre-assigned to HTTP server as the default port number.)

Locate the following lines (around Line 69) that define the HTTP connector, and change port='8080' to port='9999'.

Step 3(b) 'confweb.xml' - Enable Directory Listing

Again, use a programming text editor to open the configuration file 'web.xml'.

Tomcat 8 Download

We shall enable directory listing by changing 'listings' from 'false' to 'true' for the 'default' servlet. This is handy for test system, but not for production system for security.

Locate the following lines (around Line 108) that define the 'default' servlet; and change the 'listings' from 'false' to 'true'.

Step 3(c) 'confcontext.xml' - Enabling Automatic Reload

We shall add the attribute reloadable='true' to the <Context> element to enable automatic reload after code changes. Again, this is handy for test system but not recommended for production, due to the overhead of detecting changes.

Locate the <Context> start element (around Line 19), and change it to <Context reloadable='true'>.

STEP 4: Start Tomcat Server

The Tomcat's executable programs and scripts are kept in the 'bin' sub-directory of the Tomcat installed directory.

Step 4(a) Start Server

For Windows

I shall assume that Tomcat is installed in 'c:myWebProjecttomcat'. Launch a CMD shell and issue:

For Mac OS

I assume that Tomcat is installed in '~/myWebProject/tomcat'. To start the Tomcat server, open a new 'Terminal' and issue:

A new Tomcat console window appears (with Java's coffee-cup logo as icon). Study the messages on the console. Look out for the Tomcat's port number. Double check that Tomcat is running on port 9999 as configured.

Error messages will be sent to this console. System.out.println() issued by your Java servlets will also be sent to this console.

(Skip Unless ..) Cannot Start Tomcat: Read 'How to Debug'.

Step 4(b) Start a Client to Access the Server

Start a browser (Firefox, Chrome) as an HTTP client. Issue URL 'http://localhost:9999' to access the Tomcat server's welcome page. The hostname 'localhost' (with IP address of 127.0.0.1) is meant for local loop-back testing within the same machine. For users on the other machines over the net, they have to use the server's IP address or DNS domain name in the form of 'http://serverHostnameOrIPAddress:9999'.

(Optional) Try issuing URL http://localhost:9999/examples to view the servlet and JSP examples. Try running some of the servlet examples.

Step 4(c) Shutdown Server

For Windows

You can shutdown the tomcat server by either:

  1. Press Ctrl-C on the Tomcat console; OR
  2. Run '<TOMCAT_HOME>binshutdown.bat' script. Open a new 'cmd' and issue:

For Mac OS

To shutdown the Tomcat server:

  1. Press Control-C (NOT Command-C) on the Tomcat console; OR
  2. Run the '<TOMCAT_HOME>/bin/shutdown.sh' script. Open a new 'Terminal' and issue:

WARNING: You MUST properly shutdown the Tomcat. DO NOT kill the CAT by pushing the window's 'CLOSE' button.

STEP 5: Develop and Deploy a WebApp

Step 5(a) Create the Directory Structure for your WebApp

Let's call our first webapp 'hello'. Goto Tomcat's 'webapps' sub-directory and create the following directory structure for your webapp 'hello' (as illustrated):

  1. Under Tomcat's 'webapps', create your webapp's root directory 'hello' (i.e., '<TOMCAT_HOME>webappshello').
  2. Under 'hello', create a sub-directory 'WEB-INF' (case sensitive, a 'dash' not an underscore) (i.e., '<TOMCAT_HOME>webappshelloWEB-INF').
  3. Under 'WEB-INF', create a sub-sub-directory 'classes' (case sensitive, plural) (i.e., '<TOMCAT_HOME>webappshelloWEB-INFclasses').

You need to keep your web resources (e.g., HTMLs, CSSs, images, scripts, servlets, JSPs) in the proper directories:

  • 'hello': The is called the context root (or document base directory) of your webapp. You should keep all your HTML files and resources visible to the web users (e.g., HTMLs, CSSs, images, scripts, JSPs) under this context root.
  • 'hello/WEB-INF': This directory, although under the context root, is not visible to the web users. This is where you keep your application's web descriptor file 'web.xml'.
  • 'hello/WEB-INF/classes': This is where you keep all the Java classes such as servlet class-files.

You should RE-START your Tomcat server to pick up the hello webapp. Check the Tomcat's console to confirm that 'hello' application has been properly deployed:

Hp tx1000 video driver for windows 7. You can issue the following URL to access the web application 'hello':

You should see the directory listing of the directory '<TOMCAT_HOME>webappshello', which shall be empty at this point of time. Take note that we have earlier enabled directory listing in 'web.xml'. Otherwise, you will get an error '404 Not Found'.

Step 5(b) Write a Welcome Page

Create the following HTML page and save as 'HelloHome.html' in your webapp's root directory 'hello'.

You can browse this page by issuing this URL:

Alternatively, you can issue an URL to your webapp's root 'hello':

The server will return the directory listing of your base directory. You can then click on 'HelloHome.html'.

Rename 'HelloHome.html' to 'index.html', and issue a directory request again:

Now, the server will redirect the directory request to 'index.html', if the root directory contains an 'index.html', instead of serving the directory listing.

You can check out the home page of your peers by issuing:

with a valid 'YourPeerHostnameOrIPAddr', provided that your peer has started his tomcat server and his firewall does not block your access. You can use command such as 'ipconfig' (Windows), 'ifconfig' (Mac OS X and Unix) to find your IP address.


(Skip Unless..) The likely errors are 'Unable to Connect', 'Internet Explorer cannot display the web page', and '404 File Not Found'. Read 'How to Debug' section.

STEP 6: Write a 'Hello-world' Java Servlet

A servlet is Java program that runs inside a Java-capable HTTP Server, such as Apache Tomcat. A web user invokes a servlet by issuing an appropriate URL from a web browser (HTTP client).

Before you proceed, I shall assume that you are familiar with Java Programming and have installed the followings:

  1. JDK (Read 'How to install JDK and Get Started').
  2. A programming text editor, such as Sublime Text or Atom.
Step 6(a) Write a 'Hello-world' Java Servlet

A Java servlet is a Java program that runs inside a HTTP server. A web user invokes a servlet by issuing a URL from a browser (or HTTP client).

In this example, we are going to write a Java servlet called HelloServlet, which says 'Hello, world!'. We will configure such that web users can invoke this servlet by issuing URL http://ip_addr:port/hello/sayhello from their browser, as illustrated:

Write the following source codes called 'HelloServlet.java' and save it under your application 'classes' directory (i.e., '<TOMCAT_HOME>webappshelloWEB-INFclassesHelloServlet.java'). This servlet says 'Hello', echoes some request information, and prints a random number upon each request.

Take note that in Line 7, we configure this HelloServlet to URL '/sayhello' via annotation @WebServlet('/sayhello'), which is applicable to Tomcat 7 onwards. In other words, the full URL shall be http://ip_addr:port/hello/sayhello to trigger this HelloServlet.

Step 6(b) Compiling the Servlet (DIFFICULT)

We need the Java Servlet API to compile the servlet. Servlet API is NOT part of JDK. Tomcat provides a copy in <TOMCAT_HOME>/lib/servlet-api.jar. We need to include this JAR file in the compilation via the -cp (classpath) option as follows:

(For Mac OS)

The output of the compilation is 'HelloServlet.class'.

Use your 'File Explorer' to check the 'webapps/hello/WEB-INF/classes' folder to make sure that 'HelloServlet.class' has been created in the right place.

Step 6(c) Invoke the Servlet

Restart your Tomcat Server (just in case ..).

To invoke this servlet, start a browser, and issue the request URL configured as follows:

You shall see the output of the servlet displayed in your web browser.

Refresh the browser, you shall see a new random number upon each refresh. In other word, the doGet() method of the servlet runs once per request.

View Page Source

(For Firefox and Chrome) Right-click the page ⇒ 'View Page Source' to look at the output received by the web browser (which is returned by the server). Take note that the web browser receives only the output of the servlet (generated via the out.println() statements). The client has no access to the servlet source codes (which may contain confidential information).

(For Mac OS's Safari browser) You need to enable 'Developer Menu' under the 'Preferences' to enable the 'View Source' menu.


(Skip Unless..) The likely errors are '404 File Not Found' and '500 Internal Server Error'. Read 'How to debug' Section.

(Optional) Inspecting HTTP Request and Response Messages

When you enter a URL (e.g., http://localhost:9999/hello/sayhello) on a web browser, an HTTP GET request message is sent to the server; and the server returns a response message for display on the web browser. You can inspect the request and response messages via Web browser's Developer Tool.

For Firefox/Chrome, press F12 (called F12 debugger) to enable 'Web Console' or 'Developer Tool'. Choose 'Console' or 'Network' pane. Enter URL http://localhost:9999/hello/sayhello (or refresh). Enable 'Net' (not in Gray). Expand the link http://localhost:9999/hello/sayhello. A HTTP message consists of a header and a body. Inspect the request header and body; as well as the response header and body.

The request message header is as follows:

For this request, there is no request message body.

The response message header is as follows:

The response message body is as follows:

STEP 7: Write a Database Servlet

This section assumes that you are familiar with 'Java database programming' and 'MySQL database server'. Otherwise, read 'Java Database Program' and 'How to Install MySQL and Get Started', respectively.

Step 7(a) Setup a Database on MySQL (Already done in the MySQL exercises)

Start your MySQL server. Take note of the server's port number. I shall assume that the MySQL server is running on port 3306, whereas the Tomcat is running on port 9999.

Start a MySQL client. I shall assume that there is a user called 'myuser' with password 'xxxx'.

Run the following SQL statements to create a database called 'ebookshop', with a table called 'books' with 5 columns: id, title, author, price, qty.

Step 7(b) Install MySQL JDBC Driver (Already done in the previous JDBC exercises)

You need to download MySQL JDBC driver if you have not done so. Read 'Installing the MySQL JDBC Driver'.

Step 7(c) Copy the MySQL JDBC Drive to Tomcat's 'lib' (IMPORTANT!!!)

Copy the MySQL JDBC Driver JAR file 'mysql-connector-java-8.0.{xx}.jar' into Tomcat's lib directory, i.e., 'c:myWebProjecttomcatlib' (for Windows) or '~myWebProjecttomcatlib' (Mac OS).

Step 7(d) Write a Client-side HTML Form

Let's write an HTML script to create a query form with 3 checkboxes and a submit button, as illustrated below. Save the HTML file as “querybook.html” in your application root directory “<TOMCAT_HOME>webappshello”.


You can browse the HTML page by issuing the following URL:

Check a box (e.g., 'Tan Ah Teck') and click the 'Search' button. You are expected to get an error '404 File Not Found', as you have yet to write the server-side program.

But observe the URL in the browser's navigation bar, reproduced as follows:

The URL request consists of two part: a URL corresponding to the 'action' attribute of the <form> tag, and the 'name=value' pair extracted from the <input> tag, separated by a '?'. Take note that blanks are replaced by '+' (or %20), because blanks are not allowed in the URL.

If you check two boxes (e.g., 'Tan Ah Teck' and 'Mohammad Ali'), you will get this URL, which has two 'name=value' pairs separated by an '&'.

Step 7(e) Write the Server-side Database Query Servlet

The next step is to write a Java servlet, which responses to the client’s request by querying the database and returns the query results.

Take note that in Line 8, we configure this QueryServlet to URL '/query' via annotation @WebServlet('/query'). In other words, the full URL to trigger this QueryServlet is http://ip_addr:port/hello/query, which corresponds to the 'action' attribute of the <form> tag of the 'querybook.html' written earlier.

Compile 'QueryServlet.java' as follows:

Use a 'File Explorer', verify that 'QueryServlet.class' was generated in the 'classes' directory.

Step 7(f) Invoke the Servlet from the Client-Side Form

Issue the following URL to browse the HMTL form 'querybook.html' that you have created earlier:

Select an author (e.g., 'Tan Ah Teck') and click the submit button, which activates the following URL coded in the <form>'s 'action' attribute, together with the name=value pair:

This URL '/query' triggers QueryServlet. The QueryServlet retrieves the name=value pair of 'author=Tan+Ah+Teck'. Inside the QueryServlet, the method request.getParameter('author') returns 'Tan Ah Teck', which is inserted into the SQL SELECT command to query the database. The processed query result is then written to the client as an HTML document.

(Skip Unless..) If you see a blank screen or incorrect output, look for error messages from the Tomcat console!!! Check 'How to debug' Database Servlet Errors.

(Archive)(Prior to Tomcat 7) Deploying Servlets using web.xml

Please skip this section. I keep it here just in case..

The annotation @WebServlet('url') for deploying servlet is supported from Tomcat 7/Servlet 3.0. Prior to Tomcat 7, you need to deploy servlets via deployment descriptors in the web.xml configuration file.

Create the following configuration file called 'web.xml', and save it under 'webappshelloWEB-INF' (i.e., '<TOMCAT_HOME>webappshelloWEB-INFweb.xml').

In the above configuration, a servlet having a class file 'HelloServlet.class' is mapped to request URL '/sayhello' (via an arbitraryservlet-name 'HelloWorld'), under this web application 'hello'. In other words, the complete request URL for this servlet is 'http://hostname:port/hello/sayhello'.

This configuration file, saved under your webapp 'hello', is applicable only to this particular webapp 'hello'.

Restart your Tomcat server to refresh the 'web.xml' file.

Note: For EACH servlet, you need to write a pair of <servlet> and <servlet-mapping> elements with a common but arbitrary <servlet-name>. Take note that all the <servlet> elements MUST be grouped together and placed IN FRONT of the <servlet-mapping> elements.

(Skip Unless..) How to Debug?

'Everything that can possibly go wrong will go wrong.' The most important thing to do is to find the ERROR MESSAGES!!!

Always..
  1. Refresh your browser using Cntl-F5 (instead of refresh button or simply F5) to get a fresh copy, instead of from the cache.
  2. You may re-start your Tomcat server. You may also re-start your browser to clear the cache.
  3. Check your spelling! Always assume that all programs are case-sensitive. Don't type, copy and paste if possible!
  4. and MOST IMPORTANTLY - Find the ERROR MESSAGE!!!
    1. Check the Error Messages on Tomcat's Console. Most of the error messages have a few screens of lines. You need to scroll up slowly from the last line to look for the FIRST LINE of the error messages.
    2. Check the Tomcat's log files, located at '<TOMCAT_HOME>logs'. The 'catalina.yyyy-mm-dd.log' shows the Tomcat's startup messages. Also check the 'localhost.yyyy-mm-dd.log'.
  5. If things were running fine until the lightning strikes, ask yourself 'What have I changed?'

Cannot Start Tomcat after Installation


Locating/Killing Tomcat's Process
  • In windows, start 'Task Manager', Tomcat run as a 'process' named 'java.exe'. You may need to kill the process.
  • In Mac OS, start 'Activity Monitor'. Select 'All Processes' and look for 'java.exe'.
  • In Linux/Mac OS, you may issue 'ps aux grep tomcat' to locate the Tomcat process. Note down the process ID (pid). You can kill the Tomcat process via 'kill -9 pid'.

Cannot Access the Tomcat Server From Browser

Java Servlet Errors


Java Database Servlet Errors

REFERENCES & RESOURCES

  1. Apache Tomcat mother site @ http://tomcat.apache.org.
  2. Apache Tomcat Documentation @ '<TOMCAT_HOME>webappsdocs'.
  3. 'How to install MySQL and Get Started'.
  4. 'Introduction to Java Database (JDBC) Programming'.
  5. Jason Brittain, Ian F. Darwin, 'Tomcat The Definitive Guide', 2nd eds, OReilly, 2007.
Active8 months ago

Is it possible to run a PHP app using tomcat?

Before you tell me to just use httpd, I already have a Java application running on my webserver at host/myapp. Now I want to install RoundCube at host/roundcube.

One is PHP and one is Java. I keep seeing offhand references saying this is possible but no real instructions. I do not want to put them on separate ports, I need the standard HTTP and HTTPS ports.

Does anyone have any resources for this?

Mark
4,1824 gold badges16 silver badges34 bronze badges
GBaGBa
6,70415 gold badges45 silver badges66 bronze badges

8 Answers

Install Tomcat 8 Ubuntu

Yes it is Possible Will Den. we can run PHP code in tomcat server using it's own port number localhost:8080

here I'm writing some step which is so much useful for you.

How to install or run PHP on Tomcat 6 in windows

  1. download and unzip PHP 5 to a directory, c:php-5.2.6-Win32 - php-5.2.9-2-Win32.zip Download

  2. download PECL 5.2.5 Win32 binaries - PECL 5.2.5 Win32 Download

  3. rename php.ini-dist to php.ini in c:php-5.2.6-Win32

  4. Uncomment or add the line (remove semi-colon at the beginning) in php.ini:;extension=php_java.dll

  5. copy php5servlet.dll from PECL 5.2.5 to c:php-5.2.6-Win32

  6. copy php_java.dll from PECL 5.2.5 to c:php-5.2.6-Win32ext

  7. copy php_java.jar from PECL 5.2.5 to tomcatlib

  8. create a directory named 'php' (or what ever u like) in tomcatwebapps directory

  9. copy phpsrvlt.jar from PECL 5.2.5 to tomcatwebappsphpWEB-INFlib

  10. Unjar or unzip phpsrvlt.jar for unzip use winrar or winzip for unjar use : jar xfv phpsrvlt.jar

  11. change both netphpreflect.properties and netphpservlet.properties to library=php5servlet

  12. Recreate the jar file-> jar cvf php5srvlt.jar net/php/.PS: if the jar file doesnt run you have to add the Path to system variables for me I added C:Program FilesJavajdk1.6.0bin; to System variables/Path

  13. create web.xml in tomcatwebappsphpWEB-INF with this content:

  14. Add PHP path( c:php-5.2.6-Win32) to your System or User Path in Windows enironment (Hint: Right-click and select Properties from My Computer

  15. create test.php for testing under tomcatwebappsphp like

  16. Restart tomcat

  17. browse localhost:8080/php/test.php

Community
Saunik SinghSaunik Singh

It's quite common to run Tomcat behind Apache. In Apache you can then direct certain URLs to Tomcat, and have Apache/PHP handle the others (including the static images).

(On Unix, Tomcat itself cannot securely made to run on port 80, while Apache can. Tomcat, being a Java process, would be required to run as root, while Apache will switch to non-root privileges as soon as port 80 has been claimed. So, running Apache on port 80 and have it redirect some or all requests to Tomcat, is quite common on Unix.)

ArjanArjan
17.8k8 gold badges52 silver badges63 bronze badges
EquistaticEquistatic

A tad late, but here goes.

How about http://wiki.apache.org/tomcat/UsingPhp if you just want to run the real php on tomcat.

Concerning running tomcat on port 80 there's always jsvc, just google jsvc + tomcat.

philphil

There this PHP/Java bridge. This is basically running PHP via FastCGI. I have not used it myself.

Will HartungWill Hartung
97.4k18 gold badges112 silver badges189 bronze badges

tomcat is designed as JSP servlet container. Apache is designed PHP web server. Use apache as web server, responding for PHP request, and direct JSP servlet request to tomcat container. should be better implementation.

lwpro2lwpro2
17.6k3 gold badges24 silver badges19 bronze badges

If anyone's still looking - Quercus has a war that allows to run PHP scripts in apache tomcat or glassfish. For a step by step guide look at this article

mithil-studytrailsmithil-studytrails
  1. Make sure you have php installed on your server
  2. Find the latest release of php-java-bridge off of sourceforge
  3. From the exploded directory on Sourceforge, download php-servlet.jar and JavaBridge.jar
  4. Place those jar files into webapp/WEB-INF/lib folder of your project
  5. Edit webapp/WEB-INF/web.xml to look like:

ok

You may have other content inside this file, just make sure you have added everything between the web-app tag.

  1. Add your php files to the webapp directory

You can do other special things with this as well. You cal learn more about it here: http://php-java-bridge.sourceforge.net/pjb/how_it_works.php

Michael KernMichael Kern

Install Php On Tomcat 8 Managerial Functions

protected by CommunityJan 6 at 0:33

Running Php On Tomcat Server

Thank you for your interest in this question. Because it has attracted low-quality or spam answers that had to be removed, posting an answer now requires 10 reputation on this site (the association bonus does not count).
Would you like to answer one of these unanswered questions instead?

Php On Tomcat 7

Not the answer you're looking for? Browse other questions tagged phptomcatapache or ask your own question.