在fedora core6.0 /redhat 9 下整合apache+jsp+php+mysql+JK经验配制文档
作者:黄玉生 Email:hys1983@163.com QQ:187192204 QQ群:6276733
本文档是本人工作经验加网络资料整理出来的希望给大家一点点帮助。
Php5.2.1+mysql5.0.27+apache
2.0.59
+tomcat5.0.28+
ZendOptimizer3.2.0
下载apache httpd-2.0.59.tar.gz 到root目录
准备工作
http://tomcat.apache.org/download-55.cgi TOMCAT
下载
1
安装apache
tar zxvf httpd-2.0.59.tar.gz
cd httpd-2.0.59
./configure --prefix=/usr/local/httpd --enable-shared=max --enable-module=most --enable-so
#
备注: prefix定义apache的安装路径
make
make install
安装成功
cp /usr/local/httpd/bin/apachectl /etc/rc.d/init.d/httpd
vi /etc/rc.d/init.d/httpd
vi /etc/rc.d/init.d/httpd
修改文件,在文件中'#!/bin/sh'后面加入下面两条规则:
#!/bin/sh
#
# chkconfig: 2345 85 15
# description: Apache is a World Wide Web Server
#
#
# chkconfig: 2345 85 15
# description: Apache is a World Wide Web Server
#
使用chkconfig命令把apachectl命令加入到系统启动队列中:
chkconfig --add httpd
查看apachectl的状态:
chkconfig --list httpd
可以看到
[root@localhost init.d]# chkconfig --list httpd
httpd 0:off 1:off 2:off 3:off 4:off 5:off 6:off
Apache
配置完成
2
安
装
jdk
下载jdk-1_5_0_11-linux-i586.bin
[root@localhost ~]# mkdir /usr/local/jdk
[root@localhost ~]# cp jdk-1_5_0_11-linux-i586.bin /usr/local/jdk/
# cd /usr/local/jdk/
# cd /usr/local/jdk/
[root@localhost jdk]# chmod 755 jdk-1_5_0_11-linux-i586.bin
./jdk-1_5_0_11-linux-i586.bin
3
安装 Tomact
# tar zxvf jakarta-tomcat-5.0.28.tar.gz
# mv jakarta-tomcat-5.0.28 /usr/local/tomcat
vi /usr/local/tomcat/bin/catalina.sh
在第一节后、第二节前,即:# OS specific support 前输入
export JAVA_HOME=/usr/local/jdk/jdk1.5.0_11
export CATALINA_BASE=/usr/local/tomcat
export CATALINA_HOME=/usr/local/tomcat
export CLASSPATH=$JAVA_HOME/lib:$JAVA_HOME/jre/lib
export PATH=$JAVA_HOME/lib:$JAVA_HOME/jre/bin:$PATH:$HOME/bin
JAVA_OPTS="$JAVA_OPTS -Djava.awt.headless=true"
echo "Using JAVA_OPTS:
$JAVA_OPTS"
export CATALINA_BASE=/usr/local/tomcat
export CATALINA_HOME=/usr/local/tomcat
export CLASSPATH=$JAVA_HOME/lib:$JAVA_HOME/jre/lib
export PATH=$JAVA_HOME/lib:$JAVA_HOME/jre/bin:$PATH:$HOME/bin
JAVA_OPTS="$JAVA_OPTS -Djava.awt.headless=true"
echo "Using JAVA_OPTS:
$JAVA_OPTS"
保存退出。
备注:以上两节内容,第一节是指定
jdk
相关内容,第二节是应用系统的图片验证码生成程序要用,如果你没有使用到需要生成图片的程序,可以不加第二节内容。
继续把
tomcat
加入到系统自动启动队列中:
cd /etc/rc.d/init.d/
vi tomcat
在里面输入如下内容:
CODE:
#!/bin/sh
#
# tomcat: Start/Stop/Restart tomcat
#
# chkconfig: 2345 80 20
# description: Tomcat is a Java Servlet Container
#
#
# Source function library.
. /etc/rc.d/init.d/functions
TOMCAT=/usr/local/tomcat
start() {
echo -n $"Starting Tomcat: "
$TOMCAT/bin/startup.sh
}
stop() {
echo -n $"Stopping Tomcat: "
$TOMCAT/bin/shutdown.sh
}
# See how we were called.
case "$1" in
start)
start
;;
stop)
stop
;;
status)
;;
status)
;;
restart)
stop
start
;;
*)
echo $"Usage: $0 {start|stop|restart}"
;;
esac
exit $RETVAL
把
tomcat
修改为可运行的文件
chmod a+x tomcat
使用
chkconfig
命令把
tomcat
命令加入到系统启动队列中:
chkconfig --add tomcat
查看
apachectl
的状态:
chkconfig --list tomcat
看到
httpd 0:off 1:off 2:off 3:on4:on 5:off 6:off
4
、安装
mysql
下载 mysql-standard-5.0.27-linux-i686-glibc23.tar.gz 到目录: /usr/local/ 下
cd /usr/local/
tar -zxvf mysql-standard-5.0.27-linux-i686-glibc23.tar.gz
cd mysql-standard-5.0.27-linux-i686-glibc23
下载 mysql-standard-5.0.27-linux-i686-glibc23.tar.gz 到目录: /usr/local/ 下
cd /usr/local/
tar -zxvf mysql-standard-5.0.27-linux-i686-glibc23.tar.gz
cd mysql-standard-5.0.27-linux-i686-glibc23
groupadd mysql
useradd -g mysql mysql
useradd -g mysql mysql
ln -s /usr/local/mysql-standard-5.0.27-linux-i686-glibc23 /usr/local/mysql
cd /usr/local/mysql
scripts/mysql_install_db --user=mysql
chown -R root .
chown -R mysql data
chgrp -R mysql .
bin/mysqld_safe --user=mysql &
cd /usr/local/mysql
scripts/mysql_install_db --user=mysql
chown -R root .
chown -R mysql data
chgrp -R mysql .
bin/mysqld_safe --user=mysql &
这时再敲入回车,
mysql
现在已经启动了
继续配置
mysql
,使其在系统启动时自动启动:
cp support-files/mysql.server /etc/init.d/mysqld
chkconfig --add mysqld
查看 apachectl 的状态:
chkconfig --list mysqld
重新启动 mysql :
service mysqld restart
cp support-files/mysql.server /etc/init.d/mysqld
chkconfig --add mysqld
查看 apachectl 的状态:
chkconfig --list mysqld
重新启动 mysql :
service mysqld restart
安装php
先安装libxml2
# tar zxvf libxml2-2.6.19.tar.gz
# cd libxml2-2.6.19
# ./configure --prefix=/usr/local/module/libxml2
# make
# make install
安装php-5.2.1.tar.gz
# tar zxvf php-5.2.1.tar.gz
# cd php-5.2.1
./configure --prefix=/usr/local/php --with-apxs2=/usr/local/httpd/bin/apxs --with-mysql=/usr/local/mysql --with-xml --with-png --with-zlib --with-curl --enable-track-vars --disable-debug --enable-url-includes --enable-sockets --enable-force-cgi-redirect --enable-calendar --with-config-file-path=/etc --enable-magic-quotes --enable-ftp
# make
# make install
这样安装好像 php.ini在 /etc/php.ini
这个复制就不用做了 # cp php.ini-dist /usr/local/php/lib/php.ini
Php
安装完毕
让apache 支持php
vi /usr/local/httpd/conf/httpd.conf
vi /usr/local/httpd/conf/httpd.conf
找到 AddType application/x-gzip .gz .tgz 在其下添加如下内容
AddType application/x-httpd-php .php
AddType application/x-httpd-php-source .phps
Apache
和
Tomacat
整合
(
这是最关键的一部,
这里受
Apache
版本与
MOD_JK
版本的影响配制有些不同,如果版本不支持,有时会让你头晕
)
我这里使用
Fedora-core-1-i386.tar.gz //apache
与
tomcat
的连接程序
,
一般的方法是用
jakarta-tomcat-connectors-jk2-src-current.tar.gz,
但是这个过程十分麻烦
,
还需依赖另外好几个包
,
所以建议使用这个文件,或者用自己(别人)已编译好的
SO
文件
.
在
redhat 9
和
fedora core6.0
我都没能生成出
mod_jk.so
文件,这使用你没办法整合。而且
APACHE
的版本和
mod_jk.so
版本一定要相支持,不然也不能成功。
mod_jk.so
的版本不同的话,设置也是不一样
#tar
╟
zxvf fedora-core-1-i386.tar.gz
#cp fedora-core-1-i386/usr/lib/httpd/modules/*.so /usr/local/apache/modules // 把模块加入到 apache 里
#cp fedora-core-1-i386/etc/httpd/conf/workers. properties /usr/local/apache/c // 这个文件是 tomcat 与 apache 协同工作的脚本,稍后需要对它进行修改
#cp fedora-core-1-i386/usr/lib/httpd/modules/*.so /usr/local/apache/modules // 把模块加入到 apache 里
#cp fedora-core-1-i386/etc/httpd/conf/workers. properties /usr/local/apache/c // 这个文件是 tomcat 与 apache 协同工作的脚本,稍后需要对它进行修改
1
配置
tomcat
:这个过程比较复杂,要分几步进行。
a 修改文件 web.xml. #vi /usr/local/jakarta-tomcat/conf/web.xml , 把 web.xml 文件中的如下部分:
<!--
<servlet>
<servlet-name>invoker</servlet-name>
<servlet-class>
org.apache.catalina.servlets.invokerservlet
</servlet-class>
<init-param>
<param-name>debug</param-name>
<param-value>0</param-value>
</init-param>
<load-
</servlet>
-->
和
<!--
<servlet-mapping>
<servlet-name>invoker</servlet-name>
<url-pattern>/servlet/*</url-pattern>
</servlet-mapping>
-->
两部分的注释去掉即可(就是把 <!-- --> 去掉)。做这一步的原因是, tomcat 4.1.12 以后的版本的 servlet 调用器开关在默认状态下是关闭的。
b 修改文件 jk2.properties 。 #vi /usr/local/tomcat/conf/jk2.properties
## this file may be overriden at runtime. make sure tomcat is stoped
## when you edit the file.
## comments will be _lost_
## documentation of the format in jkmain javadoc.
# set the desired handler list
handler.list=apr,request // 去掉了前面的注释符号 #
# override the default port for the socketchannel
channelsocket.port=8009 // 去掉了前面的注释符号 #
# default:
# channelunix.file=${jkhome}/work/jk2.socket
# just to check if the the c is working
shm.file=/usr/local/apache/logs/jk2.shm // 手动添加的
# in order to enable jni use any channeljni directive
# channeljni.disabled = 0
# and of the following directives:
# apr.jnimodeso=/opt/apache2/modules/mod_jk2.so
# if set to inprocess the mod_jk2 will register natives itself
# this will enable the starting of the tomcat from mod_jk2
# apr.jnimodeso=inprocess
在这里可以先验证一下 tomcat 是否可以正常工作。启动 tomcat #sh /usr/local/jakarta-tomcat-5.0.28/bin/startup.sh , 正常情况会输出 tomcat 和 jdk 的目录。
tomcat 启动输出示意图
然后再在 windows 的计算机的浏览器里输入 linux 服务器的 ip 地址和端口号,形如: http://192.168.0.100:8080 , 如果没有意外,则可出现那只可爱的小猫。
2 配置 apache: 因为 php 和 jsp 都要整合在 apache 里(可以把 apache 想象成一个容器),这一步的配置过程也是很复杂的。配置前可以先验证一下 apache ,看它是否可以正常工作。与 tomcat 相试,只是不用输端口号而已,形如 http://192.168.0.100 , 如果出现 apache 的测试 web 页面,表明一切正常。
a 对文件 workers2.properties 的修改。其目的是让 tomcat 与 apache 系统工作。使用命令 #vi /usr/local/apache/conf/workers2.properties 编辑文件如下所示
[shm]
info=scoreboard. requried for rec and status with multiprocess servers.
file=/usr/local/apache/logs/shm.file // 这行是改动过的
size=1048576 // 手动添加的
# defines a load balancer named lb. use even if you have machine.
[lb:lb]
# example socket channel, override port and host.
[channel.socket:localhost:8009]
port=8009
host=127.0.0.1
# define the worker
[ajp13:localhost:8009]
channel=channel.socket:localhost:8009
group=lb
# map the tomcat examples webapp to the web server uri space
[uri:/*.jsp] //jsp 脚本交给 tomcat 解释器完成,其它的由 apache 处理, 如果不是这 // 样,就会出现 /usr/local/jakarta-tomcat/webapps/root 里的 php 脚本 // 不能被正确解析。感谢张炜宇在这个问题上的大力帮助。
[uri:/servlet/*]
[uri:/*.do]
worker=ajp13:localhost:8009 // 手动添加的
group=lb
[status:]
info=status worker, displays runtime information
[uri:/jkstatus/*]
worker=ajp13:localhost:8009 // 手动添加的
info=the tomcat /jkstatus handler
group=status:
b 修改 apache 的配置文件
a 修改文件 web.xml. #vi /usr/local/jakarta-tomcat/conf/web.xml , 把 web.xml 文件中的如下部分:
<!--
<servlet>
<servlet-name>invoker</servlet-name>
<servlet-class>
org.apache.catalina.servlets.invokerservlet
</servlet-class>
<init-param>
<param-name>debug</param-name>
<param-value>0</param-value>
</init-param>
<load-
</servlet>
-->
和
<!--
<servlet-mapping>
<servlet-name>invoker</servlet-name>
<url-pattern>/servlet/*</url-pattern>
</servlet-mapping>
-->
两部分的注释去掉即可(就是把 <!-- --> 去掉)。做这一步的原因是, tomcat 4.1.12 以后的版本的 servlet 调用器开关在默认状态下是关闭的。
b 修改文件 jk2.properties 。 #vi /usr/local/tomcat/conf/jk2.properties
## this file may be overriden at runtime. make sure tomcat is stoped
## when you edit the file.
## comments will be _lost_
## documentation of the format in jkmain javadoc.
# set the desired handler list
handler.list=apr,request // 去掉了前面的注释符号 #
# override the default port for the socketchannel
channelsocket.port=8009 // 去掉了前面的注释符号 #
# default:
# channelunix.file=${jkhome}/work/jk2.socket
# just to check if the the c is working
shm.file=/usr/local/apache/logs/jk2.shm // 手动添加的
# in order to enable jni use any channeljni directive
# channeljni.disabled = 0
# and of the following directives:
# apr.jnimodeso=/opt/apache2/modules/mod_jk2.so
# if set to inprocess the mod_jk2 will register natives itself
# this will enable the starting of the tomcat from mod_jk2
# apr.jnimodeso=inprocess
在这里可以先验证一下 tomcat 是否可以正常工作。启动 tomcat #sh /usr/local/jakarta-tomcat-5.0.28/bin/startup.sh , 正常情况会输出 tomcat 和 jdk 的目录。
tomcat 启动输出示意图
然后再在 windows 的计算机的浏览器里输入 linux 服务器的 ip 地址和端口号,形如: http://192.168.0.100:8080 , 如果没有意外,则可出现那只可爱的小猫。
2 配置 apache: 因为 php 和 jsp 都要整合在 apache 里(可以把 apache 想象成一个容器),这一步的配置过程也是很复杂的。配置前可以先验证一下 apache ,看它是否可以正常工作。与 tomcat 相试,只是不用输端口号而已,形如 http://192.168.0.100 , 如果出现 apache 的测试 web 页面,表明一切正常。
a 对文件 workers2.properties 的修改。其目的是让 tomcat 与 apache 系统工作。使用命令 #vi /usr/local/apache/conf/workers2.properties 编辑文件如下所示
[shm]
info=scoreboard. requried for rec and status with multiprocess servers.
file=/usr/local/apache/logs/shm.file // 这行是改动过的
size=1048576 // 手动添加的
# defines a load balancer named lb. use even if you have machine.
[lb:lb]
# example socket channel, override port and host.
[channel.socket:localhost:8009]
port=8009
host=127.0.0.1
# define the worker
[ajp13:localhost:8009]
channel=channel.socket:localhost:8009
group=lb
# map the tomcat examples webapp to the web server uri space
[uri:/*.jsp] //jsp 脚本交给 tomcat 解释器完成,其它的由 apache 处理, 如果不是这 // 样,就会出现 /usr/local/jakarta-tomcat/webapps/root 里的 php 脚本 // 不能被正确解析。感谢张炜宇在这个问题上的大力帮助。
[uri:/servlet/*]
[uri:/*.do]
worker=ajp13:localhost:8009 // 手动添加的
group=lb
[status:]
info=status worker, displays runtime information
[uri:/jkstatus/*]
worker=ajp13:localhost:8009 // 手动添加的
info=the tomcat /jkstatus handler
group=status:
b 修改 apache 的配置文件
/etc/httpd/conf/httpd.conf. #vi /usr/local/apache/conf/httpd.c ,
loadmodule jk2_module modules/mod_jk2.so //jk2 以 apache 的模块方式运行
directoryroot “/usr/local/jakarta-tomcat-5.0.28/webapps/root” // 默认的
// 为 ”/var/www/html”
typeadd application /x-httpd-php .php3 // 让 apache 能解释 php 脚
// 本,注意 .php3 前面有空格
测试
自己搞几个 *.php 和 *.jsp 文件拷贝到目录,然后分别启动 apache 和 tomcat .
#/usr/local/apache/bin/apachectl start // 启动 apache ( 可惜不是直升机 )
#sh /usr/local/jakarta-tomcat/bin/startup.sh // 启动 tomcat
loadmodule jk2_module modules/mod_jk2.so //jk2 以 apache 的模块方式运行
directoryroot “/usr/local/jakarta-tomcat-5.0.28/webapps/root” // 默认的
// 为 ”/var/www/html”
typeadd application /x-httpd-php .php3 // 让 apache 能解释 php 脚
// 本,注意 .php3 前面有空格
测试
自己搞几个 *.php 和 *.jsp 文件拷贝到目录,然后分别启动 apache 和 tomcat .
#/usr/local/apache/bin/apachectl start // 启动 apache ( 可惜不是直升机 )
#sh /usr/local/jakarta-tomcat/bin/startup.sh // 启动 tomcat
http://127.0.0.1/index.jsp
http://127.0.0.1/index.php
我的成功了
此是我还有一个问题还没有解决:我以前
TOMCAT4.0
下的目录现在移到
tomcat5.0
上时,
JSP
页在显示时浏览器老是默认字符为西欧的,
THML
,
HTM
都中文显示正常,我想了很多办法都没有解决。欢迎大家一起讨论
LINUX
下(
JAVA
)问题:
QQ
群:6276733