Do a jam bottle [Jampot] server
- Set JSP, PHP, MySQL Web Server
After a few days, I got the countless article on the Internet, I have experienced a number of unclear failures, I finally do a web server that supports JSP, PHP programming languages, mySQL database, and now consolidate the experience, for the friends, Let's go!
First, application environment and required software
1. Operating system: WindowsXP SP2
2. Application software:
(1) J2SDK-1_4_2-windows-i586.exe
Description: Java development kit software from Sun Company;
(2) Apache_2.0.52-win32-x86-no_ssl.exe
Description: The most popular personal web server software is currently;
(3) mysql-4.1.7-win.exe
Description: The World's Most Popular Open Source Database, the key may be cheap, j
(4) MOD_JK_2.0.46.DLL
Description: For communication between Apache and Tomcat;
(5) PHP-5.0.2-win32.zip
Description: The most popular web background programming language PHP
(6) phpMyadmin-2.6.0.zip
Description: MySQL database management software written with PHP
(7) [odbc] mysql-connector-java-3.1.7-bin.jar
Description: JSP uses a driver file when connecting to the MySQL database;
(8) Tomcat-5.0.30.exe
Description: A JSP application container cannot be completely replaced by apache;
The above software can be found online, or you can download it here.
Second, install software and configuration
For convenience, please establish a D: / jampot folder first, well, start installing the software:
Install JDK
Run J2SDK-1_4_2-Windows-i586.exe, when selecting the installation path, select D: /jampot/J2SDK1.4.2, after the installation is complete, then to "My Computer> Properties> Advanced> Environment Variable" as follows:
Add Java_Home variable, the variable value is: D: / jampot /j2sdk1.4.2
Modify the PATH variable, add D: / Jampot / J2SDK1.4.2 / bin, so that you are running in any way to run the java command.
Restart CMD into DOS, run Java and Javac to see if there is any reaction, if the command is helpful, then Java is successful, you can also run a Java applet:
Public class testjdk {
Public static void main (string arg []) {
System.out.println ("Hello, THE JDK IS Install Successful!");
}
}
Saved as Testjdk.java, then run under CMD
Javac Testjdk.java
Java Testjdk
If "Hello, THE JDK IS Install Successful!", Then we can go next step.
2. Install Apache
(1) Run Apache_2.0.52-win32-x86-no_ssl.exe, all the way "OK" and "Accept" in line, select the path to input D: / jampot; the Apache directory after the installation is d: / jampot / apache2, After the installation is successful, the Apache service will run automatically, enter http: // localhost / you can see the homepage of Apache in IE. (2) Modify httpd.conf
Apache's configuration file is httpd.conf, under the CONF folder under the Apache root directory
1 Modify the default website root directory:
Create a folder WWW under D: / Jampot to use this as the root of the website
DocumentRoot "D: / jampot / apache2 / htdocs"
Change to DocumentRoot "D: / Jampot / WWW"
2 Modify Character Settings
Apache will generate garbled when resolving Chinese webpages,
Modify AddDefaultcharset ISO-8859-1 is AddDefaultCharset GB2312
Or will be plugged in the AddDefaultCharset ISO-8859-1 ##
3 Modify the default homepage
When accessing the directory, Apache will automatically import the home page, priority is subject to the order
Change DirectoryIndex INDEX.html Index.html to
DirectoryIndex Index.html Index.jsp Index.php Default.jsp Default.php Index.html
4 Setup Error Page [Recommended Settings]
This will be more secure for your website. If you don't set it, you will enter a path after your URL, you will display 404 errors, and you will display your server version number, the server configuration is clear, in order to avoid this, you can Set the error page. When a 404 error occurs, it is found to find the webpage, import the visitor into an error page, find this part in httpd.conf:
# 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
Modify #errordocument 404/missing.html a line to ErrorDocument 404 /ERRR/nofile.htm, where nofile.htm is D: / Jampot / WWW / Error / next error file, you need yourself. When a 404 error occurs, enter the Nofile.htm page, you can prompt the web page. This is impossible to see your server software information. You can also set other error-oriented pages, please refer to the relevant information for the specific HTTP response error number.
Restart Apache, if there is no accident, it is already installed, put the static page into the D: / Server / WWW / Error / Directory, see if you can successfully resolve. Just enter one: http://localhost/sdagasgdasaSg.htm, see if it is directed to the 404 error, namely the nofile.htm error page. Success? Ok, start the next step. 3. Install MySQL
Run mysql-4.1.7-win.exe, the default installation is in c: / mysql, here we will install the mysql database to D: / jampot / mysql4_1, for MySQL 4.1 previous version, may need after the installation is completed MY-Small.cnf within the mysql directory is copied to C: / Windows, renamed my.ini and modified as follows:
[mysqld]
Basedir = D: / jampot / mysql
DATADIR = D: / jampot / mysql / data
Modify the PATH variable, add D: / jampot / mysql4_1 / bin, so that you are running at the mysql command.
Start CMD, enter:
Mysql -u root -p
Enter your password (assuming to ABC)
ABC
If the following characters appear:
Welcome to the mysql monitor. ComMmonds end with; or / g. Your mysql connection ID is 1 to server version: 4.1.7-nt type 'help;' or '/ h' for help. Type '/ c' to clear the Buffer. mysql>
So, our MySQL database is successful! Let's start installing PHP.
4. Install PHP
PHP-5.0.2-win32.zip is a zip compressed file, unzip file to D: / jampot / php5, then open the PHP5 directory, you will find a file called "php.ini-dist", this is PHP configuration file, you need to change it into "php.ini", then copy it to the Windows directory, copy the "php5apache2.dll" file under the D: / jampot / php5 directory to D: / jampot / aphache2 / BIN directory.
Open the php.ini file, do the following modification:
Find extension_dir = "./" changed to extension_dir = "d: / jampot / php5 / ext"
Find; session.save_path = "/ tmp" will ';'
Set you save the session directory, such as session.save_path = "d: / jampot / php5 / session_temp";
Edit Apache2 / Conf / httpd.conf file:
In the last side of the file plus two sentences:
LoadModule PHP5_MODULE BIN / PHP5APACHE2.DLL
AddType Application / X-httpd-php .php .php3
PHPINIDIR "D: / jampot / php5"
Write a simplest PHP program test:
PHP
PHPINFO ();
?>
Named INFO.PHP to deploy down D: / jampot / www, then knock http: //localhost/info.php inside the address bar, you should display the information about PHP and Apache2, now you can use PHP, but we must Let PHP support MySQL, open the php.ini file, do the following modification: found; extension = php_mysql.dll will ';' go to change to extension = php_mysql.dll
Ok, save, restart Apache, write a program to test.
PHP
$ link = mysql_connect ('localhost', 'username', 'password');
IF (! $ link) echo "fail";
Else Echo "Success";
MySQL_Close ();
?>
If "Success" appears after running, then your PHP can use the MySQL database, so far, our server is already half configured, it supports the PHP language, MySQL database, take a break.
5. Install PHPMYADMIN
Unzip phpMyadmin-2.6.0.zip to D: / jampot / phpMyAdmin2_6, modify the config.inc.php file within the directory:
Set $ cfg ['PMaabSoluteuri']] for http: // localhost / phpmyadmin
Set $ cfg ['BLOWFISH_SECRET'] = 'admin'
Set $ cfg ['Servers'] ['$ I'] ['Auth_Type'] = 'Cookie'
Set $ cfg ['Servers'] ['$ I'] ['user'] for mysql username
Set $ cfg ['Servers'] ['$ I'] ['Password'] for mysql user password
Modify the httpd.conf file in Apache, add the statement at the bottom:
PHP_ADMIN_FLAG ENGINE ON
PHP_ADMIN_FLAG SAFE_MODE OFF
Alias / phpmyadmin "d: / jampot / phpmyadmin2_6"
DirectoryIndex Index.php
Options Indexes MultiViews
ALLOWOVERRIDE NONE
ORDER ALOW, DENY
ALLOW FROM ALL
PHP_ADMIN_FLAG ENGINE ON
PHP_ADMIN_FLAG SAFE_MODE OFF
PHP_ADMIN_VALUE OPEN_BASEDIR NONE
PHP_ADMIN_VALUE OPEN_BASEDIR "D: / jampot / phpMyAdmin2_6"
Directory>
Note: Pay attention to the case when modified!
6. Install Tomcat
In fact, in the previous process, did not use JDK, and install it first because the author's love, but now, we will use JDK. Run the Tomcat-5.0.30.exe installation file, "OK" in Windows, it is, relatively simple, the installation directory is D: / jampot / tomcat5, set the environment variable below: Add variable tomcat_home, the variable value: D: / Jampot / tomcat5
Modify Path variable, add D: / jampot / tomcat5 / bin
After restarting, Tomcat will start automatically. Enter http: // localhost: 8080 /, then you can see the home page of Tomcat. This is installed in Tomat, and write a JSP file test.
<% out.println ("This Is A JSP Page!");%>
html>
Put the file as jtest.jsp, put it in the D: / Jampot / Tomcat5 / WebApps / root directory. Then enter http: // localhost: 8080 / jtest.jsp in IE, have you seen it?
We have two problems now to solve, one is to merge with the Aache server; second, let JSP can connect to the MySQL database.
The first step is to merge the AACHE server.
Tomcat is just a container used to resolve * .jsp files. It is not a server. It is not as good as Apache. After the integration is integrated, the Apache will resolve the static web page, and encounter * .jsp When the webpage, it will be parsed by Tomcat.
1) Copy the mod_jk_2.0.46.dll file to the Apache2 root directory bin folder.
2) Modify the httpd.conf file under the Apache directory, and add the following statement at this file:
# ------------------------------------------
#Connecting to Tomcat Using AJP13
LoadModule JK_Module Bin / Mod_jk_2.0.46.dll
JkWorkersFile "D: /jampot/tomcat5/conf/Workers.properties"
JKMOUNT / Servlet / * ajp13
JKMount /*.jsp Ajp13
# ------------------------------------------------- ----
Note: The basic meaning of the above statement is:
LoadModule One line: Load MOD_JK_2.0.46.DLL dynamic link library module to make it communicated with Tomcat;
JKWORKERSFILE: Indicates the Tomcat related files in Workers.Properties position;
JKMount: The two lines indicate that when they encounter * .jsp and servlet, they will be transferred to the AJP13 protocol and then forward to Tomcat processing.
3) Create a workers.properties file in the D: / jampot / tomcat5 / conf directory, the content is:
Workers.tomcat_home = d: / jampot / Tomcat5
Workers.java_home = d: / jampot / j2sdk1.4.2
PS = /
# worker.list = ajp13
Worker.list = ajp12, ajp13
Worker.ajp12.port = 8007worker.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) class 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, second lines fill in your own Tomcat and JDK's related directories.
4) Modify the server.xml file under D: / Jampot / Tomcat5 / Conf, this is the main configuration file of Tomcat, do the following modifications:
1 Set the Tomcat listening port and find the following:
Ort = "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 this everyone knows, it is best to modify, suppose to modify: 8178, then as follows: Port = "8178" minprocessors = "5" maxprocessors = "75" Enablelookups = "True" redirectport = "8443" Acceptcount = "100" debug = "0" connectionTIMEOUT = "0" Useurivalidationhack = "false" disableuploadtimeout = "true" /> 2 Find the following 8009 port, this is very important, pass 8009, Tomcat and Apache communication, if the following Note by , must remove it . Enablelookups = "false" redirectport = "8443" debug = "0" Protocol = "AJP / 1.3" /> 3 Add the following statement on host>: This sentence means adding a virtual directory TEST to Tomcat, and establishing a TEST directory under D: / Jampot / WWW, copy the jtest.jsp file to the folder. 5) Modify the web.xml file under D: / jampot / tomcat5 / conf [recommended]: Similar to the configuration of the 404 error page under Apache, add the following before the last web-app>: Error-Page> Error-Page> The first The second <% @ Page ErrorPage = "/ Error / Error.jsp"%> A typical error.jsp error page is written as follows: <% @ Page ContentType = "text / html; charset = GB2312"%> <% @ page isrrorpage = "true"%> Error: p> 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);
Xception.PrintStackTrace (PW);
Out.println (cw.toString ());
%>
font> pre>
html>
Tomcat is imported into Error.jsp when nullpointerexception is often the NullPointersRexception exception. The modification here is mainly for security considerations. Under normal circumstances, if you can't find a web page, a 404 error or JSP program has an error, and you will list the following information (Tomcat as an example, RESIN. ):
Http status 404 - /sdags.jsp
-------------------------------------------------- ------------------------------
Type Status Report
Message /sdags.jsp
Description The Requested Resource (/SDags.jsp) Is Not Available.
-------------------------------------------------- ------------------------------
Apache Tomcat / 5.0.30
This way the server version will be seen by others. If you make the web.xml file as above, this will not happen. Restart Tomcat in "Service", then enter http: // localhost: 8178 / test / jtest.jsp, you can run, then enter http: //localhost/test/jtest.jsp, is it possible to run . This way, we only need to put JSP in the JSPFile folder, and the first part is completed. Step 2 - Let JSP connection to MySQL database
Copy the mysql-connector-java-3.1.7-bin.jar file to the D: /jampot/j2sdk1.4.2/jre/lib/ext directory or copy the mysql-connector-java-3.1.7-bin.jar file to D: / jampot / Tomcat5 / Common / lib directory,
Write a file jtestmysql.jsp to do test:
<% @ Page ContentType = "text / html; charset = GB2312"%>
<% @ Page Import = "java.sql. *"%>
<%
Class.Forname ("Org.gjt.mm.mysql.driver"). NewInstance ();
String url = "jdbc: mysql: // localhost / test?
User = username & password = userpass & useunicode = True & Characterencoding = 8859_1 ";
Connection conn = drivermanager.getConnection (URL);
Statement Stmt = Conn.createStatement (ResultSet.Type_Scroll_Sensitive, ResultSet.concur_Updata);
String SQL = "SELECT * from TbTest";
ResultSet RS = Stmt.executeQuery (SQL);
While (rs.next ()) {
%>
Your first Field IS: <% = rs.getstring (1)%>
Your Second Field IS: <% = rs.getstring (2)%>
<%}%>
<% out.print ("Operation Database IS Success, Congratulate You!");%>
<% rs.close ();
Stmt.close ();
CONN.CLOSE ();
%>
body>
html>
Save the file under D: / Jampot / WWW / TEST, enter http: // localhost /test/jtestmysql.jsp in IE, if you see "Operation Database Is Success, Congratulate You!", Then explain that we have You can use JSP to connect the MySQL database, well, we can use this jam bottle J
Third, pay attention to the problem
1. MySQL database and PHP connection problem:
MySQL4.1 is different from the past, first in the installation process, it will ask you to set the root password, so after installation, you cannot use an empty password to enter mysql as the front version. In addition, MySQL has also reforms the password. After adding a user, we cannot use the grant command, but also use the password command, otherwise, it will not be connected with the PHP to connect to the database. For a word: Suppose we build a userTestSt using the Test database, the password is Passtest;
Enter mysql with root, enter:
Grant all on test. * to usestest @ locathost ';
At this time, you can use this user to enter mysql under CMD, but when connecting with a PHP language, it will be reported. This is because MySQL changes the encryption method of the password, so we have to change the userTestest's password to the old encryption method, enter MYSQL with root, enter:
Set password for usest @ localhost = OLD_Password ('passtest');
Exit MySQL and connect with PHP, successfully.
2. Problems about the mode of operation of PHP
Scriptalias / PHP / "C: / PHP /"
AddType Application / X-httpd-php .php
Action Application / X-httpd-php "/ php/Php.exe"
or
LoadModule PHP4_MODULE C: /PHP/SAPI/php5apache2.dll
AddType Application / X-httpd-php .php4
Scriptalias / PHP4 / "C: / PHP /"
Action Application / X-httpd-php4 "/ php4/php.exe"
AddType Application / X-httpd-php4 .php
Some of the best in the upper side said that PHP is running in modular operation, and some people say that it is running in CGI mode, I have not studied, and I have recorded interesters.
3. Tomcat and Aache mergers and virtual hosts
For the JSP file accessed under the Apache host, it is actually physically physically on the host of Apache, but there is a host directory of Tomcat, for example:
The jtest.jsp file in httest.jsp actually exists under D: / Jampot / Tomcat5 / WebApps / ROOT in d: / jampot / tomcat5 / webapps / root. Please note this, don't confuse the concept!
In this article, I am using the virtual directory method to solve, namely:
The TEST directory under WWW is a virtual TEST directory under root in Tomcat.
There is also a virtual host method on the Internet, I don't quite clear, listed here, for interested friends:
Implementation of Tomcat and Apache virtual host:
This method sets Tomcat and Apache's root directory, but must restrict access to some texts in the directory, such as the Class's web-inf, add the following code to httpd.conf: # deny the access to WEB-INF
ORDER ALOW, DENY
Deny from all
Directory>
In the final addition to the following
ServerAdmin admin@rosealet.com // Your mail address
DocumentRoot D: / YourWeb // Your project root directory
ServerName Localhost // Your service name, if your machine has domain name, set it to domain name
ErrorLog logs / rosealet_home_log.txt // Error log, under C: / Apache / logs
CustomLog logs / rosealet_custom_log.txt common // Access log, under C: / Apache / logs
Virtualhost>
4. About the version compatibility problem in the software in this article
When I just started to configure the server, the Tomcat software used was Tomcat 5.5.7. I found that I couldn't run. Later, I saw the log file. I learned that the version of Tomcat 5.5 needs JDK1.5 or more, and I have re-downloaded it again. A Tomcat 5.0.30 can only be used.
In addition, MySQL-Connector-Java-3.1.7-bin.jar file is a file in the directory after mysql-connector-java-3.1.7.zip file - there is this file. MySQL-CONNECTOR-JAVA-3.1.7.Zip file can be downloaded to mySQL.com website, I am looking at it, I find it suggest that the mysql database uses the version after 4.1, so I don't guarantee that the file can be connected. The mysql database 4.1 previous version.
At this point, this article should come to a paragraph, I have to thank the online netizens, do not refer to their related articles, relying on myself to spend more time and energy, but most people are not signed by writing. So I can only say thank you for my moonsbird (http://www.hyd8.net/info/10100.htm), this article is initially written, if there is any mistake, please forgive and tell you (Mail: kafeimo@371.net ),Thank you!
I Home: http://javaheart.niwote.com
I qq: 312652431
Nette: Ink · Non [Mophay]
Tuesday, April 5, 2005
0:6 am
Related download:
1. http://freeweb.nyist.net/~bwc/bd/j2sdk-1_4_2.exe
2. http://freeweb.nyist.net/~bwc/bd/jakarta-tomcat-5.0.30.exe
3. http://freeweb.nyist.net/~bwc/bd/mod_jk_2.0.46.dll
4. http://freeweb.nyist.net/~bwc/bd/mysql-connector-java-3.1.7-bin.jar
5. http://freeweb.nyist.net/~guyusl/bd/apache_2.0.52-win32-x86-no_ssl.msi6. Http://freeweb.nyist.net/~guyusl/bd/mysql-4.1.7- Win.exe
7. http://freeweb.nyist.net/~guyusl/bd/php-5.0.2-win32.zip
8. http://freeweb.nyist.net/~guyusl/bd/phpmyadmin-2.6.0.zip