网络编程
位置:首页>> 网络编程>> php编程>> wdcp添加tomcat,同时支持php和java教程

wdcp添加tomcat,同时支持php和java教程

作者:断剑残缺  发布时间:2023-10-09 10:39:38 

标签:wdcp,tomcat,php,java

用wdcp官方提供的脚本安装lnamp环境,安装请参考:http://www.wdlinux.cn/bbs/thread-6292-1-1.html,本文主要讲如何在LNAMP环境下安装JDK+Tomcat6使同一台服务器同时支持PHP和JAVA语言。服务器系统和各软件版本如下所示

  1. [root@E ~]# uname -a

  2. Linux E.CentOS6.4 2.6.32-358.el6.x86_64 #1 SMP Fri Feb 22 00:31:26 UTC 2013 x86_64 x86_64 x86_64 GNU/Linux

  3. [root@E ~]# /www/wdlinux/nginx/sbin/nginx -v

  4. nginx version: nginx/1.2.9

  5. [root@E ~]# /www/wdlinux/httpd-2.2.24/bin/httpd -v

  6. Server version: Apache/2.2.24 (Unix)

  7. Server built: Oct 30 2014 00:17:07

  8. [root@E ~]# rpm -qa |grep mysql

  9. mysql-libs-5.1.66-2.el6_3.x86_64

  10. [root@E ~]# /www/wdlinux/php/bin/php -v

  11. Cannot load Zend Extension Manager - it was built with configuration 1.2.0, whereas running engine is API220090626,NTS

  12. PHP 5.3.27 (cli) (built: Oct 30 2014 00:30:02)

  13. Copyright (c) 1997-2013 The PHP Group

  14. Zend Engine v2.3.0, Copyright (c) 1998-2013 Zend Technologies


开始安装jdk: 列出yum库可用的jdk安装包

  1. [root@E ~]# yum -y list java*

  2. Loaded plugins: fastestmirror

  3. Loading mirror speeds from cached hostfile

  4. * base: mirror.bit.edu.cn

  5. * extras: mirror.bit.edu.cn

  6. * rpmforge: mirrors.neusoft.edu.cn

  7. * updates: mirrors.neusoft.edu.cn

  8. base | 3.7 kB 00:00

  9. extras | 3.3 kB 00:00

  10. rpmforge | 1.9 kB 00:00

  11. updates | 3.4 kB 00:00

  12. updates/primary_db | 171 kB 00:00

  13. Available Packages

  14. java-1.5.0-gcj.x86_64 1.5.0.0-29.1.el6 base

  15. java-1.5.0-gcj-devel.x86_64 1.5.0.0-29.1.el6 base

  16. java-1.5.0-gcj-javadoc.x86_64 1.5.0.0-29.1.el6 base

  17. java-1.5.0-gcj-src.x86_64 1.5.0.0-29.1.el6 base

  18. java-1.6.0-openjdk.x86_64 1:1.6.0.33-1.13.5.0.el6_6 updates

  19. java-1.6.0-openjdk-demo.x86_64 1:1.6.0.33-1.13.5.0.el6_6 updates

  20. java-1.6.0-openjdk-devel.x86_64 1:1.6.0.33-1.13.5.0.el6_6 updates

  21. java-1.6.0-openjdk-javadoc.x86_64 1:1.6.0.33-1.13.5.0.el6_6 updates

  22. java-1.6.0-openjdk-src.x86_64 1:1.6.0.33-1.13.5.0.el6_6 updates

  23. java-1.7.0-openjdk.x86_64 1:1.7.0.71-2.5.3.1.el6 updates

  24. java-1.7.0-openjdk-demo.x86_64 1:1.7.0.71-2.5.3.1.el6 updates

  25. java-1.7.0-openjdk-devel.x86_64 1:1.7.0.71-2.5.3.1.el6 updates

  26. java-1.7.0-openjdk-javadoc.noarch 1:1.7.0.71-2.5.3.1.el6 updates

  27. java-1.7.0-openjdk-src.x86_64 1:1.7.0.71-2.5.3.1.el6 updates

  28. java-1.8.0-openjdk.x86_64 1.8.0.25-1.b17.el6 updates

  29. java-1.8.0-openjdk-demo.x86_64 1.8.0.25-1.b17.el6 updates

  30. java-1.8.0-openjdk-devel.x86_64 1.8.0.25-1.b17.el6 updates

  31. java-1.8.0-openjdk-headless.x86_64 1.8.0.25-1.b17.el6 updates

  32. java-1.8.0-openjdk-javadoc.noarch 1.8.0.25-1.b17.el6 updates

  33. java-1.8.0-openjdk-src.x86_64 1.8.0.25-1.b17.el6 updates

  34. java_cup.x86_64 1:0.10k-5.el6 base

  35. java_cup-javadoc.x86_64 1:0.10k-5.el6 base

  36. java_cup-manual.x86_64 1:0.10k-5.el6 base

  37. javacc.x86_64 4.1-0.5.el6 base

  38. javacc-demo.x86_64 4.1-0.5.el6 base

  39. javacc-manual.x86_64 4.1-0.5.el6 base

  40. javassist.noarch 3.9.0-6.el6 base

  41. javassist-javadoc.noarch 3.9.0-6.el6 base

选择jdk1.6安装

  1. [root@E ~]# yum -y install java-1.6.0-openjdk*

其它版本请自己修改对应的版本号安装 检测是否安装成功

  1. [root@E ~]# java -version

  2. java version "1.6.0_33"

  3. OpenJDK Runtime Environment (IcedTea6 1.13.5) (rhel-1.13.5.0.el6_6-x86_64)

  4. OpenJDK 64-Bit Server VM (build 23.25-b01, mixed mode)

安装tomcat6 因为wdcp后台默认安装的端口是8080,tomcat默认端口也是8080为了避免冲突请提前把wdcp后台端口改为其它端口(如:8089...) 可以到wdcp后台系统设置中手动修改:

  1. [root@E ~]# yum install tomcat6 tomcat6-webapps tomcat6-admin-webapps

安装成功 启动

  1. [root@E ~]# service tomcat6 start

  2. 其它命令:service tomcat6 {start|stop|restart|condrestart|try-restart|reload|force-reload|status|version}

启动成功,访问测试:http://ip:8080 能访问即为安装成功: 配置nginx和tomcat,使其不加端口号,直接通过域名也能访问 首先增加解析,使域名指向到主机IP,本地可以直接改host实现 解析正常 不加8080端口访问 添加8080端口访问 接下来修改nginx和tomcat的配置使其不加端口号也能访问到tomcat的webservice

  1. [root@E ~]# cd /www/wdlinux/nginx/conf/vhost/

  2. [root@E ~]# vi myweb.com.conf

  3. 添加如下内容

  4. server {

  5. listen 80;

  6. server_name www.myweb.com myweb.com;

  7. #root /www/web/master_myweb_com/public_html;

  8. index index.html index.jsp index.htm;

  9. error_page 400 /errpage/400.html;

  10. error_page 403 /errpage/403.html;

  11. error_page 404 /errpage/404.html;

  12. error_page 405 /errpage/405.html;

  13. location ~ \.jsp$ {

  14. proxy_pass http://127.0.0.1:8080;

  15. include naproxy.conf;

  16. }

  17. location / {

  18. try_files $uri @tomcat;

  19. }

  20. location @tomcat {

  21. proxy_pass http://127.0.0.1:8080;

  22. include naproxy.conf;

  23. }

  24. access_log /www/web_logs/myweb_com_access.log wwwlogs;

  25. error_log /www/web_logs/myweb_com_error.log;

  26. }

重新加载nginx配置文件或重启nginx

  1. [root@E vhost]# service nginxd reload

  2. nginx: the configuration file /www/wdlinux/nginx/conf/nginx.conf syntax is ok

  3. nginx: configuration file /www/wdlinux/nginx/conf/nginx.conf test is successful

不加端口号访问测试: 至此nginx已经成功将来自myweb.com域名的请求代理到8080端口 如果需要配置多域名的话,还需要修改tomcat虚拟主机配置文件 默认配置文件路径:/etc/tomcat6/ 默认项目路径:/var/lib/tomcat6/webapps/ tomcat默认指向/var/lib/tomcat6/webapps/ROOT目录 创建新项目目录,这里直接复制ROOT项目,进行修改

  1. [root@E webapps]# pwd

  2. /var/lib/tomcat6/webapps

  3. [root@E webapps]# chown -R root myweb.com

  4. 修改权限,使新项目权限和默认项目权限一致

  5. [root@E webapps]# chgrp -R tomcat myweb.com

  6. [root@E webapps]# ll

  7. 总用量 24

  8. drwxrwxr-x 5 root tomcat 4096 10月 30 22:06 examples

  9. drwxrwxr-x 5 root tomcat 4096 10月 30 22:06 host-manager

  10. drwxrwxr-x 5 root tomcat 4096 10月 30 22:06 manager

  11. drwxr-xr-x 3 root tomcat 4096 10月 30 22:48 myweb.com

  12. drwxrwxr-x 3 root tomcat 4096 10月 30 22:06 ROOT

  13. drwxrwxr-x 5 root tomcat 4096 10月 30 22:06 sample

  14. [root@E myweb.com]# cd myweb.com/

  15. [root@E myweb.com]# rm -f index.html

  16. [root@E myweb.com]# vi index.jsp

  17. 写入:WebService is Tomcat

  18. 不要忘记删除ROOT项目或者对它重命,否则新项目不生效

  19. [root@E webapps]# mv ROOT/ ROOT.BAK

修改tomcat虚拟主机配置

  1. [root@E myweb.com]# vi /etc/tomcat6/server.xml

  2. 在最下面<Host></Host>标签后面添加如下内容

  3. <!--myweb.com host config-->

  4. <Host name="www.myweb.com" appBase="webapps"

  5. unpackWARs="true" autoDeploy="true"

  6. xmlValidation="false" xmlNamespaceAware="false">

  7. <Context path="/" reloadable="true" docBase="myweb.com"/>

  8. <Alias>myweb.com</Alias>

  9. <!-- SingleSignOn valve, share authentication between web applications

  10. Documentation at: /docs/config/valve.html -->

  11. <!--

  12. <Valve className="org.apache.catalina.authenticator.SingleSignOn" />

  13. -->

  14. <!-- Access log processes all example.

  15. Documentation at: /docs/config/valve.html -->

  16. <!--

  17. <Valve className="org.apache.catalina.valves.AccessLogValve" directory="logs"

  18. prefix="localhost_access_log." suffix=".txt" pattern="common" resolveHosts="false"/>

  19. -->

  20. </Host>

重启tomcat,测试 [root@E myweb.com]# service tomcat6 restart success!

0
投稿

猜你喜欢

手机版 网络编程 asp之家 www.aspxhome.com