Experience summary of server consolidation configuration for apache|js|mysql|window| server under Windows apache+tomcat+mysql+jsp+php
1. Author: moonsbird
Topic: Experience Summary of server consolidation configuration under Windows apache+tomcat+mysql+jsp+php
Time: 2004.8.19
Originally posted at Jincheng station, Southwest Jiaotong University
2. This paper 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 learning JSP for a long time, there are many examples of JSP integration on the web, but there are many problems.
For apache+tomcat+mysql+jsp+php consolidation, there is a slight difference between the different Tomcat and Apache versions.
Even if you are good at E, it is not always possible to see the Manual of Tomcat and Apache. Summer vacation at home, the speed is not like
In the same way---ox pull a car like slow, so based on the author of a large number of online data, to extract the essence, write this article
Chapter hope to provide convenience for beginners, can also be used as a reference manual of experts.
JSP is excellent, it is based on Java technology, using Javabean/servlet to make dynamic Web sites, Java powerful to
Like programming to make JSP relative to PHP and ASP has a unique advantage. But learning JSP is difficult compared to PHP and ASP.
I think one of the reasons is that the JSP server environment is a bit tricky to configure. For dynamic Web page production, at Jiaotong University ASP has been very long time
Occupy the upper hand, not too many "master" (perhaps many people think that using JSP is a master bar) using JSP, Jiaotong University more successful
JSP sites such as century Star Network (tomcat), Network Education Institute website (Resin), Jiaotong University Enrollment and Employment Network (tomcat), the server is
Linux 9, running relatively stable and reliable. Apache and Tomcat integration under Linux I've sent an article that needs
The people who want to search in Jincheng. Linux and Windows integration ideas are the same, using Apache to parse *.html/*.htm
Static Web pages, when encountering *.jsp and servlet, by using a module in Apache to toss the JSP page to Tomcat (or
Resin) to deal with, in Linux by compiling to make this module, to trouble some, this article through the ready-made win under a
module to complete the integration.
No more nonsense, start the integration below:
The required software
(1) J2sdk-1_4_2-windows-i586.exe
The JDK version relationship is not very large and does not affect the integration of Apache and Tomcat, so be aware of some of the things you can do to configure your environment variables.
(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 with this version, others I have not tried, there may be a result of the integration is unsuccessful.
(3) Php-4.3.3-win32.zip
is a compression package, download down directly decompression on the line.
(4) Mod_jk.dll
This module is placed in the module in Apache, which is 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 the database is connected with the
The above software I will not put down the address posted out, go online search Baidu, North Skynet, as long as the intention to find, should be a problem
Not much, if you really can't find it, send me a letter.
I. Installation of J2SDK
Under Windows, run the downloaded J2sdk-1_4_1_01-windows-i586.exe file directly, installed according to the Setup 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;
D:\server\j2sdk1.4.0\bin
This configuration ensures that the class class can be found in the Java runtime.
2. Add java_home variable with variable value of d:\server\j2sdk1.4.0
3. In the original path variable, add d:\server\j2sdk1.4.0\bin so that no matter where the Java name order is run.
Reboot
CMD into the DOS, run Java and javac see if there is a response, if the command to help, then the installation of Java is successful
You can also run a Java applet to see.
public class test{
public static void Main (String args[]) {
System.out.println ("See this description Java installation success!");
}
}
Put the program in the Test.java file, must be Test.java, and then use the command to compile
Javac Test.java
If there is no error, then the compilation is successful, if there is a mistake, on the basis of the program writing, just explained that the Java environment variables did not
Configuration is good, just reconfigure. If the compilation succeeds, it runs:
Java test
Note, not the Java test.java! If correct, it will just print out:
See this description 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 "OK" and "accept" on the line, the path selected
D:\server\apache Group\apache2.
At this time Apache has been installed successfully, and has been running, in IE input http://localhost/can see
The home page of Apache. Installation 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 site
DocumentRoot "D:/server/apache Group/apache2/htdocs"
Change to DocumentRoot "d:/server/www
(2). Modify character settings
Apache will produce garbled characters when parsing Chinese web pages.
Modify Adddefaultcharset iso-8859-1 to Adddefaultcharset GB2312
(3). Modify the default home page
When you access the directory, Apache automatically imports the home page, prioritized in order of precedence
Change the DirectoryIndex index.html Index.html.var to
DirectoryIndex index.html index.jsp index.php default.jsp default.php
(4). Set error page
This will be more secure for your site, if not set, others in your URL after the random input a path, will show 404 wrong
Wrong, and will display your server version number, server configuration at a glance, in order to avoid this situation, you can set the error page.
When a 404 error occurs, 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
One line is modified to ErrorDocument 404/error/nofile.htm, where nofile.htm is the d:\server\www\error\ next error file, which requires
You have to build your own. When 404 error occurs, enter the Nofile.htm page, you can prompt the Web page is not found. So it's impossible to see
Information about your server software. You can also set other error-oriented pages, specific HTTP response error number please refer to the relevant information.
Restart Apache, if not unexpected, this time has been installed successfully, the static page into the D:\server\www\error\ directory, to see if it can be successfully resolved.
Enter a random: http://localhost/sdagasgdasasg.htm, see if you set the 404 error, that is, the nofile.htm error page.
It's a success!
About the significance of other parameters in Apache, I do not say, you can go online, in fact, the best way is to see the httpd.conf in the comments section
Points, has made it very clear.
OK, to this Apache installation is successful, you can take a break, listen to the music, and start the next installation:
Three. PHP Installation
Unzip the php-4.3.3-win32.zip to the d:\server\php directory. Configure PHP and Apache to parse PHP programs.
Rename "Php.ini-dist" in the D:\server\php\ directory to "php.ini" and copy it to C:\windows\system32
(Win2K directory is: C:\winnt\system32), in the Apache configuration file httpd.conf down the following lines, so that the
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 under D:\server\www: index.php, the content is:
<?php
Phpinfo ();
?>
Edit with a text editor to save as index.php, restart Apache, enter http://localhost/index.php in IE, if there is PHP
Environment variables, description of PHP, successful installation, if you cannot resolve <?php phpinfo (),?> parts, then the installation is not successful.
Four. Tomcat installation
I am using the Jakarta-tomcat-4.1.30.exe installation file, in Windows under the "OK" on the line, relatively simple, installation directory for
D:\server\tomcat
Set the environment variables below:
The environment variable with JDK, add variable tomcat_home, value is d:\server\tomcat, add variable catalina_home, value is
D:\tomcat\server, add D:\server\tomcat\bin in the PATH variable
Start Tomcat below, run the Bin/startup.bat file on the Tomcat directory, and the Tomcat run console, tomcat successful
Start.
In IE input http://localhost:8080/, see the Cat's Bar, then Tomcat installed successfully.
Five. Install MySQL
The first step: unpack Mysql-max-3.23.46a-win.zip, run MySQL installation files, 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 will appear dialog box, set the MySQL user password, assume
Account number: The root password is: 123
Fourth step: Into the DOS, into the Mysql/bin, run the following command to open MySQL
Mysqld-nt--standalone
Then MySQL opens
And then run:
Mysql
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.
Mysql>
Note: MySQL does not set the password at this time, in order to keep others from entering your database, please set the password for MySQL, please see MySQL for specific operation
The Chinese documentation.
At this point, MySQL installation success!
Six. Install MySQL driver class jdbc
To unlock the JDBC driver package, copy the Org folder inside to the location that the JSP can find. Can be the root directory of Tomcat Common/classes
folder, can also be the JSP site class classes web-inf/class/under. When the driver is loaded, the related class can be found. or the JDBC Package
Path is added to the CLASSPATH variable.
Seven. The integrated configuration of Tomcat and Apache
Tomcat is just a container for parsing *.jsp files, not servers, and its ability to parse static htm/html files is far less than Apache,
After integration on the same port so that Apache to resolve static Web pages, and encountered *.jsp Web pages, by Tomcat to resolve.
The first step: Copy the Mod_jk.dll to the Apache Root module folder.
Step Two: Configure Apache
Open the Apache root directory 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 One line: Load the mod_jk.dll dynamic link library module so that it communicates with Tomcat
Jkworkersfile: Specifies the location of Tomcat-related files workers.properties at work
Jkmount: Two lines indicate that when the *.jsp and servlet are encountered, they are referred to the AJP13 protocol, which is then forwarded to Tomcat processing.
The third step: establish the Workers.properties file, under the Tomcat root directory conf set up the Workers.properties file, the content is:
Workers.tomcat_home=d:\server\tomcat
workers.java_home=d:\server\j2sdk1.4.0
Ps=\
# WORKER.LIST=AJP13
Worker.list=ajp12,ajp13
Note that the above file line first to second fills in the related directories for Tomcat and JDK.
Step Fourth: Configure the Server.xml file under Tomca/conf, which is the main configuration file for Tomcat, with the following important configuration:
1. Virtual Directory settings:
Find the following:
Unpackwars= "true" autodeploy= "true" >
Modified to:
Unpackwars= "true" autodeploy= "true" >
Make the Tomcat master directory a d:\server\www.
Find the following:
<context path= "Examples" docbase= "/examples" debug= "0"
Reloadable= "true" crosscontext= "true" >
Amended to
<context path= "" docbase= "/" debug= "0"
Reloadable= "true" crosscontext= "true" >
My understanding of this is to make the JSP under the Tomcat root directory a virtual host.
2. Set up the Tomcat listening port and find the following:
<connector classname= "Org.apache.coyote.tomcat4.CoyoteConnector"
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 you know, it's best to modify it, assuming that the modification is: 8123, as follows:
<connector classname= "Org.apache.coyote.tomcat4.CoyoteConnector"
Port= "8123" minprocessors= "5" maxprocessors= "75"
Enablelookups= "true" redirectport= "8443"
Acceptcount= "debug=" "0" connectiontimeout= "0"
Useurivalidationhack= "false" disableuploadtimeout= "true"/>
3. Locate the following 8009 ports, this is important, through the 8009,tomcat and Apache communication, if the following section
Be sure to remove <!----> by <!----> comments.
<!--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= "Ten" debug= "0" connectiontimeout= "0"
Useurivalidationhack= "false"
Protocolhandlerclassname= "Org.apache.jk.server.JkCoyoteHandler"/>
Step Fifth: Configure Tomcat's Conf/web.xml file:
Similar to the configuration of the Apache 404 error page, add the following 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> between is 404 did not find the JSP page error-oriented page, so that a 404 error occurred,
Web pages are directed to/error/nofile.htm, or you can add many of their error code-oriented pages in a similar way.
The second <error-page></error-page> between is when the JSP page appears java.lang.NullPointerException guide often
Guide to/error/error.jsp error page. Then you need to include the following in the first JSP page:
<%@ page errorpage= "/error/error.jsp"%>
The typical ERROR.JSP error page program is written as follows:
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>
When a NullPointerException exception occurs, Tomcat imports the Web page into the error.jsp and prints an error message.
The fifth step is mainly security considerations, under normal circumstances, if the page can not find the 404 error or JSP program error, in the client
Will enumerate information similar to the following (in tomcat example, resin similar):
HTTP Status 404-/sdags.jsp
This will make the server version visible to others, and this will not happen if you complete the fifth step configuration.
Step Sixth: Configure the httpd.conf file
This method sets the root directory of Tomcat and Apache to the same directory, but it must restrict client access to some files in the directory, such as storing class
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 to ask http://localhost/web-inf/, Apache will reject it.
To this end, the integration of Tomcat and Apache is complete. Restart Tomcat and Apache,
Put the JSP page under D:\server\www\, for example:
<%out.println ("Hello world!"); %>
Save As index.jsp, enter http://localhost:8123/index.jsp in IE
If there is a
Hello world!
I just explained that Tomcat is running normally, enter http://localhost/index.jsp in IE, if also appear
Hello world!
Congratulations, you! Integration successful, you are in the JSP long hard road on a big step ~!
The above integration article I was in the rush of time to complete, there may be some mistakes. or thoughtless, but the general should not
Too big a problem, I was repeatedly using this method to integrate successfully. If you have any questions, you can contact me directly.
Moonsbird:mail:pengw97@163.com
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.