免费注册 查看新帖 |

Chinaunix

  平台 论坛 博客 文库
最近访问板块 发新帖
查看: 1797 | 回复: 0
打印 上一主题 下一主题

apache+php+tomcat+mysql整合 [复制链接]

论坛徽章:
0
跳转到指定楼层
1 [收藏(0)] [报告]
发表于 2009-12-08 16:00 |只看该作者 |倒序浏览
apache+php+tomcat+mysql整合
系统软件环境:
Linux 2.6.9-89.ELsmp
apr-1.1.1.tar.tar
apr-util-1.1.2.tar.tar
httpd-2.2.6.tar.tar
jakarta-tomcat-connectors-jk2-src-current.tar.tar
jakarta-tomcat-5.0.30.tar.gz
jdk-1_5_0_11-linux-i586-rpm.bin
mysql-5.0.20a
php-5.2.5
强烈建议停掉系统默认自带的mysql
[root@localhost ~]# df -h
Filesystem            Size  Used Avail Use% Mounted on
/dev/mapper/vg00-lvroot
                      3.9G  3.2G  527M  86% /
/dev/sda1              99M   14M   81M  15% /boot
none                  147M     0  147M   0% /dev/shm
/dev/mapper/vg00-lvapp
                      4.8G   42M  4.5G   1% /webapp
一 、安装步骤
1、安装mysql-5.0.20a
[root@jieli software]# pwd
/webapp/software
[root@jieli software]# tar -zxvf mysql5.0.tar.gz
./mysql-5.0.20a/cmd-line-utils/libedit/hist.h
./mysql-5.0.20a/cmd-line-utils/libedit/refresh.c
./mysql-5.0.20a/cmd-line-utils/libedit/tokenizer.c
[root@jieli software]# cd mysql-5.0.20a/
[root@jieli mysql-5.0.20a]# ./configure --prefix=/webapp/db/mysql --sysconfdir=/etc --localstatedir=/var/lib/mysql --with--charset=gbk --with-extra-charsets="gbk gb2312 big5 utf8" --with-unix-socket-path=/etc/mysql.sock
Remember to check the platform specific part of the reference manual for
hints about installing MySQL on your platform. Also have a look at the
files in the Docs directory.

Thank you for choosing MySQL!
[root@jieli mysql-5.0.20a]# make
make[3]: Leaving directory `/webapp/software/mysql-5.0.20a/server-tools'
make[2]: Leaving directory `/webapp/software/mysql-5.0.20a/server-tools'
make[1]: Leaving directory `/webapp/software/mysql-5.0.20a'
[root@jieli mysql-5.0.20a]# make install
make[4]: Leaving directory `/webapp/software/mysql-5.0.20a/server-tools'
make[3]: Leaving directory `/webapp/software/mysql-5.0.20a/server-tools'
make[2]: Leaving directory `/webapp/software/mysql-5.0.20a/server-tools'
make[1]: Leaving directory `/webapp/software/mysql-5.0.20a'
[root@jieli mysql]# cd /webapp/db/mysql/bin/
[root@jieli bin]# ./mysql_install_db                    ------必须执行这个来生成基本数据库
Installing all prepared tables
Fill help tables

To start mysqld at boot time you have to copy support-files/mysql.server
to the right place for your system

PLEASE REMEMBER TO SET A PASSWORD FOR THE MySQL root USER !
To do so, start the server, then issue the following commands:
/webapp/db/mysql/bin/mysqladmin -u root password 'new-password'
/webapp/db/mysql/bin/mysqladmin -u root -h jieli password 'new-password'
See the manual for more instructions.

You can start the MySQL daemon with:
cd /webapp/db/mysql ; /webapp/db/mysql/bin/mysqld_safe &

You can test the MySQL daemon with the benchmarks in the 'sql-bench' directory:
cd sql-bench ; perl run-all-tests

Please report any problems with the /webapp/db/mysql/bin/mysqlbug script!

The latest information about MySQL is available on the web at
http://www.mysql.com
Support MySQL by buying support/licenses at
https://order.mysql.com
[root@jieli bin]# ./mysqld_safe --user=root &
[1] 29019
[root@jieli bin]# Starting mysqld daemon with databases from /var/lib/mysql
[root@jieli bin]# ps -ef|grep mysql
root     29019  7279  0 21:15 pts/1    00:00:00 /bin/sh ./mysqld_safe --user=root
root     29037 29019  0 21:15 pts/1    00:00:00 /webapp/db/mysql/libexec/mysqld --basedir=/webapp/db/mysql --datadir=/var/lib/mysql --user=root --pid-file=/var/lib/mysql/jieli.pid --skip-locking
root     29047  7279  0 21:16 pts/1    00:00:00 grep mysql
[root@jieli bin]# ./mysqladmin -u root password '123456'           ----默认root是没有密码的,这里先设置root的密码
[root@jieli etc]# pwd
/etc
[root@jieli etc]# vi ld.so.conf
include ld.so.conf.d/*.conf
/webapp/db/mysql/lib/mysql/            ----添加这一行,把mysql的动态库的路径加入到系统中,其他的程序就可以使用mysql的动态库
[root@jieli etc]# ldconfig
[root@jieli etc]# cd /webapp/db/mysql/share/mysql/
[root@jieli mysql]# cp my-medium.cnf /etc/my.cnf
设置mysqld开机自启动
[root@jieli mysql]# pwd
/webapp/db/mysql/share/mysql
[root@jieli mysql]# cp mysql.server /etc/init.d/mysqld
[root@jieli mysql]# chkconfig --add mysqld
[root@jieli mysql]# chkconfig --level 2345 mysqld on
查看mysql的字符集
mysql> show character set;
+----------+-----------------------------+---------------------+--------+
| Charset  | Description                 | Default collation   | Maxlen |
+----------+-----------------------------+---------------------+--------+
| big5     | Big5 Traditional Chinese    | big5_chinese_ci     | 2      |
| dec8     | DEC West European           | dec8_swedish_ci     | 1      |
| cp850    | DOS West European           | cp850_general_ci    | 1      |
| hp8      | HP West European            | hp8_english_ci      | 1      |
| koi8r    | KOI8-R Relcom Russian       | koi8r_general_ci    | 1      |
| latin1   | cp1252 West European        | latin1_swedish_ci   | 1      |
| latin2   | ISO 8859-2 Central European | latin2_general_ci   | 1      |
| swe7     | 7bit Swedish                | swe7_swedish_ci     | 1      |
| ascii    | US ASCII                    | ascii_general_ci    | 1      |
| hebrew   | ISO 8859-8 Hebrew           | hebrew_general_ci   | 1      |
| koi8u    | KOI8-U Ukrainian            | koi8u_general_ci    | 1      |
| gb2312   | GB2312 Simplified Chinese   | gb2312_chinese_ci   | 2      |
| greek    | ISO 8859-7 Greek            | greek_general_ci    | 1      |
| cp1250   | Windows Central European    | cp1250_general_ci   | 1      |
| gbk      | GBK Simplified Chinese      | gbk_chinese_ci      | 2      |
| latin5   | ISO 8859-9 Turkish          | latin5_turkish_ci   | 1      |
| armscii8 | ARMSCII-8 Armenian          | armscii8_general_ci | 1      |
| utf8     | UTF-8 Unicode               | utf8_general_ci     | 3      |
| cp866    | DOS Russian                 | cp866_general_ci    | 1      |
| keybcs2  | DOS Kamenicky Czech-Slovak  | keybcs2_general_ci  | 1      |
| macce    | Mac Central European        | macce_general_ci    | 1      |
| macroman | Mac West European           | macroman_general_ci | 1      |
| cp852    | DOS Central European        | cp852_general_ci    | 1      |
| latin7   | ISO 8859-13 Baltic          | latin7_general_ci   | 1      |
| cp1251   | Windows Cyrillic            | cp1251_general_ci   | 1      |
| cp1256   | Windows Arabic              | cp1256_general_ci   | 1      |
| cp1257   | Windows Baltic              | cp1257_general_ci   | 1      |
| binary   | Binary pseudo charset       | binary              | 1      |
| geostd8  | GEOSTD8 Georgian            | geostd8_general_ci  | 1      |
+----------+-----------------------------+---------------------+--------+
29 rows in set (0.00 sec)
2、安装jdk-1_5_0_11
[root@jieli software]# chmod +x jdk-1_5_0_11-linux-i586-rpm.bin
。。。。。。。。
[root@jieli software]# ./jdk-1_5_0_11-linux-i586-rpm.bin
Do you agree to the above license terms? [yes or no]
yes
。。。。。。。。
UnZipSFX 5.42 of 14 January 2001, by Info-ZIP (
Zip-Bugs@lists.wku.edu
).
  inflating: jdk-1_5_0_11-linux-i586.rpm  
Preparing...                ########################################### [100%]
   1:jdk                    ########################################### [100%]

Done.
[root@jieli jdk1.5.0_11]# cp /etc/profile /etc/profile-bak
[root@jieli jdk1.5.0_11]#vi /etc/profile
JAVA_HOME=/usr/java/jdk1.5.0_11
JRE_HOME=$JAVA_HOME/jre
RESIN_HOME=/webapp/db/resin
CLASSPATH=.:../$JAVA_HME/lib:$JAVA_HOME/jre/lib:$RESIN_HOME/lib:/webapp/db/jdbc
PATH=$JAVA_HOME/bin:$JRE_HOME/bin:$PATH:$HOME/bin
export JAVA_HOME JRE_HOME RESIN_HOME CLASSPATH PATH
"/etc/profile" 63L, 1195C written
[root@jieli jdk1.5.0_11]# source /etc/profile
[root@jieli jdk1.5.0_11]# java -version
java version "1.5.0_11"
Java(TM) 2 Runtime Environment, Standard Edition (build 1.5.0_11-b03)
Java HotSpot(TM) Client VM (build 1.5.0_11-b03, mixed mode, sharing)
3、安装mysql-connector-java(在这里安装不安装无所谓)
[root@jieli software]# tar -zxvf mysql-connector-java-5.0.8.tar.tar
[root@jieli software]# mv mysql-connector-java-5.0.8 /webapp/db/
[root@jieli db]# pwd
/webapp/db
[root@jieli db]# ln -s mysql-connector-java-5.0.8/ jdbc
4、安装http-2.2.6
[root@jieli software]# tar -zxvf httpd-2.2.6.tar.gz
httpd-2.2.6/test/test_select.c
httpd-2.2.6/test/time-sem.c
httpd-2.2.6/test/zb.c
httpd-2.2.6/VERSIONING
[root@jieli httpd-2.2.6]# ./configure --prefix=/webapp/www/apache --enable-so
config.status: creating build/config_vars.sh
config.status: creating include/ap_config_auto.h
config.status: executing default commands
[root@jieli httpd-2.2.6]# make
as.la modules/mappers/libmod_so.la server/mpm/prefork/libprefork.la os/unix/libos.la -lm /webapp/software/httpd-2.2.6/srclib/pcre/libpcre.la /webapp/software/httpd-2.2.6/srclib/apr-util/libaprutil-1.la -lexpat /webapp/software/httpd-2.2.6/srclib/apr/libapr-1.la -luuid -lrt -lcrypt -lpthread -ldl
make[1]: Leaving directory `/webapp/software/httpd-2.2.6'
[root@jieli httpd-2.2.6]# make install
mkdir /webapp/www/apache/man
mkdir /webapp/www/apache/man/man1
mkdir /webapp/www/apache/man/man8
mkdir /webapp/www/apache/manual
make[1]: Leaving directory `/webapp/software/httpd-2.2.6'
设置httpd开机自启
[root@jieli init.d]# cp httpd httpd-bak
[root@jieli init.d]# cd /webapp/www/apache/bin/
[root@jieli bin]# cp apachectl /etc/init.d/httpd
cp: overwrite `/etc/init.d/httpd'? y
[root@jieli bin]# cd /etc/rc3.d
[root@jieli rc3.d]# ln -s /etc/init.d/httpd S85httpd
[root@jieli rc3.d]# ln -s /etc/init.d/httpd K85httpd
[root@jieli etc]# cd rc5.d
[root@jieli rc5.d]# ln -s /etc/init.d/httpd S85httpd
[root@jieli rc5.d]# ln -s /etc/init.d/httpd K85httpd
[root@jieli rc5.d]# cd /webapp/www/apache/bin/
[root@jieli bin]# ps -ef|grep httpd
root     16488  7279  0 21:37 pts/1    00:00:00 grep httpd
[root@jieli bin]# ./apachectl start
[root@jieli bin]# ps -ef|grep httpd
root     16695     1  0 21:37 ?        00:00:00 /webapp/www/apache/bin/httpd -k start
daemon   16696 16695  0 21:37 ?        00:00:00 /webapp/www/apache/bin/httpd -k start
daemon   16697 16695  0 21:37 ?        00:00:00 /webapp/www/apache/bin/httpd -k start
daemon   16698 16695  0 21:37 ?        00:00:00 /webapp/www/apache/bin/httpd -k start
daemon   16699 16695  0 21:37 ?        00:00:00 /webapp/www/apache/bin/httpd -k start
daemon   16700 16695  0 21:37 ?        00:00:00 /webapp/www/apache/bin/httpd -k start
root     16887  7279  0 21:37 pts/1    00:00:00 grep httpd
[root@jieli bin]# ./httpd -l
Compiled in modules:
。。。。
http_core.c
mod_so.c
。。。。
看到以上的信息表明apache支持DSO方式了。这样就可以用DSO的方式把php和resin的模块加进来
5、安装php-5.2.5
[root@jieli software]# tar -xvf php-5.2.5.tar
php-5.2.5/README.UPDATE_5_2
php-5.2.5/README.UNIX-BUILD-SYSTEM
php-5.2.5/buildconf.bat
[root@jieli php-5.2.5]# ./configure --prefix=/webapp/www/php --with-apxs2=/webapp/www/apache/bin/apxs --with-config-file-path=/webapp/www/php --enable-sockets --with-mysql=/webapp/db/mysql/ --with-pdo-mysql=/webapp/db/mysql/ --with-jpeg-dir=/usr/local/lib --with-png-dir=/usr/lib --with-gd  --with-zlib --enable-gd-native-ttf --with-bz2  --enable-sysvsem --enable-sysvshm --enable-discard-path  --enable-mbstring=all --enable-magic-quotes --with-xmlrpc=shared --with-iconv --enable-calendar --with-freetype-dir=/webapp/www/freetype --enable-zip --with-openssl --with-gettext --disable-debug --disable-rpath --with-curl --with-libxml-dir=/usr/include/libxml2/libxml
+--------------------------------------------------------------------+
| License:                                                           |
| This software is subject to the PHP License, available in this     |
| distribution in the file LICENSE.  By continuing this installation |
| process, you are bound by the terms of this license agreement.     |
| If you do not agree with the terms of this license, you must abort |
| the installation process at this point.                            |
+--------------------------------------------------------------------+

Thank you for using PHP.
[root@jieli php-5.2.5]# make
e.lo sapi/cli/getopt.lo main/internal_functions_cli.lo -lcrypt -lcrypt -lrt -lmysqlclient -lresolv -lm -ldl -lnsl -lxml2 -lz -lm -lxml2 -lz -lm -lxml2 -lz -lm -lcrypt -lxml2 -lz -lm -lxml2 -lz -lm -lxml2 -lz -lm -lcrypt  -o sapi/cli/php

Build complete.
Don't forget to run 'make test'.
[root@jieli php-5.2.5]# make test
TIME END 2009-11-26 19:43:32

=====================================================================
TEST RESULT SUMMARY
---------------------------------------------------------------------
Exts skipped    :   42
Exts tested     :   37
---------------------------------------------------------------------

Number of tests : 4616              3236
Tests skipped   : 1380 ( 29.9%) --------
Tests warned    :    3 (  0.1%) (  0.1%)
Tests failed    :    6 (  0.1%) (  0.2%)
Tests passed    : 3227 ( 69.9%) ( 99.7%)
---------------------------------------------------------------------
Time taken      :  242 seconds
=====================================================================


[root@jieli php-5.2.5]# make install
pear/PEAR can optionally use package "pear/XML_RPC" (version >= 1.4.0)
[PEAR] PEAR           - installed: 1.6.1
Wrote PEAR system config file at: /webapp/www/php/etc/pear.conf
You may want to add: /webapp/www/php/lib/php to your php.ini include_path
Installing PDO headers:          /webapp/www/php/include/php/ext/pdo/
[root@jieli php-5.2.5]# cp php.ini-dist /webapp/www/php/php.ini
[root@jieli php]# cp php.ini php.ini-bak
[root@jieli php]# vi php.ini
; Default socket name for local MySQL connects.  If empty, uses the built-in
; MySQL defaults.
mysql.default_socket =/tmp/mysql.sock
mysql.sock =/tmp/mysql.sock
。。。。
; to possible security problems, if the code is not very well thought of.
register_globals = On    ---修改成On,默认是off,否则会出现php不能直接读到post或get的数据的现象
最下面添加
zend_optimizer.optimization_level=7
zend_extension="/webapp/www/zend/data/5_2_x_comp/ZendOptimizer.so"
[root@jieli php]# cd /webapp/www/apache/conf/
[root@jieli conf]# cp httpd.conf httpd.conf-bak
[root@jieli conf]# vi httpd.conf
    DirectoryIndex index.php index.html
..............................
AddType application/x-tar .tgz
AddType application/x-httpd-php .php
AddType image/x-icon .ico
[root@jieli bin]# ./apachectl restart
[root@jieli htdocs]# vi test.php

   
~
[root@jieli htdocs]# vi mysqltest.html

         
            

         
             Host
             User
             Password
         

         
            
            
            
         
            
         
      
6、安装jakarta-tomcat-5.0.30
[root@jieli www]# tar -zxvf jakarta-tomcat-5.0.30.tar.gz
[root@jieli bin]# ./startup.sh
Using CATALINA_BASE:   /webapp/www/jakarta-tomcat-5.0.30
Using CATALINA_HOME:   /webapp/www/jakarta-tomcat-5.0.30
Using CATALINA_TMPDIR: /webapp/www/jakarta-tomcat-5.0.30/temp
Using JAVA_HOME:       /usr/java/jdk1.5.0_11
[root@jieli bin]# ps -ef|grep tomcat
root     20693     1 42 19:27 pts/2    00:00:02 /usr/java/jdk1.5.0_11/bin/java -Djava.endorsed.dirs=/webapp/www/jakarta-tomcat-5.0.30/common/endorsed -
classpath /usr/java/jdk1.5.0_11/lib/tools.jar:/webapp/www/jakarta-tomcat-5.0.30/bin/bootstrap.jar:/webapp/www/jakarta-tomcat-5.0.30/bin/commons-logging-
api.jar -Dcatalina.base=/webapp/www/jakarta-tomcat-5.0.30 -Dcatalina.home=/webapp/www/jakarta-tomcat-5.0.30 -Djava.io.tmpdir=/webapp/www/jakarta-tomcat-
5.0.30/temp org.apache.catalina.startup.Bootstrap start
浏览器中打入
http://172.16.11.86:8080/
,如果看到tomcat的欢迎画面,表示安装成功.见图1
7、安装apr-1.1.1
[root@jieli software]# mv apr-1.1.1.tar.tar /webapp/www/
[root@jieli www]# tar -zxvf apr-1.1.1.tar.tar
[root@jieli apr-1.1.1]# ./configure
config.status: creating apr.pc
config.status: creating include/arch/unix/apr_private.h
config.status: executing default commands
[root@jieli apr-1.1.1]# make
-I/webapp/www/apr-1.1.1/include  export_vars.c | sed -e 's/^\#[^!]*//' | sed -e '/^$/d' >> apr.exp
make[1]: Leaving directory `/webapp/www/apr-1.1.1'
[root@jieli apr-1.1.1]# make install
/usr/bin/install -c -m 644 build/apr_rules.out /usr/local/apr/build-1/apr_rules.mk
/usr/bin/install -c -m 755 apr-config.out /usr/local/apr/bin/apr-1-config
8、安装apr-util-1.1.2
[root@jieli software]# mv apr-util-1.1.2.tar.tar /webapp/www/
[root@jieli www]# tar -zxvf apr-util-1.1.2.tar.tar
apr-util-1.1.2/buildconf
apr-util-1.1.2/build-outputs.mk
apr-util-1.1.2/libaprutil.rc
[root@jieli apr-util-1.1.2]# ./configure --with-apr=/usr/local/apr/
config.status: creating test/Makefile
config.status: creating include/private/apu_config.h
config.status: executing default commands
[root@jieli apr-util-1.1.2]# make
ivate  -I/usr/local/apr/include/apr-1    export_vars.c | sed -e 's/^\#[^!]*//' | sed -e '/^$/d' >> aprutil.exp
make[1]: Leaving directory `/webapp/www/apr-util-1.1.2'
[root@jieli apr-util-1.1.2]# make install
/usr/bin/install -c -m 644 aprutil.exp /usr/local/apr/lib
/usr/bin/install -c -m 755 apu-config.out /usr/local/apr/bin/apu-1-config
9、安装jk2(这里最复杂,若出现问题,请参考"整合apache+tomcat"这篇文章)
[root@jieli software]# mv jakarta-tomcat-connectors-jk2-src-current.tar.tar /webapp/www/
[root@jieli www]# tar -zxvf jakarta-tomcat-connectors-jk2-src-current.tar.tar
[root@jieli native2]# ./configure --with-apxs2=/webapp/www/apache/bin/apxs
config.status: creating ../build.properties
config.status: creating scripts/build/unix/dummy
config.status: executing depfiles commands
[root@jieli native2]# make
/bin/cp ../../../build/jk2/apache2//webapp/www/apache/modules/mod_jk2.so ../../../build/jk2/apache2/mod_jk2.so
make[1]: Leaving directory `/webapp/www/jakarta-tomcat-connectors-jk2-2.0.4-src/jk/native2/server/apache2'
[root@jieli apache2]# pwd
/webapp/www/jakarta-tomcat-connectors-jk2-2.0.4-src/jk/build/jk2/apache2
[root@jieli apache2]# cp mod_jk2.so /webapp/www/apache/modules/         ---一定要做这步,否则后面apache是无法启动的
10、配置,整合apache,tomcat
[root@jieli conf]# vi httpd.conf
第一块
DocumentRoot "/webapp/www/apache/htdocs"

#
# Each directory to which Apache has access can be configured with respect
# to which services and features are allowed and/or disabled in that
# directory (and its subdirectories).
#
# First, we configure the "default" to be a very restrictive set of
# features.
#
    Options FollowSymLinks
    AllowOverride None
    Order deny,allow               
    Allow from all                   ----这里默认的deny改成Allow
第二块
    Options Indexes FollowSymLinks

    #
    # AllowOverride controls what directives may be placed in .htaccess files.
    # It can be "All", "None", or any combination of the keywords:
    #   Options FileInfo AuthConfig Limit
    #
    AllowOverride None

    #
    # Controls who can get stuff from this server.
    #
    Order allow,deny
    Allow from all
    XBitHack on                   ----这里增加一条这个
第三块
# Example:
# LoadModule foo_module modules/mod_foo.so
LoadModule php5_module        modules/libphp5.so
#LoadModule php4_module        modules/libphp4.so
LoadModule jk2_module modules/mod_jk2.so                ----这里增加一条这个
第四块
#
    DirectoryIndex index.php index.html index.jsp       ----这里添加一个index.jsp,默认是没有的
[root@jieli conf]# pwd
/webapp/www/apache/conf
[root@jieli conf]# vi workers2.properties
#---- worker2.properties
[logger.apache2]
level=DEBUG               

# Shared memory handling. Needs to be set.
[shm]
file=/webapp/www/apache/logs/shm.file   
size=1048576              

# Example socket channel, explicitly set port and host.
[channel.socket:localhost:8009]
tomcatId=localhost:8009
port=8009
host=127.0.0.1

# define the worker
[ajp13:localhost:8009]
channel=channel.socket:localhost:8009

#[status:status]
# Uri mapping

#[uri:/jkstatus/*]
#group=status:status

#[uri:/jsp-examples/*]
#group=ajp13:localhost:8009

#[uri:/servlets-examples/*]
#group=ajp13:localhost:8009

#[uri:/javaapp/*]
#group=ajp13:localhost:8009

#[uri:www.home.net/*.jsp]
#worker=ajp13:localhost:8009
#[uri:10.0.0.10/*]
#worker=ajp13:localhost:8009

#[uri:/*.do]
#worker=ajp13:localhost:8009

[uri:/servlet/*]                                   ---这里的意思是当apache遇到servlet请求时,将该文件解释工作转交给tomcat        
worker=ajp13:localhost:8009

[uri:/*.jsp]                                       ---这里的意思是当apache遇到jsp请求时,将该文件解释工作转交给tomcat      
worker=ajp13:localhost:8009
#---- end of workers2.properties
[root@jieli conf]# cp server.xml server.xml-bak
[root@jieli conf]# vi server.xml
-->
      
                                        ---修改成这样,docBase目录替换成实际的web根目录

        
11、创建JSP,php,html测试文档
[root@jieli htdocs]# pwd
/webapp/www/apache/htdocs
[root@jieli htdocs]# more aa.jsp
[root@jieli htdocs]# more tianyu.jsp
2 + 2 =
[root@jieli htdocs]# more jiajia.php

[root@jieli htdocs]# more mysqltest.html
         
            

         
             Host
             User
             Password
         

         
            
            
            
         
            
         
      
[root@jieli htdocs]# more testdb.jsp
  
  Test JDBC For MySQL
  
  
  
  
  
  
再从网上下一个jspcheck.jsp的探针
12、测试
先启动httpd,这个时候不启动tomcat
[root@jieli bin]# ./apachectl start
[root@jieli bin]# ps -ef|grep httpd
root     20933     1  0 20:10 ?        00:00:00 /webapp/www/apache/bin/httpd -k start
daemon   20934 20933  0 20:10 ?        00:00:00 /webapp/www/apache/bin/httpd -k start
daemon   20935 20933  0 20:10 ?        00:00:00 /webapp/www/apache/bin/httpd -k start
daemon   20936 20933  0 20:10 ?        00:00:00 /webapp/www/apache/bin/httpd -k start
daemon   20937 20933  0 20:10 ?        00:00:00 /webapp/www/apache/bin/httpd -k start
daemon   20938 20933  0 20:10 ?        00:00:00 /webapp/www/apache/bin/httpd -k start
root     20942 19399  0 20:10 pts/2    00:00:00 grep httpd
使用
http://172.16.11.64

http://172.16.11.64/jiajia.php

http://172.16.11.64/aa.jsp
进行访问,这个时候因为tomcat没启动,所以无法解析jsp代码
见如下几图


再启动tomcat
[root@jieli bin]# ./startup.sh
Using CATALINA_BASE:   /webapp/www/jakarta-tomcat-5.0.30
Using CATALINA_HOME:   /webapp/www/jakarta-tomcat-5.0.30
Using CATALINA_TMPDIR: /webapp/www/jakarta-tomcat-5.0.30/temp
Using JAVA_HOME:       /usr/java/jdk1.5.0_11
[root@jieli bin]# ps -ef|grep tomcat
root     20955     1 45 20:14 pts/2    00:00:02 /usr/java/jdk1.5.0_11/bin/java -Djava.endorsed.dirs=/webapp/www/jakarta-tomcat-5.0.30/common/endorsed -
classpath /usr/java/jdk1.5.0_11/lib/tools.jar:/webapp/www/jakarta-tomcat-5.0.30/bin/bootstrap.jar:/webapp/www/jakarta-tomcat-5.0.30/bin/commons-logging-
api.jar -Dcatalina.base=/webapp/www/jakarta-tomcat-5.0.30 -Dcatalina.home=/webapp/www/jakarta-tomcat-5.0.30 -Djava.io.tmpdir=/webapp/www/jakarta-tomcat-
5.0.30/temp org.apache.catalina.startup.Bootstrap start
root     20996 19399  0 20:14 pts/2    00:00:00 grep tomcat
使用
http://172.16.11.64

http://172.16.11.64/jiajia.php
进行访问,成功,见上面图
使用
http://172.16.11.64/aa.jsp

http://172.16.11.64/tianyu.jsp
,见下图

使用
http://172.16.11.64/jspcheck.jsp
,见下图
使用
http://172.16.11.64/testdb.jsp
,报如下错
HTTP Status 500 -
--------------------------------------------------------------------------------
type Exception report
message
description The server encountered an internal error () that prevented it from fulfilling this request.  ---服务器遇到内部错误(),它无法实现这一请求
exception
org.apache.jasper.JasperException: Unable to compile class for JSP
An error occurred at line: 7 in the jsp file: /testdb.jsp
Generated servlet error:
/webapp/www/jakarta-tomcat-5.0.30/work/Catalina/localhost/_/org/apache/jsp/testdb_jsp.java:50: illegal character: \12288     ---说明代码中有非法字符
?????? Class.forName???"com.mysql.jdbc.Driver"???.newInstance?????????
上面的问题解决需要对代码进行修改,修改后的如下,一定要注意在英文输入法下写进去,并且注意大小写,还有分号,括号,百分号之类的东西
[root@jieli htdocs]# more testdb.jsp
Test JDBC For MySQL
之后再来访问
http://172.16.11.64/testdb.jsp
报如下错,是由于找不到mysql驱动导致
处理方法如下
先进入到连接mysql驱动的位置
[root@jieli bin]# cd /webapp/db/jdbc/
[root@jieli jdbc]# ls
CHANGES  COPYING  EXCEPTIONS-CONNECTOR-J  README  README.txt  build.xml  debug  docs  mysql-connector-java-5.0.8-bin.jar  src
将驱动拷贝到tomcat的相关目录下
[root@jieli jdbc]# cp mysql-connector-java-5.0.8-bin.jar /webapp/www/jakarta-tomcat-5.0.30/common/lib/
[root@jieli lib]# ls
ant-launcher.jar             commons-dbcp-1.2.1.jar  jasper-compiler.jar  mysql-connector-java-5.0.8-bin.jar  naming-java.jar
ant.jar                      commons-el.jar          jasper-runtime.jar   naming-common.jar                   naming-resources.jar
commons-collections-3.1.jar  commons-pool-1.2.jar    jsp-api.jar          naming-factory.jar                  servlet-api.jar
然后重启动tomcat
[root@jieli bin]# ./shutdown.sh
Using CATALINA_BASE:   /webapp/www/jakarta-tomcat-5.0.30
Using CATALINA_HOME:   /webapp/www/jakarta-tomcat-5.0.30
Using CATALINA_TMPDIR: /webapp/www/jakarta-tomcat-5.0.30/temp
Using JAVA_HOME:       /usr/java/jdk1.5.0_11
[root@jieli bin]# ./startup.sh
Using CATALINA_BASE:   /webapp/www/jakarta-tomcat-5.0.30
Using CATALINA_HOME:   /webapp/www/jakarta-tomcat-5.0.30
Using CATALINA_TMPDIR: /webapp/www/jakarta-tomcat-5.0.30/temp
Using JAVA_HOME:       /usr/java/jdk1.5.0_11
之后再来访问
http://172.16.11.64/testdb.jsp
,如果看到了一个没有任何错误信息的空白页面,就表示jsp连接本机的MySQL数据库成功了
当初也不知道要将连mysql的驱动拷贝到/webapp/www/jakarta-tomcat-5.0.30/common/lib/目录下,也是通过一边浏览器访问,一边看tomcat里的catalina.out日志输出,发现在访问报错的过程中,出现很多"cp="这样的段,所以猜测可能就是拷贝过去,没想到居然是对的,成功了
[root@jieli logs]# pwd
/webapp/www/jakarta-tomcat-5.0.30/logs
[root@jieli logs]# ls
catalina.out  localhost_log.2009-11-19.txt
13、扩展测试
网上书店系统
输入
http://172.16.11.64/shudian
后出现如下错误提示
HTTP Status 500 -
--------------------------------------------------------------------------------
type Exception report
message
description The server encountered an internal error () that prevented it from fulfilling this request.
exception
org.apache.jasper.JasperException: /shudian/index.jsp(2,0) The absolute uri:
http://java.sun.com/jsp/jstl/core
cannot be resolved in either web.xml or the jar files deployed with this application
org.apache.jasper.compiler.DefaultErrorHandler.jspError(DefaultErrorHandler.java:39)
org.apache.jasper.compiler.ErrorDispatcher.dispatch(ErrorDispatcher.java:409)
org.apache.jasper.compiler.ErrorDispatcher.jspError(ErrorDispatcher.java:90)
org.apache.jasper.compiler.Parser.processIncludeDirective(Parser.java:339)
org.apache.jasper.compiler.Parser.parseIncludeDirective(Parser.java:372)
这是由于jstl.jar文件无法解析web.xml
[root@jieli lib]# pwd
/webapp/www/apache/htdocs/shudian/WEB-INF/lib
[root@jieli lib]# ls
jstl.jar  mysql-connector-java-5.0.4-bin.jar  pager-taglib.jar  standard.jar
将这里的jstl.jar pager-taglib.jar  standard.jar 3个文件copy到/webapp/www/jakarta-tomcat-5.0.30/common/lib目录下,然后
http://172.16.11.64/shudian
就可以访问主页了,如下图
但是这个时候仍然不能注册使用
重新编辑/webapp/www/apache/htdocs/shudian/WEB-INF/classes/com/lovo/cq/shoppingbook/common下的DbUtil.class(之前最好先备份)
[root@jieli ~]# cd /webapp/www/apache/htdocs/shudian/WEB-INF/sql
[root@jieli sql]# /webapp/db/mysql/bin/mysql -u root -p123456



使用mysql连接客户端去连接mysql时出现如下问题:
1、
我用mysql的连接工具使用jesonc用户去连shopping10_1时,总报错:Access denied for user
[email='jesonc'@'172.16.10.50']'jesonc'@'172.16.10.50'[/email]
(using password:YES).而实际上用户名密码都是正确的,172.16.10.50是我自己电脑的IP,数据库所在服务器IP为172.16.11.64
处理方法:
该报错是由于没有授权导致,查看授权表,发现确实没有授权
mysql> select user,host,password from mysql.user;
+-------------+--------------+-------------------------------------------+
| user        | host         | password                                  |
+-------------+--------------+-------------------------------------------+
| root        | localhost    | *6BB4837EB74329105EE4568DDA7DC67ED2CA2AD9 |
| root        | jieli        | *6BB4837EB74329105EE4568DDA7DC67ED2CA2AD9 |
|             | jieli        |                                           |
|             | localhost    |                                           |
| photo       | localhost    | *6BB4837EB74329105EE4568DDA7DC67ED2CA2AD9 |
| linpha_n6BS | localhost    | *A16C1753D1EAC01916D1593CE31130245BC87B9E |
| jiajia      | localhost    | *6BB4837EB74329105EE4568DDA7DC67ED2CA2AD9 |
| root        | 172.16.11.64 | *6BB4837EB74329105EE4568DDA7DC67ED2CA2AD9 |
+-------------+--------------+-------------------------------------------+
对其进行授权
[root@jieli bin]# ./mysql -u root -p123456
Welcome to the MySQL monitor.  Commands end with ; or \g.
Your MySQL connection id is 18 to server version: 5.0.20a-log

Type 'help;' or '\h' for help. Type '\c' to clear the buffer.

mysql> grant all on shopping10_1.* to jesonc;
Query OK, 0 rows affected (0.00 sec)

mysql> grant all on shopping10_1.* to
jesonc@172.16.10.50
;
Query OK, 0 rows affected (0.00 sec)

mysql> grant all on shopping10_1.* to
jesonc@172.16.10.50
identified by '123456';
Query OK, 0 rows affected (0.00 sec)

mysql> flush privileges;
Query OK, 0 rows affected (0.00 sec)

mysql> quit
[root@jieli bin]# useradd jesonc
[root@jieli bin]# passwd jesonc
Changing password for user jesonc.
New UNIX password:                                   ----密码和上面一样
BAD PASSWORD: it is too simplistic/systematic
Retype new UNIX password:
passwd: all authentication tokens updated successfully.
再来查看已经对jesonc用户通过172.16.10.50来连接授权
mysql> select user,host,password from mysql.user;
+-------------+--------------+-------------------------------------------+
| user        | host         | password                                  |
+-------------+--------------+-------------------------------------------+
| root        | localhost    | *6BB4837EB74329105EE4568DDA7DC67ED2CA2AD9 |
| root        | jieli        | *6BB4837EB74329105EE4568DDA7DC67ED2CA2AD9 |
|             | jieli        |                                           |
|             | localhost    |                                           |
| jesonc      | %            |                                           |
| photo       | localhost    | *6BB4837EB74329105EE4568DDA7DC67ED2CA2AD9 |
| linpha_n6BS | localhost    | *A16C1753D1EAC01916D1593CE31130245BC87B9E |
| jesonc      | 172.16.10.50 | *6BB4837EB74329105EE4568DDA7DC67ED2CA2AD9 |
| jiajia      | localhost    | *6BB4837EB74329105EE4568DDA7DC67ED2CA2AD9 |
| root        | 172.16.11.64 | *6BB4837EB74329105EE4568DDA7DC67ED2CA2AD9 |
+-------------+--------------+-------------------------------------------+
10 rows in set (0.00 sec)
连接测试成功,见下图



本文来自ChinaUnix博客,如果查看原文请点:http://blog.chinaunix.net/u3/93765/showart_2114199.html
您需要登录后才可以回帖 登录 | 注册

本版积分规则 发表回复

  

北京盛拓优讯信息技术有限公司. 版权所有 京ICP备16024965号-6 北京市公安局海淀分局网监中心备案编号:11010802020122 niuxiaotong@pcpop.com 17352615567
未成年举报专区
中国互联网协会会员  联系我们:huangweiwei@itpub.net
感谢所有关心和支持过ChinaUnix的朋友们 转载本站内容请注明原作者名及出处

清除 Cookies - ChinaUnix - Archiver - WAP - TOP