Integrate JSP and PHP in Apache

Source: Internet
Author: User
Tags php web server

We want everything to be perfect. For example, in enterprise applications, we only need to select a Web platform to deploy all enterprise applications. However, the ideal is often far from the reality. In the real world, information systems are often combined by many different operating systems, platforms, and application environments. In addition, in order to maintain compatibility with the old system, the system will always mix the current technology with the legacy technology, so that the cycle starts. The system becomes more and more complex.

Such a vicious change will make many people exhausted, especially developers, and they will face almost collapsed challenges. This is especially true when two or more technologies are deployed in the same application. In the example given in this article, the PHP and JSP programs are deployed simultaneously in the same application running in Apache. In this example, you can deploy these two Web programs quickly. Developers can also use this method to solve other similar problems.

A lot of people may ask, should I be able to deploy Web programs based on PHP and JSP in the same Web application as I did? Next I will answer this question. The basic answer to this question is to configure apache as a PHP Web server, use Apache to process all PHP/CGI requests, and use Tomcat to process all other requests, including JSP requests ). Before starting, Let's first look at the software we need:

The example in this article requires three software:
1. Apache HTTP Server
2. Apache Tomcat
3. Apache Tomcat Connectors

I. technologies used in the solution

We have several solutions to the above problems. These solutions are as follows:
1. Make the Apache server as the main or default request processor and pass only Servlet/JSP requests to the Java container.
2. Use the Java container as the main or default request processor and only allow PHP/CGI requests to be processed by Apache.
3. Do not use Apache and run the PHP/CGI program in Tomcat.

The first two solutions are similar. Both methods introduce a large number of requests to a certain Server Tomcat or Apache), and then use other servers to process individual requests in PHP and JSP ). The third method looks simple and attractive. However, Apache is very efficient in processing PHP and provides a safer mechanism. Therefore, Tomcat is not suitable for processing PHP programs.

In this article, we will adopt the second solution, that is, using Tomcat as the main Web server to receive most requests, and Apache as the backup server to process PHP/CGI requests, their relationship 1 is shown. If you have a special liking for the first method, you can easily set it based on the second method.

Figure1TomcatAs the main request processor,ApacheAs an auxiliary request processor

2. Release applications

Once we have correctly configured the environment, we can package the application and release it to the Web server. Publishing an application to Apache is no different from publishing it to Tomcat, and a WEB-INF/web is required. xml file, the difference is that if the request is a PHP or CGI program, it will bypass Tomcat and directly send it to Apache for processing.

Although changing the Apache root directory is 'dtdocs' by default) is not convenient for publishing applications. However, we can direct the Apache root directory to the Tomcat publishing directory. In this way, PHP/CGI can be in the same WAR/EAR package as JSP. You only need to put HTML. PHP and JSP pages in the directory to complete the release. This is very convenient for development and testing.

In addition, publishing PHP, JSP, and CGI to the same directory also allows them to share the same support file (CSS, JS, images, etc. Also, this model provides the complete structure of a Web application, and it is easier to call PHP/CGI programs from the Java Web directory ).

Iii. Summary

Whether you are required to integrate legacy Web applications into new Web programs or add an Open Source System to a custom Web application at work, or simply integrating two different Web applications, you may integrate different technologies into the same Web application. In a word, it is the best solution to switch different technologies to the same technology platform.

  1. Java Servlets (JSP) Development Environment
  2. Develop jsp http Server
  3. Select JSP development tools
  4. Servlet and JSP paths
  5. Technical Points for transferring in JSP Servlet

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.