Windows Server + Tomcat + MySQL + jsp + php server integrated configuration Experience Summary

Source: Internet
Author: User
Tags php server apache tomcat
1. Author: moonsbird
Title: Windows server integrated configuration experience of Apache + Tomcat + MySQL + jsp + php
Time: 2004.8.19
Originally published on jincheng station of Southwest Jiaotong University
2. This Article is a summary of the author's experience in learning jsp/configuring server environments over the past few years. It can be reproduced, but please indicate the source.

I have been learning jsp for a long time. There are many examples of jsp integration on the Internet, but there are many problems.
The integration of Apache + Tomcat + MySQL + jsp + php is slightly different for different Tomcat and apache versions.
Even if you have a good E-paper, you may not be able to fully integrate the Tomcat and Apache manuals. At home during summer vacation, the network speed is not as high
As in Jiaotong University-the old scalper is slow in pulling the car sample. Therefore, based on this author's query of a large amount of online information, he likes his essence and writes this article
This chapter also serves as a reference manual for beginners.
Jsp is excellent. Based on Java technology, it uses JavaBean/Servlet to create dynamic websites.
Image programming gives Jsp a unique advantage over php and asp. However, learning jsp is more difficult than php and asp.
I think one of the reasons is that the configuration of the jsp server environment is tricky. For the production of dynamic web pages, it was a long time before asp at Jiaotong University.
There are not many "Masters" (maybe many people think that jsp is a master ).
Jsp websites such as century star network (Tomcat), Network Education College website (Resin), Jiaotong University Enrollment and Employment Network (Tomcat), the server is
Linux 9 is relatively stable and reliable. I have published an article on the integration of Apache and Tomcat in Linux.
If you want to search in Jincheng. The integration idea in linux and windows is the same. apache is used to parse *. html/*. htm.
For static Web pages, when *. jsp and servlet are encountered, the jsp page is thrown to Tomcat through a module in apache (or
Resin) to handle, compile in linux to make this module, it is a bit of trouble, this article through a ready-made windows
Module to complete integration.
If you don't talk about it, integrate the following:

Required Software
(1) j2sdk-1_4_2-windows-i586.exe
The jdk version relationship is not very big, 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 use it.
(3) jakarta-tomcat-4.1.30.exe
It is best to use this version. I have not tried any other version, and it may cause the integration to fail.
(3) php-4.3.3-Win32.zip
Is a compressed package, download it and decompress it directly.
(4) mod_jk.dll
This module is placed in the module of apache, which enables communication between Tomcat and Apache.
(5) mysql-max-3.23.46a-win.zip
The mysql database version has little impact on integration.
(6) jdbc driver
Mysql driver, used to connect to the database
I will not post the down address for the above software. I will go to the Internet to search for baidu and Peking University Skynet. If I try to find the address, I should ask questions.
Not big. If you cannot find it, send it to me.

1. Install j2sdk
Run the j2sdk-00004_000001-windows-i586.exe file in windows.
To a directory, such as install to d: \ server \ j2sdk
1. Configure environment variables:
Add CLASSPATH variable
Variable value:
./; % 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 can be found during java runtime.
2. Add the JAVA_HOME variable. The variable value is d: \ server \ j2sdk1.4.0.
3. In the original path variable, add d: \ server \ j2sdk1.4.0 \ bin, so that you can run the java name command wherever you are.
Restart

Cmd enters dos and runs java and javac to check whether there is any response. If the command is helpful, the java installation is successful.
You can also run a java applet.

Public class test {
Public static void main (String args []) {
System. out. println ("It indicates that java is successfully installed! ");
}
}
Store 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, it indicates that the compilation is successful. If there is a mistake, the java environment variable does not
You have configured it. You just need to reconfigure it. If the compilation is successful, run:
Java test
Note: It is not java test. java! If it is correct, the following output is printed:

The java installation is successful!

Gxgx: jdk has been installed successfully! You can proceed to the next step.

Ii. install apache
1.run apache_2.0.49-win32-x86-no_ssl.exe. Just click "OK" and "accept". Select the path.
D: \ server \ apache group \ apache2.
At this time, apache has been installed successfully and is running. Enter http: // localhost/in IE to see
Apache homepage. Installed successfully!
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 www folder 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 generates garbled characters when parsing Chinese webpages,
Modify adddefadefacharset ISO-8859-1 to adddefacharcharset GB2312
(3). Modify the default homepage
Apache automatically imports the home page when accessing the directory. The priority is based on the order of priority.
Change DirectoryIndex index.html. var
DirectoryIndex index.html index. jsp index. php default. jsp default. php index.html. var
(4). Set error page
In this way, your website will be safer. If you do not set it, if you enter a path after your website, the Error 404 will be displayed.
The version number of your server is displayed, and the server configuration is clear at a glance. To avoid this situation, you can set an error page.
When a 404 error occurs, that is, the webpage cannot be found, the visitor is imported to an error page.
Find:
#
# 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 ."
# ErrorDocument 404/missing.html
# ErrorDocument 404 "/cgi-bin/missing_handler.pl"
# ErrorDocument 402 http://www.example.com/subscription_info.html
#
This part in httpd. conf, # ErrorDocument 404/missing.html
Change a row to ErrorDocument 404/error/nofile.htm, and the value of nofile.htm is d: \ server \ www \ error \ next error file.
You need to create it yourself. When a error occurs, enter the nofile.htm page and you will be prompted that the page is not found. In this way, you cannot see
Your server software information. You can also set other error-oriented pages. For more information about the http response error numbers, see.
Restart apache. If no accident occurs, the installation is successful. Put the static page in the d: \ server \ www \ error \ directory to check whether the parsing can be successful.
Enter http: // localhost/sdagasgdasasg.htm, which indicates that the 404error is incorrect, that is, the nofile.htm error page.
Succeeded!
I will not mention the meaning of other parameters in apache. You can check them online. In fact, the best way is to check the comments in httpd. conf.
Points, you have already made it very clear.
Now, apache is successfully installed. You can take a break, listen to the music, and start the next installation :)

Iii. install php
Decompress php-4.3.3-win32.zip to the Directory d: \ server \ php. Configure PHP and Apache to parse the php program.
Rename "php. ini-dist" in the d: \ server \ php \ directory and copy it to C: \ windows \ system32
(The Win2K directory is C: \ winnt \ system32). In the apache configuration file httpd. conf, enter the following lines
Supports 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 webpage: index. php under d: \ server \ www with the following content:
<Html>
<Head> <title> php test </title> <? Php
Phpinfo ();
?>
</Html>
Use the text editor to edit it as index. php, restart apache, and enter http: // localhost/index. php in IE.
Environment variable, indicating that php is successfully installed. If it cannot be parsed, <? Php phpinfo ();?> Is not installed successfully.

4. Tomcat installation
I use the jakarta-tomcat-4.1.30.exe installation file. In windows, click "OK". The installation directory is
D: \ server \ tomcat
Set the environment variables as follows:
Add the TOMCAT_HOME variable to the environment variable of jdk. The value is d: \ server \ tomcat. Add the variable CATALINA_HOME. The value is
D: \ tomcat \ server, add d: \ server \ tomcat \ bin to the path variable
Start tomcat and run the bin/startup. bat file in the tomcat directory. The tomcat running console is displayed, and tomcat is successful.
Start.
Enter http: // localhost: 8080/in IE. Check that tomcat is installed successfully.

5. Install MySQL

Step 1: unzip the mysql-max-3.23.46a-win.zip, run the mysql Installation File, install mysql to d: \ server \ mysql
Step 2: Add d: \ server \ mysql \ bin to the environment variable path
Step 3: Go to the d: \ server \ mysql \ bin directory and run winmysqladmin. the dialog box appears, set the mysql user password, assuming
The root account password is 123.
Step 4: Go to dos, go to mysql/bin, and run the following command to open mysql
Mysqld-nt -- standalone
Mysql is enabled.
Then run:
Mysql
If enabled, 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: No password is set for mysql at this time. To prevent others from entering your database, set a password for mysql. For detailed operations, see mysql
.
So far, mysql has been installed successfully!

6. Install MySQL driver jdbc
Unbind the jdbc driver package and copy the org folder to a location that can be found in jsp. It can be the tomcat root directory common/classes
Folder, can also be jsp site class WEB-INF/class. When the driver is loaded, you can find related classes. Or set the jdbc package
To the classpath variable.

VII. Integrated configuration of Tomcat and Apache
Tomcat is just a container used to parse *. jsp files. It is not a server, and 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. In the case of *. jsp web pages, it is resolved by tomcat.
Step 1: Copy mod_jk.dll to the module folder in the apache root directory.
Step 2: Configure APACHE

Open conf \ httpd. conf in the apache root directory.

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 above statements basically mean:
LoadModule: load the mod_jk.dll Dynamic Link Library module to communicate with tomcat.
JkWorkersFile: Specifies the location of the tomcat-related file workers. properties at work.
JkMount: the 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 and create the workers. properties file under the conf directory of tomcat. 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

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. worker _line =-config

Worker. inprocess. worker _line = $ (workers. worker at_home)/conf/jni_server.xml

Worker. inprocess. worker _line =-home

Worker. inprocess. worker _line = $ (workers. worker at_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 and second lines of the above files fill in the relevant directories of tomcat and jdk.
 
Step 4: Configure the server. xml file under cmda/conf. This is the main configuration file of tomcat. The important configuration is as follows:
1. virtual directory settings:
Find the following content:
<Host name = "localhost" debug = "0" appBase = "/webapps"
UnpackWARs = "true" autoDeploy = "true">
To:
<Host name = "localhost" debug = "0" appBase = "d:/server/www"
UnpackWARs = "true" autoDeploy = "true">
Make tomcat Home Directory d: \ server \ www.
Find the following content:
<Context path = "examples" docBase = "/examples" debug = "0"
Reloadable = "true" crossContext = "true">
Change
<Context path = "" docBase = "/" debug = "0"
Reloadable = "true" crossContext = "true">
My understanding is that jsp under the tomcat root directory 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 number is 8080, but we all know that it is best to modify it. If it is changed to 8123, 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 port 8009. This is very important. Through port 8009, tomcat communicates with apache. If the following section
<! ----> Comment out, make 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 the conf/web. xml file of tomcat:
Similar to the configuration of the 404 error page in 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. jsp </location>
</Error-page>
The first error between <error-page> </error-page> is the error-oriented page where the jsp page is not found in 404. When the error 404 occurs,
The webpage directs to/error/noFile.htm. You can also use a similar method to add many error code-oriented pages.
The second <error-page> </error-page> occurs when java. lang. NullPointerException occurs on a jsp page.
Go to the/error. jsp error page. Add the following content to the first jsp page:
<% @ Page errorPage = "/error. jsp" %>
The 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>

<Body>
Error: </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 an NullPointerException exception occurs, tomcat imports the webpage to error. jsp and prints the error message.
Step 5 focuses on security considerations. Under normal circumstances, if the webpage cannot be found, the 404 error or jsp program error may occur.
The following information is listed (using 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 will not happen.
Step 6: configure the httpd. conf file
In this way, the root directory of tomcat and apache is set to the same directory, but you must restrict access to some files in the directory, such
To add the following code under httpd. conf:
# Deny the access to WEB-INF
<Directory ~ /WEB-INF/>
Order allow, deny
Deny from all
</Directory>
In this way, apache rejects http: // localhost/web-inf.

By now, the integration of tomcat and apache is complete. Restart tomcat and apache,
Place the jsp webpage under d: \ server \ www \, for example:
<Html>
<H1> JSP test

<% Out. println ("Hello World! "); %>

</Html>
Save as index. jsp and enter http: // localhost: 8123/index. jsp in IE
If
Hello World!
Tomcat is running normally. Enter http: // localhost/index. jsp in IE.
Hello World!
Congratulations! Integration is successful, and you have taken a big step on the long and difficult way of jsp ~!

I have completed the above integrated articles in a rush and may be wrong. Or you may not consider the week, but the overall plan should not
This is a big problem. I have used this method repeatedly to successfully integrate it. If you have any questions, contact me directly.
Moonsbird: mail: pengw97@163.com

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.