|
Debian安装Apache 1.3 MySQL PHP4 Tomcat 并整合Apache和Tomcat 以及 Tomcat 和 MySQL
作者:atfa www.linuxfans.org
转载注明出处和作者
0.安装Java2SDK
从google上搜索下面的j2sdk安装文件,
# ./j2sdk-1.4.2-rc1-linux-i586-gcc3.2.bin
使用gcc3.2版本的主要原因是firefox的官方包是用gcc3.2编译的,这样我们可以让firefox支持jre。
修改/etc/profile文件:
- PATH="/usr/local/j2sdk1.4.2/bin:/usr/local/bin:/usr/bin:/bin:/usr/bin/X11:/usr/games"
- JAVA_HOME="/usr/local/j2sdk1.4.2"
- CLASSPATH=".:/usr/local/j2sdk1.4.2/lib:/usr/local/j2sdk1.4.2/jre/lib:/usr/local/j2sdk1.4.2/jre/lib/ext"
复制代码
给firefox添加jre:
# cp /usr/local/j2sdk1.4.2/jre/plugin/i386/mozilla/libjavaplugin_oji.so /path/to/firefox/plugins/
1.安装Apache等软件:
# apt-get install apache php4 php4-mysql mysql-server mysql-client libapache-mod-jk
2.配置Apache提供php支持
修改/etc/apache/modules.conf:
找到这一行
# LoadModule php4_module /usr/lib/apache/1.3/libphp4.so
把这一行前面的井号去掉,以便apache加载这个libphp4.so模块。
然后,配置默认页,编辑/etc/apache/http.conf
找到这一行:
DirectoryIndex index.html index.htm index.shtml index.cgi
改成:
DirectoryIndex index.php index.php3 index.html index.htm index.shtml index.cgi
给Apache加上.php3扩展名的支持和php源码支持,找到:
#
# And for PHP 4.x, use:
#
#AddType application/x-httpd-php .php
#AddType application/x-httpd-php-source .phps
把后面两行修改成:
#
# And for PHP 4.x, use:
#
AddType application/x-httpd-php .php .php3
AddType application/x-httpd-php-source .phps
修改默认字符集
让Apache把简体中文作为默认的字符集。找到这一行:
AddDefaultCharset on
修改成:
AddDefaultCharset gb2312
为了使修改生效,需要重新启动Apache,运行:
# apachecrl restart
3.MySQL配置
修改MySQL的口令
# mysqladmin -u root password new-password
# mysqladmin -u root -h atfa password new-password
打开3306端口监听
这项工作要慎重。处于安全考虑,默认情况下,Debian把3306端口关闭了。因为,不少黑客通过它来攻击你的系统。如果你不通过其他机器来存取数据库,那么不要打开这个端口。但是由于atfa不知道的原因,使用Tomcat和Mysql的Connector连接Mysql需要我们打开这个端口。
修改/etc/mysql/my.cnf,找到:
skip-networking
把它注释掉:
# skip-networking
修改默认字符集
让MySQL把简体中文作为默认的字符集。编辑/etc/init.d/mysql,找到这一行:
/usr/bin/mysqld_safe > /dev/null 2>&1 &
改成:
/usr/bin/mysqld_safe > /dev/null --default-character-set=gb2312 2>&1 &
重新启动MySQL:
# /etc/init.d/mysql restart
4.PHP配置
修改php的默认字符集,把它改成简体中文。编辑/etc/php4/apache/php.ini:
找到 ;default_charset = "iso-8859-1"这一行:
;default_charset = "iso-8859-1"
把前面的分号去掉,并改成: default_charset = "gb2312"
default_charset = "gb2312"
5.安装Tomcat
在/usr/local/目录下:
# tar jxf jakarta-tomcat-5.0.19.tar.gz
把新产生的目录更名为tomcat
# mv jakarta-tomcat-5.0.19 tomcat
# chomd 755 tomcat/bin/*.sh
6.整合配置Apache和Tomcat
创建/etc/apache/mod_jk目录。在该目录下创建以下两个文件:
文件1
- # cat tomcat
- Alias /jsp-examples "/usr/local/tomcat/webapps/jsp-examples"
- Alias /network "/usr/local/tomcat/webapps/network"
- <Directory "/usr/local/tomcat/webapps/jsp-examples">
- Options Indexes FollowSymLinks
- </Directory>
- <Directory "/usr/local/tomcat/webapps/network">
- Options Indexes FollowSymLinks
- </Directory>
复制代码
# 就是这两行让Apache把请求的jsp文件和servlet下面的所有文件摔给Tomcat处理
- JkMount /jsp-examples/servlet/* ajp13
- JkMount /jsp-examples/*.jsp ajp13
- JkMount /network/servlet/* ajp13
- JkMount /network/*.jsp ajp13
- # The following line prohibits users from directly accessing WEB-INF
- <Location "/jsp-examples/WEB-INF/">
- AllowOverride None
- deny from all
- </Location>
- # The following line prohibits users from directly accessing META-INF
- <Location "/jsp-examples/META-INF/">
- AllowOverride None
- deny from all
- </Location>
- <Location "/network/WEB-INF/">
- AllowOverride None
- deny from all
- </Location>
- <Location "/network/META_INF/">
- AllowOverride None
- deny from all
- </Location>
复制代码
文件2
- # cat workers.properties
- workers.tomcat_home=/usr/local/tomcat
- workers.java_home=/usr/local/j2sdk1.4.2/
- ps=/
- worker.list=ajp12, ajp13
- worker.ajp12.port=8007
- worker.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.class_path=$(workers.tomcat_home)$(ps)classes
复制代码
此外还要修改/etc/apache/http.conf,在文件中找到这一行:
Include /etc/apache/modules.conf
在下面添加:
- <IfModule mod_jk.c>
- JkWorkersFile /etc/apache/mod_jk/workers.properties
- JkLogFile /etc/apache/mod_jk/mod_jk.log
- JkLogLevel info
- Include /etc/apache/mod_jk/tomcat
- </IfModule>
复制代码
修改/usr/local/tomcat/conf/server.xml
找到这一行:
<!-- Global logger unless overridden at lower levels -->
添加:
- <Context path="/jsp-examples"
- docBase="webapps/jsp-examples"
- crossContext="false"
- debug="0"
- reloadable="true">
- </Context>
- <Context path="/network"
- docBase="webapps/network"
- crossContext="false"
- debug="0"
- reloadable="true">
- </Context>
复制代码
7.配置tomcat和mysql
在www.mysql.com下载一个文件 ... e找,快一点:
mysql-connector-java-3.0.11-stable.zip
解压缩这个文件,复制下面的文件到指定目录:
# cp mysql-connector-java-3.0.11-stable-bin.jar /usr/local/j2sdk1.4.2/lib
用下面的文件测试mysql connector是否安装成功
- # cat /usr/local/tomcat/webapps/network/testmysql.jsp
- <%@ page import = "java.sql.*" %>
- <%
- Statement stmt = null;
- Class.forName("com.mysql.jdbc.Driver");
- //com.mysql.jdbc.Driver
- java.sql.Connection conn;
- conn = DriverManager.getConnection ("jdbc:mysql://atfa/mysql?user=root&password=new-password");
- stmt = conn.createStatement();
- %>
复制代码
感谢:
《Debian服务器设置入门》系列教程
作者:kanaka [冷罡华]
|
|