1. Author: moonsbird
Title: Summary of server integration configuration experience for Apache+Tomcat+MySQL+jsp+php under Windows
Time: 2004.8.19
Originally published at Southwest Jiaotong University Jincheng Station
2. This article is a summary of the author’s experience in learning jsp/configuration server environment over the past few years. It can be reproduced, but please indicate the source.
It has been a long time since I started learning jsp. There are many examples of jsp integration on the Internet, but there are many problems.
For the integration of Apache+Tomcat+MySQL+jsp+php, there are slight differences for different versions of Tomcat and apache.
Even if your E-text is good, if you read the manuals of Tomcat and Apache, you may not be able to fully integrate them successfully. I am at home during the summer vacation, and the Internet speed is not as slow as that of Jiaotong University---it is as slow as an old scalper's car, so based on this, the author consulted a large amount of online information and absorbed its essence. I wrote this article hoping to provide convenience for beginners and also serve as a A master's reference manual.
jsp is excellent. It is based on Java technology and uses JavaBean/Servlet to create dynamic websites. Java's powerful object-oriented programming gives Jsp unique advantages over php and asp. But 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 a little trickier. For the production of dynamic web pages, ASP has had the upper hand in Jiaotong University for a long time. There are not many "experts" (perhaps many people think that those who use jsp are experts) use jsp, and Jiaotong University is more successful.
jsp websites such as Century Star Network (Tomcat), Online Education Institute website (Resin), Jiaotong University Admissions and Employment Network (Tomcat), the server is
Linux 9 runs relatively stable and reliable. I once published an article on the integration of Apache and Tomcat under Linux. If you need it, please search it in Jincheng. The integration ideas under Linux and Windows are the same, using apache to parse *.html/*.htm
For static web pages, when encountering *.jsp and servlet, the jsp page is thrown to Tomcat (or
resin), it is a bit more troublesome to make this module by compiling it under Linux. This article uses a ready-made module under win to complete the integration.
Without further ado, let’s start integrating:
Required software
(1) j2sdk-1_4_2-windows-i586.exe
The version of jdk is not very relevant and does not affect the integration of Apache and Tomcat. Just pay attention when configuring environment variables.
(2) apache_2.0.49-win32-x86-no_ssl.exe
The apache version does not have much impact on integration, but it is best to take advantage of this version.
(3)jakarta-tomcat-4.1.30.exe
It is best to use this version. I have not tried other versions, which may cause the integration to fail.
(3) php-4.3.3-Win32.zip
It is a compressed package, just download it and unzip it directly.
(4) mod_jk.dll
This module is placed in the module in apache, and is used to communicate between Tomcat and Apache.
(5) mysql-max-3.23.46a-win.zip
Database mysql, its version has little impact on integration.
(6) jdbc driver
mysql driver, used when connecting to the database
I won’t post the address of the above software. Search Baidu and Beida Tianwang online. As long as you search carefully, it shouldn’t be a big problem. If you really can’t find it, just send me an email to ask for it.
1. Install j2sdk
Under Windows, directly run the downloaded j2sdk-1_4_1_01-windows-i586.exe file and install it to a directory according to the installation wizard, for example, install to d:serverj2sdk
1. Configure environment variables:
Add CLASSPATH variable variable value as
./;%CLASSPATH%;D:serverj2sdk1.4.0libdt.jar;d:serverj2sdk1.4.0libtools.jar;
d:serverj2sdk1.4.0bin
This configuration ensures that the class class can be found when java is running.
2. Add the JAVA_HOME variable, the variable value is d:serverj2sdk1.4.0
3. In the original path variable, add d:serverj2sdk1.4.0bin, so that the java command can be run no matter where it is.
Restart
cmd to enter dos, run java and javac to see if there is any response. If the help of the command appears, then java is installed successfully. You can also run a java applet to see.
public class test{
public static void main(String args[]){
System.out.println("Seeing this means that Java installation is successful!");
}
}
Store the above program in the test.java file, it must be test.java, and then use the command to compile
javac test.java
If there are no errors, it means the compilation was successful. If there are errors, it means that the Java environment variables have not been configured properly and have just been reconfigured based on the correct program writing. If compilation is successful, run:
java test
Note, not java test.java! If it is correct, it will just print out:
Seeing this means that java is installed successfully!
gxgx, jdk are installed successfully! You can proceed to the next step.
2. apache installation
1. Run apache_2.0.49-win32-x86-no_ssl.exe, just click "OK" and "Accept" along the way, select the path
d:serverapache groupapache2.
At this point, apache has been installed successfully and is running. You can see it by entering http://localhost/ in IE.
apache's home page. Installation successful!
2. Modify httpd.conf
The configuration file of apache is httpd.conf, which is located in the conf folder under the apache root directory.
(1). Modify the default website root directory:
Create the folder www under d:server as the root directory of the website
DocumentRoot "D:/server/Apache Group/Apache2/htdocs"
Change to DocumentRoot "D:/server/www
(2). Modify character settings
Apache will generate garbled characters when parsing Chinese web pages.
Modify AddDefaultCharset ISO-8859-1 to AddDefaultCharset GB2312
(3). Modify the default homepage
When accessing a directory, apache will automatically import the home page, and the priority will be 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 safer for your website. If it is not set, and someone else enters a random path after your URL, a 404 error will be displayed.
error, and your server version number will be displayed. The server configuration is clear at a glance. To avoid this situation, you can set up an error page.
When a 404 error occurs, that is, the web page cannot be found, direct the visitor to an error page
turn up:
#
# Customizable error responses come in three flavors:
# 1) plain text 2) local redirects 3) external redirects
#
# Some examples:
#ErrorDocument 500 "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 httpd.conf, #ErrorDocument 404 /missing.html
One line is modified to ErrorDocument 404 /error/noFile.htm, where noFile.htm is the next error file in d:serverwwwerror.
You have to build it yourself. When a 404 error occurs, enter the noFile.htm page and it will prompt that the web page is not found. It will then be impossible to see your server software information. You can also set up other error-oriented pages. Please refer to relevant information for specific http response error numbers.
Restart apache. If nothing unexpected happens, the installation has been successful. Place the static page in the d:serverwwwerror directory to see if it can be parsed successfully.
Enter any one: http://localhost/sdagasgdasasg.htm and see if it leads to the 404 error you set, that is, the noFile.htm error page.
Success!
I won’t go into details about the meaning of other parameters in apache. You can check it online. In fact, the best way is to read the comments in httpd.conf, which is already very clear.
Okay, now apache is successfully installed. You can take a break, listen to some music, and start the next step of installation:)
3.php installation
Unzip php-4.3.3-Win32.zip and go to the d:serverphp directory. Configure PHP and Apache so that they can parse php programs.
Rename "php.ini-dist" in the d:serverphp directory to "php.ini" and copy it to C:windowssystem32
(Win2K directory: C:winntsystem32), enter the following lines in the apache configuration file httpd.conf to make it support php.
ScriptAlias /php/ "d:/server/php/"
AddType application/x-httpd-php .php3
AddType application/x-httpd-php .php
AddType application/x-httpd-php .phtml
Action application/x-httpd-php "/php/php.exe"
Create a web page: index.php under d:serverwww, with the following content:
<html>
<head><title>php test</title></head>
<?php
phpinfo();
?>
</html>
Edit it with a text editor and save it as index.php, restart apache, enter http://localhost/index.php in IE, if the environment variable of php appears, it means php is installed successfully. If it cannot parse <?php phpinfo(); ?>, it means the installation was not successful.
4. Tomcat installation
I used the jakarta-tomcat-4.1.30.exe installation file. Just click "OK" under Windows. It is relatively simple. The installation directory is
d:servertomcat
Set the environment variables below:
The same as the environment variables of jdk, add the variable TOMCAT_HOME, the value is d:servertomcat; add the variable CATALINA_HOME, the value is
d:tomcatserver, add d:servertomcatbin to the path variable
Next, start tomcat and run the bin/startup.bat file in the tomcat directory. The tomcat running console appears and tomcat starts successfully.
Enter http://localhost:8080/ in IE. If you see Big Cat, the tomcat installation is successful.
5. Install MySQL.
Step 1: Unzip mysql-max-3.23.46a-win.zip and run the mysql installation file. , install mysql to d:servermysql
Step 2: Add d:servermysqlbin to the environment variable path
Step 3: Enter the d:servermysqlbin directory and run winmysqladmin. A dialog box will appear just now. Set the mysql user password. Assume that the account is: root and the password is: 123
Step 4: Enter dos, enter mysql/bin, and run the following command to open mysql
mysqld-nt --standalone
Then mysql is opened
Then run:
mysql
If turned on, the following text appears:
Welcome to the MySQL monitor. Commons 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.
mysql>
Note: There is no password set for mysql at this time. In order to prevent others from entering your database, please set a password for mysql. For specific operations, please refer to mysql
Chinese documentation.
At this point, mysql is installed successfully!
6. Install the MySQL driver class jdbc
Unzip the jdbc driver package and copy the org folder inside to a location where jsp can be found. It can be the root directory common/classes of tomcat
folder, or it can be under the jsp website class WEB-INF/class/. So that the relevant classes can be found when the driver is loaded. Or add the path of the jdbc package to the classpath variable.
7. Integrated configuration of Tomcat and Apache
Tomcat is just a container used to parse *.jsp files. It is not a server. Its ability to parse static htm/html files is far inferior to apache.
After integration, apache is used to parse static web pages on the same port, and when a *.jsp web page is encountered, it is handed over to tomcat for parsing.
Step 1: Copy mod_jk.dll to the module folder in the apache root directory.
Step 2: Configure APACHE
to open confhttpd.conf in the apache root directory
and 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:
One line of loadModule: Load the mod_jk.dll dynamic link library module to communicate with tomcat
jkWorkersFile: Indicates the location of tomcat related files workers.properties when working
jkMount: Two lines indicate that when *.jsp and servlet are encountered, they are handed over to the ajp13 protocol and then forwarded to tomcat for processing.
Step 3: Create the workers.properties file. Create the workers.properties file in the tomcat root directory conf. The content is:
workers.tomcat_home=d:servertomcat
workers.java_home=d:serverj2sdk1.4.0
ps=
# worker.list=ajp13
worker.list=ajp12,ajp13
worker.ajp12.port=8007
worker.ajp12.host=localhost
worker.ajp12.type=ajp12
worker.ajp12.lbfactor=1
worker.ajp13.port=8009
worker.ajp13.host=localhost
worker.ajp13.type=ajp13
worker.ajp13.lbfactor=1
worker.loadbalancer.type=lb
worker.loadbalancer.balanced_workers=ajp12, ajp13
worker.inprocess.type=jni
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=-config
worker.inprocess.cmd_line=$(workers.tomcat_home)/conf/jni_server.xml
worker.inprocess.cmd_line=-home
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 in the first and second lines of the above file, fill in the related directories of tomcat and jdk.
Step 4: 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:
<Host name="localhost" debug="0" appBase="/webapps"
unpackWARs="true" autoDeploy="true">
Modify to:
<Host name="localhost" debug="0" appBase="d:/server/www"
unpackWARs="true" autoDeploy="true">
Make the tomcat home directory d:serverwww.
Find the following:
<Context path="examples" docBase="/examples" debug="0"
reloadable="true" crossContext="true">
Modify to
<Context path="" docBase="/" debug="0"
reloadable="true" crossContext="true">
My understanding of this is that the jsp in the root directory of tomcat should be used as a virtual host.
2. Set the tomcat listening port and find the following content:
<Connector className="org.apache.coyote.tomcat4.CoyoteConnector"
port="8080" minProcessors="5" maxProcessors="75"
enableLookups="true" redirectPort="8443"
acceptCount="100" debug="0" connectionTimeout="0"
useURIValidationHack="false" disableUploadTimeout="true" />
The default port is 8080, but everyone knows this. It is best to modify it. Suppose it is modified to: 8123, then it is as follows:
<Connector className="org.apache.coyote.tomcat4.CoyoteConnector"
port="8123" minProcessors="5" maxProcessors="75"
enableLookups="true" redirectPort="8443"
acceptCount="100" debug="0" connectionTimeout="0"
useURIValidationHack="false" disableUploadTimeout="true" />
3. Find the following 8009 port. This is very important. Tomcat and apache communicate with each other through 8009. If the following part is commented out by <!---->, be sure to remove <!---->.
<!-- Define a Coyote/JK2 AJP 1.3 Connector on port 8009 -->
<Connector className="org.apache.coyote.tomcat4.CoyoteConnector"
port="8009" minProcessors="5" maxProcessors="75"
enableLookups="true" redirectPort="8443"
acceptCount="10" debug="0" connectionTimeout="0"
useURIValidationHack="false"
protocolHandlerClassName="org.apache.jk.server.JkCoyoteHandler"/>
Step 5: Configure tomcat’s conf/web.xml file:
Similar to the configuration of the 404 error page under Apache, add the following content before the last </web-app> line:
<error-page>
<error-code>404</error-code>
<location>/error/noFile.htm</location>
</error-page>
<error-page>
<exception-type>java.lang.NullPointerException</exception-type>
<location>/error/error.jsp</location>
</error-page>
The first <error-page></error-page> is the error-oriented page of the 404 not found jsp page, so that when a 404 error occurs,
The web page is directed to /error/noFile.htm. You can also use a similar method to add other error codes to the page.
The one between the second <error-page></error-page> is directed to the /error/error.jsp error page when a java.lang.NullPointerException occurs on the jsp web page. Then you need to add the following content to the jsp page:
<%@ page errorPage="/error/error.jsp" %>
A typical error.jsp error page program is written as follows:
<%@ page contentType="text/html;charset=GB2312"%>
<%@ page isErrorPage="true"%>
<html>
<head><title>Error page</title></head>
<body>
Something went wrong:</p> Error message: <%= exception.getMessage() %><br>
Stack Trace is: <pre><font color="red"><%
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());
%></font></pre>
</body>
</html>
When a NullPointerException occurs, tomcat will import the web page to error.jsp and print out the error message.
The fifth step is mainly for security considerations. Under normal circumstances, if the web page cannot be found, a 404 error or jsp program error will occur. On the client
Information similar to the following will be listed (taking tomcat as an example, resin is similar):
HTTP Status 404 - /sdags.jsp
------------------------------------------------ -------------------------------------
type Status report
message /sdags.jsp
description The requested resource (/sdags.jsp) is not available.
-------------------------------------------------- -------------------------------
Apache Tomcat/5.0.19
In this way, the server version will be seen by others. If the configuration in step 5 is completed, this situation will not occur.
Step 6: Configure the httpd.conf file
This method sets the root directories of tomcat and apache to the same directory, but must restrict the customer's access to some files in the directory, such as saving classes
web-inf, add the following code under httpd.conf:
#deny the access to WEB-INF
<Directory ~ "/WEB-INF/">
Order allow,deny
Deny from all
</Directory>
This way, when trying to remember http://localhost/web-inf/ , apache will refuse.
At this point, the integration of tomcat and apache is completed. Restart tomcat and apache.
Put the jsp web page under d:serverwww, for example:
<html>
<h1>JSP test<hr>
<%out.println("Hello World!");%>
</html>
Save as index.jsp, enter http://localhost:8123/index.jsp in IE
if it appears
Hello World!
Just explained that tomcat is running normally, enter http://localhost/index.jsp in IE, if it also appears
Hello World!
Congratulations! The integration is successful. You have taken a big step on the long and arduous road of jsp~!
I completed the above integration article in a hurry, and there may be some errors. or some ill-considered aspects, but overall it should be fine
It's a big problem. I successfully integrated it using this method repeatedly. If you have any questions, you can contact me directly.
moonsbird: mail:[email protected]
http://blog.csdn.net/jangill/archive/2007/03/18/1532857.aspx