Experience summary of server consolidation configuration under Windows apache+tomcat+mysql+jsp+php

Source: Internet
Author: User
Keywords Experience summary of server consolidation configuration under Windows apache+tomcat+mysql+jsp+php
Tags phpinfo apache tomcat

1. Author: moonsbird
Title: Experience Summary of server consolidation configuration under Windows apache+tomcat+mysql+jsp+php
Time: 2004.8.19
Originally published at Jincheng station, Southwest Jiaotong University
2. This article is a summary of the author's experience in learning jsp/Configuration Server environment for several years. Can be reproduced, but please indicate the source.

started to learn JSP for a long time, there are many examples of JSP integration on the Internet, but there are many problems.
for apache+tomcat+mysql+jsp+php, there is a slight difference between the different versions of Tomcat and Apache.
Even if you're good at E, looking at the manuals for Tomcat and Apache doesn't necessarily integrate successfully. Summer vacation at home, the speed is not like the
in Jiaotong University as---Old ox pull broken car-like slow, so based on this author to consult a large number of online data, ji its essence, write this article
Chapter hope for Beginners to provide convenience, also can be as a master reference manual. The
JSP is excellent, it is based on Java technology, the use of Javabean/servlet to make dynamic Web sites, Java's powerful orientation to
-like programming so that JSP with PHP and ASP has a unique advantage. However, learning JSP is difficult compared to PHP and ASP.
I think one of the reasons is that the configuration of the JSP server environment is tricky. For the Dynamic Web page production, in the big-time ASP has been very long
between the upper hand, not too many "master" (perhaps many people think that the use of JSP is a master bar) using JSP, more successful
JSP website such as the Century Star Network (TOMCAT), Web Education Institute website (Resin), Jiaotong University Recruitment and Employment Network (TOMCAT), the server is
Linux 9, running relatively stable and reliable. Apache and Tomcat integration under Linux I have sent an article, you need to
the people in Jincheng search. Linux and Windows integration ideas are the same, using Apache to parse the *.html/*.htm
Static Web page, when encountering *.jsp and servlet, through an Apache module to the JSP page to Tomcat (or
Resin) to deal with, under Linux compiled to make this module, to trouble, this article through a ready-made win under a
module to complete the integration.
No nonsense, the following begins to integrate:

Required Software
(1) J2sdk-1_4_2-windows-i586.exe
JDK version relationship is not very large, does not affect the integration of Apache and Tomcat, configure the environment variables to pay attention to some of the line.
(2) Apache_2.0.49-win32-x86-no_ssl.exe
The Apache version does not have much impact on consolidation, but it is best to take advantage of this version.
(3) Jakarta-tomcat-4.1.30.exe
The version is best to use this version, the others I have not tried, it is possible to lead to integration is not successful.
(3) Php-4.3.3-win32.zip
is a compressed package, download the direct decompression on the line.
(4) Mod_jk.dll
This module is placed in the module in Apache and used to communicate between Tomcat and Apache.
(5) Mysql-max-3.23.46a-win.zip
Database MySQL, whose version has little impact on consolidation.
(6) JDBC Driver
MySQL driver, and database connection with
The above software I will not put down the address to paste out, go online search Baidu, Peking University Skynet, as long as the intentions to find, should be the problem
No, if you really can't find it, send me a letter.

I. Installation J2SDK
Under Windows, run the downloaded J2sdk-1_4_1_01-windows-i586.exe file directly, and install it according to the installation wizard
To a directory, such as installing to D:\SERVER\J2SDK
1. Configure Environment variables:
Add Classpath variable
Variable value is
./;%classpath%;D: \server\j2sdk1.4.0\lib\dt.jar;d:\server\j2sdk1.4.0\lib\tools.jar;
This configuration ensures that the Java runtime can find the class classes.
2. Add java_home variable, variable value is d:\server\j2sdk1.4.0
3. In the original path variable, add D:\server\j2sdk1.4.0\bin so that the Java name order is run wherever it is running.

CMD into DOS, run Java and javac see if there is any response, if the command to help, then Java installed successfully
You can also run a Java applet to see.

public class test{
public static void Main (String args[]) {
System.out.PRintln ("See this note Java installation succeeded!");
Put the program in the Test.java file, it must be Test.java, and then use the command to compile
Javac Test.java
If there is no error, then the compilation succeeds, if wrong, on the basis of writing the program correctly, just explained that the Java environment variable is not
has been configured well, just reconfigured. If the compilation is successful, run:
Java test
Note that this is not a Java test.java! If it's correct, it just prints out:

See this instructions for Java installation success!

GXGX,JDK installation is successful! You can proceed to the next step.

Two. Apache Installation
1. Run Apache_2.0.49-win32-x86-no_ssl.exe, all the way to "OK" and "accept" on the line, path selection
D:\server\apache Group\apache2.
At this point Apache has been installed successfully, and has been run, in IE input http://localhost/can see
Apache's homepage. Installation is successful!
2. Modify Httpd.conf
The Apache configuration file is httpd.conf, located under the Conf folder under the Apache root directory
(1). Modify the Default Web site root directory:
Create a folder www under D:\server as the root directory of the Web site
DocumentRoot "D:/server/apache Group/apache2/htdocs"
Change to DocumentRoot "d:/server/www
(2). modifying character settings
Apache Parsing Chinese web page will produce garbled,
Modify Adddefaultcharset iso-8859-1 to Adddefaultcharset GB2312
(3). Modify the default home page
When the directory is accessed, Apache automatically imports the home page, whichever priority is in order
Change DirectoryIndex index.html Index.html.var to
DirectoryIndex index.html index.jsp index.php default.jsp default.php Index.html.var
(4). Set error page
This will be more secure for your site, if not set, others in your URL after entering a random path, will show 404 error
Your server version number and server configuration at a glance, in order to avoid this situation, you can set the error page.
When a 404 error occurs, which means that the page is not found, the visitor is imported to an error page
Found it:
# Customizable error responses come in three flavors:
# 1) Plain text 2) local redirects 3) external redirects
# Some Examples:
#ErrorDocument "The server made a boo boo."
#ErrorDocument 404/missing.html
#ErrorDocument 404 "/cgi-bin/missing_handler.pl"
#ErrorDocument 402 http://www.example.com/subscription_info.html
This part of the httpd.conf, #ErrorDocument 404/missing.html
A row is modified to ErrorDocument 404/error/nofile.htm, where nofile.htm is the next error file for D:\server\www\error\ and requires
You have to build it yourself. When a 404 error occurs, go to the nofile.htm page and you can be prompted that the page is not found. So it's impossible to see
Your Server Software information. You can also set other error-oriented pages, specific HTTP response error number please refer to the relevant information.
Restart Apache, if no accident, at this time has been installed successfully, the static page into the D:\server\www\error\ directory, see if you can successfully parse.
Just type in one: http://localhost/sdagasgdasasg.htm, see if it's the 404 error you set, i.e. the nofile.htm error page.
It's a success!
About the meaning of other parameters in Apache, I will not say, you can go online check, in fact, the best way is to look at the httpd.conf in the annotation department
Points, have made it very clear.
Well, to this Apache installation success, you can take a break, listen to the first music, start the next installation:)

Three. PHP installation
Unzip the php-4.3.3-win32.zip to the d:\server\php directory. Under Configure PHP and Apache, so that it can parse the PHP program.
Rename "Php.ini-dist" in the D:\server\php\ directory to "php.ini" and copy it to C:\windows\system32
(Win2K directory: C:\winnt\system32),  The following lines are placed in the Apache configuration file httpd.conf to
support PHP.
AddType application/x-httpd-php. PhP3
AddType application/x-httpd-php. php< br> AddType application/x-httpd-php. phtml
Action application/x-httpd-php "/php/php.exe"
to create a Web page under D:\server\www:   index.php, Content:

php test
!--? php
phpinfo ();

Edit with a text editor to save as index.php, restart Apache, enter http://localhost/index.php in IE, if PHP's
environment variable, PHP, installation success, If you cannot parse the!--? php phpinfo (),?--the section, the installation is not successful.

Four. Tomcat installation
I am using the Jakarta-tomcat-4.1.30.exe installation file, under Windows all the way "OK" on the line, relatively simple, the installation directory for
Set Environment variables below:
With the JDK environment variable, add the variable tomcat_home, the value is d:\server\tomcat; increment the variable catalina_home, the value is
D:\tomcat\server, add D:\server\tomcat\bin to the PATH variable
Start Tomcat below, run the Bin/startup.bat file on the Tomcat directory, the Tomcat run console, Tomcat succeeds
Enter http://localhost:8080/in IE, see big Cat's Bar, then Tomcat installs successfully.

Five. Install MySQL

First step: Unzip the Mysql-max-3.23.46a-win.zip, run the MySQL installation file, install MySQL to D:\server\mysql
Step Two: Add D:\server\mysql\bin to the environment variable path
Step three: Enter D:\server\mysql\bin directory, run winmysqladmin, just appear dialog box, set MySQL user password, assuming
Account number: The root password is: 123
Fourth step: Enter DOS, enter Mysql/bin, run the following command to open MySQL
Then MySQL turns on
Then run:
If turned on, the following text appears:
Welcome to the MySQL Monitor. Commonds End With; or \g.
Your MySQL Connection ID is 1 to server version:3.23.46-nt
Type ' help ', ' or ' \h ' for help. Type ' \c ' to clear the buffer.
Note: MySQL does not set the password at this time, in order to not allow others to enter your database, please set the password for MySQL, see MySQL for specific operation
Document in Chinese.
At this point, MySQL installation is successful!

Six. Install the MySQL driver class jdbc
Unlock the JDBC driver package and copy the Org folder inside to the location where the JSP can find it. Can be the root directory of Tomcat Common/classes
folder, or it can be a JSP site class web-inf/class/. When the driver is loaded so that the related class can be found. or the JDBC Package
Add the path to the CLASSPATH variable.

Seven. The integrated configuration of Tomcat and Apache
Tomcat is just a container for parsing *.jsp files, it is not a server, its ability to parse static htm/html files is far inferior to Apache,
After the integration on the same port to enable Apache to parse static Web pages, and encountered *.jsp Web page, by Tomcat to parse.
The first step: Copy the Mod_jk.dll to the Apache Root module folder.
Step Two: Configure Apache

Open the Apache root directory under conf\httpd.conf

Add the following statement:


#connecting to Tomcat using AJP13
LoadModule Jk_module Modules/mod_jk.dll
Jkworkersfile "D:/server/tomcat/conf/workers.properties"
jkmount/servlet/* ajp13
Jkmount/*.jsp ajp13


Note: The basic meaning of the above statement is:
LoadModule line: Load the mod_jk.dll dynamic link library module to communicate with Tomcat
Jkworkersfile: Indicates workers.properties location of Tomcat-related files at work
Jkmount: Two lines indicate that when *.jsp and Servlets are encountered, they are referred to the AJP13 protocol, which is then forwarded to Tomcat processing.
Step three: Build the Workers.properties file and create the Workers.properties file under the Tomcat root directory conf:



worker.inprocess.class_path=$ (workers.tomcat_home) $ (PS) classes
worker.inprocess.class_path=$ (workers.tomcat_home) $ (PS) lib$ (PS) Jaxp.jar

worker.inprocess.class_path=$ (workers.tomcat_home) $ (PS) lib$ (PS) Parser.jar

worker.inprocess.class_path=$ (workers.tomcat_home) $ (PS) common$ (PS) lib$ (PS) Jasper.jar

worker.inprocess.class_path=$ (workers.tomcat_home) $ (PS) common$ (PS) lib$ (PS) Servlet.jar

worker.inprocess.class_path=$ (workers.tomcat_home) $ (PS) common$ (PS) lib$ (PS) Webserver.jar

worker.inprocess.class_path=$ (workers.java_home) $ (PS) lib$ (PS) Tools.jar


worker.inprocess.cmd_line=$ (workers.tomcat_home)/conf/jni_server.xml


worker.inprocess.cmd_line=$ (Workers.tomcat_home)

worker.inprocess.jvm_lib=$ (workers.java_home) $ (PS) jre$ (PS) bin$ (PS) classic$ (PS) jvm.dll

worker.inprocess.stdout=$ (workers.tomcat_home) $ (PS) inprocess.stdout

worker.inprocess.stderr=$ (workers.tomcat_home) $ (PS) Inprocess.stderr

worker.inprocess.sysprops=tomcat.home=$ (Workers.tomcat_home)

Note that the first to second line of the above file is populated with the relevant directory for Tomcat and JDK.

Fourth step: Configure the Server.xml file under Tomca/conf, this is the main configuration file of Tomcat, the important configuration is as follows:
1. Virtual Directory settings:
Find the following:
Unpackwars= "true" autodeploy= "true" >
Modified to:
Unpackwars= "true" autodeploy= "true" >
Make the Tomcat home directory d:\server\www.
Find the following:
Reloadable= "true" crosscontext= "true" >
Revision changed to
Reloadable= "true" crosscontext= "true" >
What I understand is that it should be a virtual host for the JSP root directory.
2. Set the Tomcat listener port to find the following:
port= "8080" minprocessors= "5" maxprocessors= "75"
Enablelookups= "true" redirectport= "8443"
acceptcount= "debug=" 0 "connectiontimeout=" 0 "
Useurivalidationhack= "false" disableuploadtimeout= "true"/>
The default port is 8080, but as we all know, it is best to modify it, assuming that the change is: 8123, as follows:
Port= "8123" minprocessors= "5" maxprocessors= "75"
Enablelookups= "true" redirectport= "8443"
acceptcount= "debug=" 0 "connectiontimeout=" 0 "
Useurivalidationhack= "false" disableuploadtimeout= "true"/>
3. Find the following 8009 ports where this is important to communicate with Apache via 8009,TOMCAT if the following sections
Be Comment out, be sure to put Remove.
Port= "8009" minprocessors= "5" maxprocessors= "75"
Enablelookups= "true" redirectport= "8443"
Acceptcount= "Ten" debug= "0" connectiontimeout= "0"
Useurivalidationhack= "false"
Protocolhandlerclassname= "Org.apache.jk.server.JkCoyoteHandler"/>
Fifth step: Configure the Tomcat Conf/web.xml file:
Similar to Apache under the 404 error page configuration, in the lastLine before adding the following:
First one The 404 error-oriented page of the JSP page was not found, making it a 404 error,
The page is directed to/error/nofile.htm, and you can add its many error code-oriented pages in a similar way.
A second is when the JSP Web page appears java.lang.NullPointerException
Directed to the/error/error.jsp error page. Then you need to include the following in the first JSP Web page:
<%@ page errorpage= "/error/error.jsp"%>
The typical ERROR.JSP error page program is written as follows:
<%@ page contenttype= "text/html;charset=gb2312"%>
<%@ page iserrorpage= "true"%>
  <title>Error page</title>

An error occurred:

Error message: <%= exception.getmessage ()%>

Stack Trace is:

  Java.io.CharArrayWriter cw = new Java.io.CharArrayWriter ();
  Java.io.PrintWriter pw = new Java.io.PrintWriter (cw,true);
  Exception.printstacktrace (PW);
  Out.println (Cw.tostring ());

When the nullpointerexception exception occurs, Tomcat imports the Web page to error.jsp and prints an error message.
The fifth step is security considerations, under normal circumstances, if the page can not find a 404 error or JSP program error, the client
Will list information similar to the following (in Tomcat, for example, resin):
HTTP Status 404-/sdags.jsp


Type Status Report


Description The requested resource (/SDAGS.JSP) is not available.


Apache tomcat/5.0.19
So the server version will be seen by others, if you complete the fifth step of the configuration, there will be no such situation.
Sixth step: Configure the httpd.conf file
This method sets the root directory of Tomcat and Apache to the same directory, but must limit the client's access to some of the files in the directory, such as depositing class
Web-inf, add the following code under HTTPD.CONF:
#deny the access to Web-inf
Order Allow,deny
Deny from all
This way, when you try to remember the http://localhost/web-inf/, Apache will reject it.
As of this, the integration of Tomcat and Apache is complete. Restart Tomcat and Apache,
Put the JSP page under D:\server\www\, for example:

JSP Test

<%out.println ("Hello world!");  %>

Save As index.jsp, enter http://localhost:8123/index.jsp
in IE if
Hello world!
appears  Just stating that Tomcat is working properly, enter http://localhost/index.jsp in IE, if
Hello world!
also appears Congratulations! Integration success, you in JSP long hard road to take a big step ~!

The above integration article I was in a rush of time to complete, there may be some mistakes. or poorly considered place, but overall should not be
too big problem, I was repeatedly using this method of integration success. If you have any questions, you can contact me directly.

  • Related Article

    E-Commerce Solutions

    Leverage the same tools powering the Alibaba Ecosystem

    Learn more >

    Apsara Conference 2019

    The Rise of Data Intelligence, September 25th - 27th, Hangzhou, China

    Learn more >

    Alibaba Cloud Free Trial

    Learn and experience the power of Alibaba Cloud with a free trial worth $300-1200 USD

    Learn more >

    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.