Integrated configuration of Apache + Tomcat + MySQL + jsp + php servers in Windows

Source: Internet
Author: User
Tags php server
In Windows, Apache + Tomcat + MySQL + jsp + php server integration configuration-Linux Enterprise Application-Linux server application information. The following is a detailed description. [I = s] This post was last edited by shuming at, January 29 ,.After configuring the web server for the first time, you can understand the basic configuration in widows. Reference: The integration idea in linux and windows is the same. apache is used for parsing *. html /*. htm static webpage, when *. when jsp and servlet are used, a module in apache is used to throw the jsp page to Tomcat (or resin) for processing. Compiling the module in linux requires a little trouble, this article uses a module under win to complete integration. Required Software (1) j2sdk-1_4_2-windows-i586.exe jdk version relationship is not very big, does not affect the integration of Apache and Tomcat, configure the environment variables pay attention to some on the line. (2) apache_2.0.49-win32-x86-no_ssl.exe apache version does not have much impact on integration, but it is best to use this version. (3) jakarta-tomcat-4.1.30.exe version is best to use this version, other I have not tried, may cause the integration is not successful. (4) is a compressed package, download it and unzip it directly. (5) The module mod_jk.rar is placed in the module of apache, which is used to communicate between Tomcat and Apache. (6) database mysql, its version has little impact on integration. (7) jdbc driver mysql driver, and database connection with the following start to install all the software:. install j2sdk in windows and directly run the j2sdk-00004_2-windows-i586.exe file. install it in a directory according to the installation wizard, for example, d: \ server \ j2sdk1.4.2 1. configure the environment variable: add the CLASSPATH variable with the value :.; d: \ server \ j2sdk1.4.2 \ lib \ dt. jar; d: \ server \ j2sdk1.4.2 \ lib \ tools. jar; this configuration ensures that the class can be found during java runtime. Note: Classpath is a class path: Learn How java program runs: (1 ). javac ***. java ----> ****. class file, (2 ). the Java virtual machine uses classloader to load the above bytecode (. class file) and java class libraries that have been encapsulated and called java commands for execution. class files, and classloader queries bytecode through the location specified by the class path classpath. Where. ----> current directory, that is. the directory where the java file and the javac compiled file are located; D: \ server \ j2sdk1.4.2 \ lib \ dt. jar; d: \ server \ j2sdk1.4.2 \ lib \ tools. both jar files are class library files in jdk. 2. add the JAVA_HOME variable. The value of the variable is d: \ server \ j2sdk1.4.2 java_home: The jdk installation path. The jdk installation path is used when running the program. Therefore, record it first. When used, it is queried Based on java_home. 3. In the original path variable, add d: \ server \ j2sdk1.4.2 \ bin so that you can run the java name command wherever you are. Note: the path variable is used to input related commands (javac and java) in dos. The dos system calls the corresponding methods of the command to perform operations. These query the corresponding command order based on the address in the path. 4. restart the computer. Cmd enters dos and runs java and javac to check whether there is any response. If the command is helpful, you can run a java applet to check whether java is successfully installed. public class test {public static void main (String args []) {System. out. println ("It indicates that java is successfully installed! ") ;}} Store the program in test. in the java file, it must be test. java, and then use the command to compile javac test. if there are no errors in java, it indicates that the compilation is successful. If there is a mistake, the java environment variable has not been configured and has just been reconfigured based on the correct program writing. If the compilation is successful, run: java test note, not java test. java! If no error is found, the following message is displayed: the java installation is successful! Gxgx: jdk has been installed successfully! You can proceed to the next step. 5. note: Generally, when cmd enters dos, a directory is displayed by default: enter with cd ***. if you do not go to the java file directory, click ***. compile and execute java in the default dos directory. 2. Install and run apache_2.0.49-win32-x86-no_ssl.exe in apache. Select d: \ server \ apache group as the path. Apache has been installed successfully and is running. in IE, enter http://localhost/ You can see the apache homepage. Installed successfully! 2. modify httpd. the configuration file of conf 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 "changed to DocumentRoot" D:/server/www (2 ). modify the character settings apache parsing Chinese web page will generate garbled, modify AddDefaultCharset ISO-8859-1 to AddDefaultCharset GB2312 (3 ). modify the default homepage when accessing the directory, apache will automatically import the Home Page. The priority of the DirectoryIndex index.html is prioritized accordingly. change var to DirectoryIndex index.html index. jsp Index. php default. jsp default. php index.html. var (4 ). setting the error page makes your website safer. If you do not set the page, if you enter a path after your website, the Error 404 is 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. If a 404 error occurs, that is, the webpage cannot be found, import the visitor to an error page and 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/ "# ErrorDocument 402 Httpd. in the conf file, change the # ErrorDocument 404/missing.html line to ErrorDocument 404/error/nofile.htm, and the nofile.htm is d: \ server \ www \ error \ next error file, which must be created by 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. If no accident occurs when apache is started, the installation is successful. Put the static page in the d: \ server \ www \ error \ directory to check whether the parsing can be successful. Enter either of the following: http://localhost/ Apache installation successful 3. php installation decompress to the d: \ server \ php Directory. Configure PHP and Apache so that php programs can be parsed. Set "php." In the d: \ server \ php \ directory. ini-dist "is renamed" php. ini, and copy it to C: \ windows \ system32 (the Win2K directory is: C: \ winnt \ system32), in the apache configuration file httpd. add the following lines to the conf file to 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" ---------> php-5 with Action application/x-httpd-php "/php/php-cgi.exe" ---------> For php5 and php5, select one sentence based on the php version. Create a webpage: index. php under d: \ server \ www with the following content: Php Testing You can use the text editor to edit it as index. php, restart apache, and enter http: // localhost/index in IE. php. If the php environment variable appears, it indicates that php is successfully installed. If it cannot be parsed Is not installed successfully. 4. tomcat installation 1. I use the jakarta-tomcat-4.1.30.exe installation file. In windows, click "OK". The installation directory is d: \ server \ tomcat 2. set the environment variable as follows: (1 ). add the TOMCAT_HOME variable to the environment variable of jdk. The value is d: \ server \ tomcat -----> tomcat installation directory; (2 ). add the variable CATALINA_HOME with the value d: \ server \ tomcat -----> servlet container; (3 ). add d: \ server \ tomcat \ bin ------> to the path variable to find the tomcat command 3. start tomcat and run bin/startup in the tomcat directory. the bat file is ready. The tomcat running console is displayed, and tomcat is started successfully. enter http://localhost:8080/ If you see the big cat, tomcat is successfully installed. 5. install MySQL Step 1: unzip the, run the mysql Installation File, install mysql to d: \ server \ mysql Step 2: Add d to the environment variable path: \ server \ mysql \ bin ------> to find the mysql Command Step 3: Enter the d: \ server \ mysql \ bin directory and run winmysqladmin. A dialog box is displayed, set the mysql user password. Assume that the account is: root Password: 123 Step 4: Go to dos and go to mysql/bin, run the following command to open mysql ---> mysqld-nt -- standalone to enable mysql. Note: It can be automatically started after mysql is installed. Therefore, the preceding startup command is not reflected. Enter the mysql command to go to the page. Run the following command: 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 the mysql Chinese instructions. So far, mysql has been installed successfully! 6. Install MySQL driver jdbc to unbind the jdbc driver package and copy the org folder to the location that can be found in jsp. Can be tomcat root directory common/classes folder, can also be jsp website class WEB-INF/class. When the driver is loaded, you can find related classes. Or add the jdbc package path to the classpath variable. 7. the integrated configuration of Tomcat and Apache Tomcat is only used for parsing *. the jsp file container is not a server. Its ability to parse static htm/html files is far inferior to that of apache. After integration, apache can parse static webpages on the same port *. jsp web pages are parsed by tomcat. step 1: Copy mod_jk.dll to the module folder in the apache root directory. Note: unzip mod_jk.dll.rar and paste the following information. place the dll file in the modules folder. Step 2: Configure APACHE to open conf \ httpd under the apache root directory. add the following statement to conf: # ------------------------------------ # connecting to tomcat using ajp13 LoadModule jk_module modules/mod_jk_2.0.47.dll JkWorkersFile "d:/server/tomcat/conf/workers. properties "JkMount/servlet/* ajp13 JkMount /*. jsp ajp13 # ------------------------------------------------------- note: the basic meaning of the above statement is: loadModu Le: load the dynamic link library module of mod_jk.dll to communicate with tomcat. Note: There are many mod_jk modules in LoadModule jk_module/mod_jk_2.0.47.dll. select a dll file that corresponds to the apache version (which is close to the one you may not understand). Otherwise, mod_jk in modules cannot be used. an error occurred while loading the dll to the server. JkWorkersFile: Specifies the workers. properties location of the tomcat-related file at work. 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 workers. properties file, and create workers under the tomcat root directory conf. properties file with the following content: workers. tomcat_home = d: \ server \ tomcat ----> tomcat installation path workers. java_home = d: \ server \ j2sdk1.4.2 ----> jdk installation path ps =\# worker. list = ajp13 worker. list = ajp12, ajp13 worker. ajp12.port = 8007worker. = localhostworker. ajp12.type = ajp12 worker. ajp12.lbfactor = 1worker. ajp12.port = 8007worker. = localhostworker. ajp12.type = ajp12 worker. ajp12.lbfactor = 1 worker. ajp13.port = 8009 worker. = localhost worker. ajp13.type = ajp13worker. ajp13.lbfactor = 1worker. loadbalancer. type = lb worker. loadbalancer. balanced_workers = ajp12, ajp13worker. 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. jarworker. inprocess. class_path = $ (workers. java_home) $ (ps) lib $ (ps) tools. jar worker. inprocess. pai_line =-config worker. inprocess. worker _line = $ (workers. tomcat_home)/conf/jni_server.xml worker. inprocess. pai_line =-home worker. inprocess. worker _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) Pay attention to the installation path of tomcat and jdk in the first and second lines of the above files. step 4: Configure the server under consumer A/conf. xml file, which is the main configuration file of tomcat. The important configuration is as follows: 1. virtual directory settings: (1 ). find the following content: To: Make tomcat Home Directory d: \ server \ www. (2). Find the following content: Change 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: 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: 3. Find the following port 8009. This is very important. Through port 8009, tomcat communicates with apache. If the following part is Comment out, make sure Remove. Step 5: configure the conf/web. xml file of tomcat: similar to the configuration of the 404 error page in apacheAdd the following content before a row: 404 /Error/noFile.htm Java. lang. NullPointerException /Error. jsp First The difference is that 404 does not find the error-oriented page of the jsp page, so that when the 404 error occurs, the page directs to/error/noFile.htm, you can also add multiple error codes to the page in a similar way. Second When java. lang. NullPointerException occurs on the jsp page, it is redirected to the/error. jsp error page. Add the following content to the first jsp page: <% @ page errorPage = "/error. jsp "%> Typical error. the jsp error page program is written as follows: <% @ page contentType = "text/html; charset = GB2312" %> <% @ page isErrorPage = "true" %> Error Page Error:

Error message: <% = exception. getMessage () %>
Stack Trace is:
<% cw = new; pw = new,true);    exception.printStackTrace(pw);    out.println(cw.toString());    %>
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 a webpage cannot be found, a 404 error or a jsp program error occurs, the client will list information similar to the following (take tomcat as an example, similar to resin): HTTP Status 404-/sdags. jsp -------------------------------------------------------------------------------- type Status report message/sdags. jsp description The requested resource (/sdags. jsp) is not available implements Apache Tomcat/5.0.19, so that the server version will be seen by others. If the configuration in step 5 is completed, this will not happen. step 6: Configure 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 as the web-inf stored in the class, in httpd. add the following code under conf: # deny the access to WEB-INF Order allow, deny Deny from all In this way, apache rejects http: // localhost/web-inf. by now, the integration of tomcat and apache is complete. restart tomcat and apache and put the jsp webpage under d: \ server \ www \. For example:JSP test <% out. println ("Hello World! "); %>Save as index. jsp. Input http: // localhost: 8123/index. jsp in IE if Hello World! It indicates that tomcat is running normally. in IE, enter http: // localhost/index. jsp. If Hello World is displayed! Congratulations! Integration is successful, and you have taken a big step on the long and difficult way of jsp ~! Note: many of the following problems may occur when apache is started: System. net. sockets. socketException: Generally, each socket address (Protocol/network address port) can only be used once. This is a netsh winsock reset problem. There are two solutions: 1.WinsockxpFix.exe tries to fix winsock. After restarting, apache can be started. 2. the host does not need to be restarted. You only need to fix the network connection. In fact, Windows has a repair tool. You only need to enter netsh winsock reset in the running state to indicate that you do not need to restart the system, the problem is completely solved, which is very good and powerful!
Related Article

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: 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.