Linux下安装配置 Jdk1.6+Tomcat6.0.x+MySql5.x+Apache2.2.x+jk_mod1.2+PHP5.x 详解

Linux下安装配置 Jdk1.6+Tomcat6.0.x+MySql5.x+Apache2.2.x+jk_mod1.2+PHP5.x 详解

本篇以Redhat AS5,内核为Linux 2.6.18-8.el5 为例,其中Redhat/Fedora系列基本一致,其他Linux或者版本均可以参考。

STEP 1

软件下载:

1. jdk1.6.x   http://java.sun.com/javase/downloads/index.jsp

2. tomcat6.x   http://tomcat.apache.org/download-60.cgi

3. mysql5.x    http://dev.mysql.com/downloads/mysql/5.0.html

                                   http://dev.mysql.com/get/Downloads/MySQL-5.0/mysql-5.0.51a-linux-i686.tar.gz/from/pick

4. JDBC connector   http://dev.mysql.com/downloads/connector/j/5.1.html

5. apache2.x   http://httpd.apache.org/download.cgi

6. php5.x      http://www.php.net/downloads.php

7. jk_mod1.2.x  http://tomcat.apache.org/download-connectors.cgi

假如以上文件都已经成功下载,并放到了/home/work/software/下,假设你是work用户。

SETP 2

1. JDK安装

         1.1  解压并授权给下载程序可以执行的权限

                [work@localhost webServer]$ chmod a+r jdk-6u10-beta-linux-i586.bin

                *** 一段许可协议 ***

                Do you agree to the above license terms? [yes or no]

                [work@localhost webServer]$ yes

                ***  解压过程 ***

                Done.

                # 出现一段许可协议,提示是否同意上面的条款,输入yes。

                [work@localhost webServer]$ mv jdk1.6.0_10 /home/work/usr/local/

                [work@localhost local]$ ln -s jdk1.6.0_10 jdk

                完成后,将解压后的jdk1.6.0_10文件夹移动到专门的目录下面,还可以做一个符号连接

        1.2  配置Java环境变量

                直接编辑/etc/profile文件或者在/etc/profile.d/文件下新建java.sh文件

                普通用户没有编辑权限,可以授权或者切换到root账户来编辑该文件。

                [work@localhost local]$ vim /etc/profile.d/java.sh

                这里以新建的java.sh文件为例子(也推荐这种方式),添加内容如下:

                #set java 环境变量

                JAVA_HOME=/home/work/usr/local/jdk

                PATH=$PATH:/$JAVA_HOME/bin

                CLASSPATH=.:$JAVA_HOME/lib

                JRE_HOME=$JAVA_HOME/jre

                export JAVA_HOME PATH CLASSPATH JRE_HOME

        1.3  设置java和javac的符号连接,这是把默认的jdk(本系统默认是JDK1.4)改成刚新装的jdk1.6

                [work@localhost local]#cd /usr/bin  #切到usr/bin目录

                [work@localhost local]#su root      #切换到root账号,分别作符号连接

                [root@localhost bin]# ln -s -f /home/work/usr/local/jdk/jre/bin/java

                [root@localhost bin]# ln -s -f /home/work/usr/local/jdk/bin/javac

        JDK安装完成,有问题请参考:http://jiarry.bokee.com/2425368.html

2.  Tomcat安装

        2.1  解压后移动文件夹到指定目录

                [work@localhost webServer]$ tar -zxvf apache-tomcat-6.0.16.tar.gz

                [work@localhost webServer]$ mv apache-tomcat-6.0.16 /home/work/usr/local/

        2.2  配置环境变量

                编辑刚新建的/etc/profile.d/java.sh文件(如果没有新建就编辑/etc/profile文件),添加TOMCAT_HOME

                TOMCAT_HOME = /home/work/usr/local/tomcat

                export JAVA_HOME PATH CLASSPATH JRE_HOME TOMCAT_HOME

3.        测试安装

        3.1   检查环境变量和java版本

                分别输入下面的命令,检查输出是否与设置的相符合:

                [work@localhost ~]$ echo $JAVA_HOME                        

                                /home/work/usr/local/jdk

                [work@localhost ~]$ echo $PATH

                                输出的含有/home/work/usr/local/jdk/bin:

                [work@localhost ~]$ echo $CLASSPATH

                                .:/home/work/usr/local/jdk/lib

                [work@localhost ~]$ echo $TOMCAT_HOME

                                /home/work/usr/local/tomcat

                设置/usr/bin下面java和javac的符号连接后,看到的应是新的jdk1.6

                [work@localhost ~]$ java -version

                java version "1.6.0_10-beta"

                Java(TM) SE Runtime Environment (build 1.6.0_10-beta-b25)

                Java HotSpot(TM) Client VM (build 11.0-b12, mixed mode, sharing)

                

            如果没有设置符号连接,将是默认的jdk1.4

            [work@localhost ~]$ java -version

            java version "1.4.2"

            gij (GNU libgcj) version 4.1.1 20070105 (Red Hat 4.1.1-52)

    3.2   启动tomcat

            [work@localhost local]$ sh /home/work/usr/local/tomcat/bin/startup.sh

            在浏览器地址栏输入    http://localhost:8080/

            如果能看到Tomcat的欢迎页表示整合成功,至此已经完成了Java/JSP服务器的搭建。

    3.3  给Tomcat添加项目

            3.3.1  修改tomcat/conf/server.xml,在<Host name="localhost"></Host>之间增加如test项目:

            <Context path="/test" reloadable="true" docBase="/home/work/dev/test"

    workDir="/home/work/usr/local/tomcat/work/test" />

           

            这样就增加了一个为test的项目,path是web请求访问路径,docBase是目录实际放的目录,workDir是tomcat解析工作目录,可以放到tomcat的work下。

            可以他通过 http://localhost:8080/test 来访问test项目

            至此,Tomcat配置完成。如果要开启目录浏览和servlet直接访问功能,可以参照下面的配置。

            3.3.2  开启目录浏览,tomcat默认是不开启目录浏览的,可以通过修改web.xml里的listings的值来设定,改false为true。如下:

            <param-name>listings</param-name>

            <param-value>true</param-value>

            3.3.3  默认不开启servlet直接访问,可以修改web.xml和context.xml文家的配置来开启,如下:

            web.xml。找到这段,打开注释

           <servlet-name>invoker</servlet-name>

                <servlet-class>

                  org.apache.catalina.servlets.InvokerServlet

                </servlet-class>

            还有这段,也开启是注释

           <servlet-mapping>

                <servlet-name>invoker</servlet-name>

           

            context.xml。在Context里增加privileged

            <Context privileged="true">

SETP 3 MySql与JDBC connector

1.  解压缩mysql-5.0.51a-linux-i686.tar.gz包,移动到指定位置

    [work@localhost webServer]$ tar -zxvf mysql-5.0.51a-linux-i686.tar.gz

    [work@localhost webServer]$ mv mysql-5.0.51a-linux-i686 /home/work/usr/local/

2. 参照INSTALL-BINARY文件安装mysql,一定要仔细阅读并认真执行,这里是二进制的安装包,如果下载的是源码就需要先编译

    2.1  建立一个mysql符号连接

    [work@localhost local]$ cd /home/work/usr/local/

    [root@localhost local]# ln -s mysql-5.0.51a-linux-i686 mysql

    切换到root账号,添加mysql用户和组

    [work@localhost local]$ su root

    [root@localhost local]# su -

    [root@localhost ~]# groupadd mysql

    [root@localhost ~]# useradd -g mysql mysql

    回到/home/work/usr/local/mysql/,更改目录所属为mysql

    [root@localhost ~]# cd /home/work/usr/local/mysql/   

    [root@localhost mysql]# chown -R mysql .

    [root@localhost mysql]# chgrp -R mysql .

    执行脚本生成mysql系统数据库

    [root@localhost mysql]# scripts/mysql_install_db  --user=mysql

    Installing MySQL system tables...

    OK

    Filling help tables...

    OK

    ……

    出现成功提示之后,授权返还给work,但是data目录仍然给mysql账号   

    [root@localhost mysql]# chown -R work .

    [root@localhost mysql]# chown -R mysql data

    2.2  看/var/run/是否有mysqld目录,如果没有就新建一个,并在mysqld目录下新建mysqld.pid的空白文件。(本步骤并不是必须的)

    [root@localhost mysql]# cd  /var/run/mysqld

    [root@localhost run]# mkdir mysqld

    [root@localhost mysqld]# cd mysqld

    [root@localhost run]# chown -R mysql mysqld .

    [root@localhost run]# chgrp -R mysql mysqld .

    [root@localhost mysql]#su mysql   

    [mysql@localhost mysql]$ vi /var/run/mysqld/mysqld.pid

    查看/tmp/下是否有mysql.sock文件,没有的话把/home/mysql/mysql.sock做个符号连接到/tmp/临时文件夹下。(本步骤并不是必须的)

    如果不建立符号连接,就需要通过在启动是加入 --socket=/home/mysql/mysql.sock参数来启动

    [root@localhost mysql]# ln -s /home/mysql/mysql.sock /tmp/mysql.sock

    [root@localhost tmp]# chown -R mysql mysql.sock

    [root@localhost tmp]# chgrp -R mysql mysql.sock

    也可以查看一下/etc/my.cnf,看里面配置的指向与自己的安装是否一致有datadir,basedir,socket等。(本步骤并不是必须的)

    [root@localhost tmp]# cat /etc/my.cnf

    2.3  启动mysql服务,非mysql帐号就加上--user=msyql

    [root@localhost mysql]# bin/mysqld_safe --user=mysql &

    [root@localhost mysql]# Starting mysqld daemon with databases from /var/lib/mysql

    启动成功后,查看一下mysql的进程:

    [root@localhost mysql]# ps -el | grep mysqld

    4 S     0 14213 13164  0  84   0 -  1171 wait   pts/0    00:00:00 mysqld_safe

    4 S   502 14241 14213  0  85   0 -  8223 -      pts/0    00:00:00 mysqld

    1 S   502 14242 14241  0  78   0 -  8223 -      pts/0    00:00:00 mysqld

    1 S   502 14243 14242  0  85   0 -  8223 rt_sig pts/0    00:00:00 mysqld

    [root@localhost tmp]# netstat -na | grep 3306

    tcp        0      0 0.0.0.0:3306                0.0.0.0:*                   LISTEN     

    可以查看mysql 3306端口是否运行中

    2.4  登录mysql试一下,可用其他账户

    [root@localhost mysql]# su work

    [work@localhost mysql]$ cd /home/work/usr/local/mysql/

    [work@localhost mysql]$ bin/mysql -uroot -p密码

    或者mysql用户[mysql@localhost mysql]$ bin/mysql -uroot -p密码,将看到成功登录信息。

    Welcome to the MySQL monitor.  Commands end with ; or \g.

    Your MySQL connection id is 1

    Server version: 5.0.51a MySQL Community Server (GPL)

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

    mysql> \s

    --------------

    bin/mysql  Ver 14.12 Distrib 5.0.51a, for pc-linux-gnu (i686) using readline 5.0

    Connection id:          2

    Current database:

    urrent user:           root@localhost

    SL:                    Not in use

    urrent pager:          stdout

    sing outfile:          ''

    Using delimiter:        ;

    Server version:         5.0.51a MySQL Community Server (GPL)

    Protocol version:       10

    Connection:             Localhost via UNIX socket

    Server characterset:    latin1

    Db     characterset:    latin1

    Client characterset:    latin1

    Conn.  characterset:    latin1

    UNIX socket:            /tmp/mysql.sock

    Uptime:                 8 min 33 sec

    Threads: 1  Questions: 7  Slow queries: 0  Opens: 11  Flush tables: 1  Open tables: 6  Queries per second avg: 0.014

    --------------

   

    mysql> create database myapp;

    Query OK, 1 row affected (0.00 sec)

    2.5  配置自动启动,也root账户

    [root@localhost mysql]# cp support-files/mysql.server /etc/rc.d/init.d/mysqld

    [root@localhost mysql]# chmod 777 /etc/init.d/mysqld

    [root@localhost init.d]# su -

    [root@localhost ~]# chkconfig --add mysqld

    至此,mysql配置完成。

但是有时候完全按照INSTALL-BINARY来安装,仍然会出现问题,如下:

***************************************************************

   

    1.  运行# bin/mysqld_safe --user=mysql & 后,若有提示STOPPING server from pid file /var/run/mysqld/mysqld.pid之类的。

    先检查一下安装日志,看是否提示/var/ran/下缺少mysqld目录及mysqld.pid文件,如是,就添加该目录

    [root@localhost mysql]# less /var/log/mysqld.log

    进入/var/run/创建mysqld目录,在/var/run/mysqld/下再创建空文件mysqld.pid,并给授权mysql账户

    mysqld.pid是运行时需要的文件,如果没有/var/ran/mysqld目录就建立一个,文件会自动生成,也可以不建立该文件。

    [root@localhost run]# cd /var/run/

    [root@localhost run]# mkdir mysqld

    [root@localhost mysqld]# cd mysqld

    [root@localhost mysqld]# touch mysqld.pid

    [root@localhost mysqld]# cd ..

    [root@localhost run]# chown -R mysql mysqld .

    [root@localhost run]# chgrp -R mysql mysqld .

    再启动服务就能成功了

    [root@localhost mysql]# bin/mysqld_safe --user=mysql &

    2.   如果mysql启动后,登录时出现错误提示:

    [root@localhost mysql]# bin/mysql -uroot -p

    ERROR 2002 (HY000): Can't connect to local MySQL server through socket '/tmp/mysql.sock' (2)

    则可能表示/tmp/下没有mysql.sock文件

         默认的mysql.sock 是在/var/lib/mysql/mysql.sock,从mysql安装目录(/home/mysql/)也有

    建一个符号连接到tmp下就可以了,并且把mysql.sock文件所属改为mysql账户

    [root@localhost mysql]# ln -s /home/mysql/mysql.sock /tmp/mysql.sock

    [root@localhost tmp]# cd /tmp/

    [root@localhost tmp]# chown -R mysql mysql.sock

    [root@localhost tmp]# chgrp -R mysql mysql.sock

    3. 给/var/lib/mysql/目录以及下面的所有文件授权给mysql账户。(但本步骤并不是必须的)

    [root@localhost mysql]# cd /var/lib/mysql/

    [root@localhost mysql]# chown -R mysql .

    [root@localhost mysql]# chgrp -R mysql .   

    [root@localhost mysql]# chmod a+w *

    4  另外还可以查看一下/etc/my.cnf文件,看一下里面配置项的指向,如socket等

    [root@localhost etc]# vim /etc/my.cnf

    [mysqld]

    datadir=/var/lib/mysql

    socket=/home/mysql/mysql.sock

    #socket=/var/lib/mysql/mysql.sock

    # Default to using old password format for compatibility with mysql 3.x

    # clients (those using the mysqlclient10 compatibility package).

    old_passwords=1

    

    [mysql.server]

    user=mysql

    basedir=/var/lib

    [mysqld_safe]

    log-error=/var/log/mysqld.log

    pid-file=/var/run/mysqld/mysqld.pid

    看下socket=/home/mysql/mysql.sock,这里的地址与/tmp/mysql.sock符号连接要对应上,

    /var/lib/mysql/目录下默认也有mysql.sock,/tmp/mysql.sock的符号连接如果指向的是这个地址,就不用修改了

    其他的配置也可以根据实际情况来修改,比如datadir,basedir,socket等

   

    以上修改一项就测试一下,最好先查一下是否存在mysql进程,可以kill已经存在的mysql进程,再重新启动mysql

    [root@localhost mysql]# bin/mysqld_safe --user=mysql &

    [root@localhost mysql]# bin/mysql -uroot -p   

    这些问题一般都是因为文件没有正确授权或者是/tmp/没有mysql.sock符号连接等原因导致的,以上几个方法能解决大部分同学遇到的问题,

    参照:

   http://lawzjf.itpub.net/post/417/451262

    http://www.chinaunix.net/jh/17/178508.html

   http://www.chinaunix.net/jh/17/416730.html

***************************************************************

   

    另外,mysql也可下载源码来编译安装。http://dev.mysql.com/downloads/mysql/5.0.html#linux-icc

3. mysql-connector-java安装

    3.1  解压缩,把jar文件移到tomcat lib目录下   

    [work@localhost webServer]$ tar -zxvf mysql-connector-java-5.1.6.tar.gz

    [work@localhost webServer]$ cp mysql-connector-java-5.1.6/mysql-connector-java-5.1.6-bin.jar /home/work/usr/local/tomcat/lib/

    3.2   配置数据池连接

            3.2 .1  修改tomcat/conf/server.xml,对原来test项目进行修改,添加数据池配置

     <Context path="/test" docBase="/home/work/dev/test"

        debug="5" reloadable="true" crossContext="true"  workDir="/home/work/usr/local/tomcat/work/test">

  <Resource  name="jdbc/test"

             auth="Container"

    type="javax.sql.DataSource"

             maxActive="100" maxIdle="30" maxWait="10000"

             username="root" password=""

    driverClassName="com.mysql.jdbc.Driver"

    url="jdbc:mysql://localhost:3306/test_db_name?autoReconnect=true&useUnicode=true&characterEncoding=utf-8"/>

 </Context>

            3.2 .2  在/home/work/dev/test/下建立WEB-INF/web.xml文件,加入如下内容:

   <web-app xmlns="http://java.sun.com/xml/ns/j2ee"

    xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"

    xsi:schemaLocation="http://java.sun.com/xml/ns/j2ee

http://java.sun.com/xml/ns/j2ee/web-app_2_4.xsd"

    version="2.4">

  <description>My Test App</description>

     <resource-ref>

      <description>DB Connection</description>

      <res-ref-name>jdbc/test</res-ref-name>

      <res-type>javax.sql.DataSource</res-type>

      <res-auth>Container</res-auth>

  </resource-ref>

  </web-app>

            3.2 .3  在tomcat的test项目下新建立一个jdbc_test.jsp文件(名字自己起),内容如下:

    <%@ page language="java" contentType="text/html; charset=utf-8" pageEncoding="utf-8"%>

    <%@ page import="java.sql.*"%>

    <%@ page import="javax.sql.*"%>

    <%@ page import="javax.naming.*"%>

    <pre>

    This is a Java Server Page. I am Jarry!

    JSP+MySql JDBC Driver and Connection Pool Test:

    </pre>

     数据库连接池测试结果:

     <%

     out.println("JDBC驱动检查<br>");

     try {

      Class.forName("com.mysql.jdbc.Driver");

      out.println("检查成功!<br>");

     } catch (ClassNotFoundException cnfe) {

      out.println("JDBC驱动创建失败!<br>");

      cnfe.printStackTrace();

     }

   

      out.println("<br>环境命名空间检查<br>");

     try {

            javax.naming.Context ctx = new javax.naming.InitialContext();

      javax.naming.Context envContext =

       (javax.naming.Context) ctx.lookup("java:/comp/env");

      out.println("检查成功!<br>");

     

      out.println("<br>查找数据源<br>");

             // org.apache.commons.dbcp.BasicDataSource ds =

             //   (org.apache.commons.dbcp.BasicDataSource) envContext.lookup("jdbc/test");

      DataSource ds =(DataSource)ctx.lookup("java:comp/env/jdbc/test");

      out.println("查找成功!<br>");

                         // 早期版本可以用BasicDataSource接收以获得比DataSource接口更具体的信息,便于错误查找

            // 测试数据库是否能执行,如果tomcat里server.xml配置的数据库可以执行的话就会成功输出数据库

         

     /*

       out.println("<br>检查数据库<br>");

       Connection conn = ds.getConnection();

       DatabaseMetaData metaData = conn.getMetaData();

       ResultSet rs = metaData.getCatalogs();

       while (rs.next())

       out.println(rs.getString(1) + "<br>");

       rs.close();

    */

 

    } catch (javax.naming.NamingException e) {

      out.println("环境变量上下文创建失败!<br>");

      e.printStackTrace();

   /*

     } catch (SQLException e) {

       out.println("数据库操作执行失败!<br>");

       e.printStackTrace();

    */

     }

   %>

    重启Tomcat,访问http://localhost:/test/jdbc_test.jsp,若都能显示成功,便表示成功安装了

    参考:http://jiarry.bokee.com/6234733.html

            http://tomcat.apache.org/tomcat-6.0-doc/jndi-datasource-examples-howto.html

   

SETP 4 Apache安装配置

            1  解压缩Apache,通读httpd目录里的INSTALL文件

            [work@localhost webServer]$ tar -zxvf httpd-2.2.9.tar.gz

            可以把得到的文件夹移动到安装目录,比如/home/work/software/下,这里放在/home/work/software/webServer/

            [work@localhost webServer]$ cd httpd-2.2.9

            [work@localhost httpd-2.2.9]$ ./configure --help #最好先查看下编译指令

            [work@localhost httpd-2.2.9]$ ./configure --prefix=/home/work/usr/local/apache2 --enable-mods-shared=all

            [work@localhost httpd-2.2.9]$ make           

            [work@localhost httpd-2.2.9]$ make install

            [work@localhost httpd-2.2.9]$ cd /home/work/usr/local/apache2

            [root@localhost apache2]# su root

            [work@localhost apache2]$ bin/apachectl start

            编译安装--enable-so-mods-shared=all新版的安装文档里没有提示需要加载,直接./configure --prefix=/home/work/usr/local/apache2即可

            安装过程要2分钟时间,完成后,切换到root账号启动Apache

            在地址栏输入http://localhost/,看到 it works欢迎页表示成功

            参照:http://httpd.apache.org/docs/2.2/install.html

            2  配置apache/conf/http.conf

            #添加test项目

            Alias /ut "/home/work/dev/test"

            <Directory "/home/work/dev/test">

            Options Indexes FollowSymLinks MultiViews Includes ExecCGI

            AllowOverride None

            Order allow,deny

            Allow from all

            </Directory>

            #禁止访问WEB-INF文件夹

            <Directory  "/home/work/dev/test/WEB-INF">

           Order allow,deny

            </Directory>

            打开注释配置语言,可以设置默认中文

           Include conf/extra/httpd-languages.conf

            在extra/httpd-languages.conf增加如下代码,这样默认就是中文了,比如Ajax请求数据,都不用定义encoding也能正常支持中文了。

            DefaultLanguage zh-CN

           AddDefaultCharset gb2312

            3  打开浏览器输入http://localhost/test/ 是否能看到目录列表呢,可以访问下之前建立的JSP文件试一下,由于还没有配置Tomcat的连接器,所以会当作文本文件来处理。

                    如果遇到禁止访问,则需要授权 [work@localhost ut]$ chmod 777 *

SETP 5 jk_mod整合Apache与Tomcat   

    1  把下载到的二进制文件mod_jk-1.2.26-httpd-2.2.6.so复制到apache的modules目录下

    下载地址: http://apache.mirror.phpchina.com/tomcat/tomcat-connectors/jk/binaries/linux/jk-1.2.26/

   

    2  在Apache的conf目录新建立两个文件,mod_jk.conf和workers.properties文件,配置过程与windows基本一样。

            mod_jk.conf的内容是jk的配置文件,包括装载模块和日志信息以及指定解析的工作器和目录,workers.properties是Tomcat wokers的配置文件。

    3  在mod_jk.conf里加入以下内容(mod_jk.conf文件是方便管理,而不需要把配置都写在httpd.conf里)

            #加载jk模块,名字要对应

            LoadModule jk_module modules/mod_jk-1.2.26-httpd-2.2.6.so 

            # 加载刚才新建的workers.properties文件

            JkWorkersFile conf/workers.properties

            # Jk日志文件

            JkLogFile logs/mod_jk.log

            # Jk日志的级别,参数有[debug/error/info]

            JkShmFile logs/mod_jk.shm

            JkLogLevel info

            # Jk日志的数据格式

            JkLogStampFormat "[%a %b %d %H:%M:%S %Y] "

            # Jk的一些配置选项 indicate to send SSL KEY SIZE,

            JkOptions +ForwardKeySize +ForwardURICompat -ForwardDirectories

            # Jk请求日志的格式

            JkRequestLogFormat "%w %V %T"

            #JSP do Servlet文件交由Tomcat处理

            JkMount /servlet/* ajp13    

            JkMount /*.jsp ajp13

            JkMount /*.do ajp13    

            # JkMount 表示使用Tomcat来解析, JkUnMount则相反

 

            # JkMount /test/* ajp13 表示把test目录下的所有文件以及子目录都交给Tomcat处理

                 #  一般是jsp和servlet程序交由tomcat处理就可以了,静态文件图片等仍然由Apache处理

                 #  你可以根据需要来设定,比如只把test/*.jsp交给Tomcat处理    # JkMount /test/*.jsp ajp13

   

            #JkAutoAlias /home/work/dev/test/* 

            #该文件夹下所有的静态文件自动交由Apache处理

            JkMount /test/servlet/* ajp13   

            #/test/servlet/下所有的文件也交给Tomcat处理

    4  编辑Apache的httpd.conf文件,把jk_mod.conf文件装载进来:

            Include conf/mod_jk.conf

    5  编辑workers.properties文件,添加以下内容:

            workers.tomcat_home=/home/work/usr/local/tomcat/

            workers.java_home=/home/work/usr/local/jdk/

            ps=\

            worker.list=ajp13

            worker.ajp13.port=8009

            worker.ajp13.host=localhost

            worker.ajp13.type=ajp13

            worker.ajp13.lbfactor=1

            #如果没有专门的配置,也可以不添加这些内容,空文件或者不要该也可以

            #配置参考请见http://tomcat.apache.org/connectors-doc/reference/workers.html           

   6  如果下载的是源文件,需要编译后再配置。也很简单,如下:

            [work@localhost webServer]$ tar -zxvf tomcat-connectors-1.2.26-src.tar.gz

            首先解压缩,查看解压后的BUILD.txt文件,并按说明去做

            [work@localhost webServer]$ cd tomcat-connectors-1.2.26-src/native/

            [work@localhost native]$ ./configure --with-apxs=/home/work/usr/local/apache2/bin/apxs

            注意apxs的路径是你apache目录的bin/apxs

            [work@localhost native]$ make

            [work@localhost native]$ su -c 'make install'

            按提示输入root密码,执行安装。可以看见含有有如下提示:

           

            Libraries have been installed in:

           /home/work/usr/local/apache2/modules

            chmod 755 /home/work/usr/local/apache2/modules/mod_jk.so

            [work@localhost modules]$ cd /home/work/usr/local/apache2/modules/

            进入到Apache的模块目录下,给mod_jk授权,不更改用户组也没有关系

            [work@localhost modules]$ su -c 'chgrp -R work mod_jk.so'

            [work@localhost modules]$ su -c 'chown -R work mod_jk.so'

            [work@localhost modules]$ chmod 777 mod_jk.so

            新建jk_mod.conf和workers.properties以及如何配置跟上面5.2的安装方法是一致的

            编辑新建的apache/conf/jk_mod.conf文件,把mod_jk.so装载进来,详细配置参见5.4

            LoadModule jk_module modules/mod_jk.so

    7   重启Apache测试

            [work@localhost modules]$ su -c '/home/work/usr/local/apache2/bin/apachectl restart'

            打开浏览器,分别通过以下两个地址访问jsp文件,如果均能正常解析表示整合成功,根据之前Apache和Tomcat的配置,test指向同一个目录

            http://localhost/test/

            http://localhost:8080/test/

            这样,Apache与Tomcat加Jk_mod就整理完成了

            如果遇到问题的话 ,就查看apache和jk_mod的log信息,一般都可以解决           

            配置文件详解:

            http://tomcat.apache.org/connectors-doc/reference/apache.html

SETP 5 安装PHP

            1  先要安装zlib,libpng和libxml、gd2库等,以便支持图形库等,可以根据需要来选装。

                    下载地址:

                    1)zlib:                    http://www.zlib.net/

                    2)libpng:             http://www.libpng.org/pub/png/libpng.html

                    3)libxml2:             ftp://xmlsoft.org/libxml2/

                    4)libtiff:             ftp://ftp.remotesensing.org/pub/libtiff/

                    5)jpegsrc:             ftp://ftp.uu.net/graphics/jpeg/

                    6)freetype2:     http://freetype.sourceforge.net/download.html

                    7)gd2:                     http://www.libgd.org/Downloads

                    8)openssl:            http://www.openssl.org/source/

                   

                    这几个PHP的库安装方式都是一致的,命令如下:

                    ./configure [--prefix=/path]

                    make check

                    make install

                    1.1  zlib安装:

                    [work@localhost php_lib]$ tar -zxvf zlib-1.2.3.tar.gz

                    [work@localhost php_lib]$ cd zlib-1.2.3

                    [work@localhost zlib-1.2.3]$ ./configure --prefix=/home/work/usr/local/zlib/

                    [work@localhost zlib-1.2.3]$ make

                    [work@localhost zlib-1.2.3]$ make install

                    1..2  libpng安装:

                    [work@localhost php_lib]$ tar -zxvf libpng-1.2.29.tar.gz

                    [work@localhost php_lib]$ cd libpng-1.2.29

                    [work@localhost libpng-1.2.29]$ ./configure --prefix=/home/work/usr/local/libpng

                    [work@localhost libpng-1.2.29]$ make

                    [work@localhost libpng-1.2.29]$ make install

                   

                    1.3  libxml2安装:

                    [work@localhost php_lib]$ tar -zxvf libxml2-2.6.32.tar.gz

                    [work@localhost php_lib]$ cd libxml2-2.6.32

                    [work@localhost libxml2-2.6.32]$ ./configure --prefix=/home/work/usr/local/libxml2

                    [work@localhost libxml2-2.6.32]$ make

                    [work@localhost libxml2-2.6.32]$ make install                   

                    1..4  libtiff安装:

                    [work@localhost php_lib]$ tar -zxvf tiff-4.0.0beta2.tar.gz

                    [work@localhost php_lib]$ cd tiff-4.0.0beta2

                    [work@localhost tiff-4.0.0beta2]$ ./configure --prefix=/home/work/usr/local/tiff

                    [work@localhost tiff-4.0.0beta2]$ make

                    [work@localhost tiff-4.0.0beta2]$ make install   

                    1.5  jpegsrc安装:

                    [work@localhost php_lib]$ tar -zxvf jpegsrc.v6b.tar.gz

                    [work@localhost php_lib]$ cd jpeg-6b/

                    [work@localhost jpeg-6b]$ ./configure --prefix=/home/work/usr/local/jpeg/ --enable-shared --enable-static

                    [work@localhost jpeg-6b]$ make

                    [work@localhost jpeg-6b]$ make install

                    (提示/home/work/usr/local/jpeg/没有bin/cjpeg和man文件夹,根据提示来分别创建即可,再执行make instal就ok了

                    [work@localhost jpeg-6b]$ mkdir /home/work/usr/local/jpeg/bin/

                    [work@localhost jpeg-6b]$ mkdir /home/work/usr/local/jpeg/bin/cjpeg

                    [work@localhost jpeg-6b]$ mkdir /home/work/usr/local/jpeg/man/)

                    1.6  FreeType安装:

                    [work@localhost php_lib]$ tar -zxvf freetype-2.3.6.tar.gz

                    [work@localhost php_lib]$ cd freetype-2.3.6/

                    [work@localhost freetype-2.3.6]$ ./configure --prefix=/home/work/usr/local/freetype2

                    [work@localhost freetype-2.3.6]$ make

                    [work@localhost freetype-2.3.6]$ make install

                    1.7  gd2安装:

                    [work@localhost php_lib]$ tar -jxvf gd-2.0.35.tar.bz2

                    [work@localhost php_lib]$ cd gd-2.0.35

                    [work@localhost gd-2.0.35]$ ./configure --prefix=/home/work/usr/local/gd2 \

                                                                                                 --with-zlib=/home/work/usr/local/zlib/ \

                                                                                                 --with-png=/home/work/usr/local/libpng/ \

                                                                                                 --with-jpeg=/home/work/usr/local/jpeg/ \

                                                                                                 --with-freetype=/home/work/usr/local/freetype2/

                    [work@localhost gd-2.0.35]$ make

                    [work@localhost gd-2.0.35]$ make install

                    1.8  openssl安装:

                    [work@localhost php_lib]$ tar -zxvf openssl-0.9.8g.tar.gz (这里有很多版本,可以选择一个比较稳定的版本)

                    [work@localhost php_lib]$ cd openssl-0.9.8g

                    [work@localhost openssl-0.9.8g]$ ./config --prefix=/home/work/usr/local/openssl --openssldir=/home/work/usr/local/openssl shared

                    [root@localhost openssl-0.9.8g]# make

                    [root@localhost openssl-0.9.8g]# su -c 'make install'

                    [root@localhost openssl]# cd /home/work/usr/local/openssl/

                    [root@localhost openssl]# chown -R work:work openssl

            2  执行PHP安装

                    2.1  解压缩PHP包,仔细阅读INSTALL文件,按照提示安装

                    [work@localhost webServer]$ tar -jxvf php-5.2.6.tar.bz2

                    [work@localhost webServer]$ cd php-5.2.6

                    [work@localhost php-5.2.6]$ cat INSTALL

                   

                    2.2  执行安装,在命令行如,除apache和mysql,gd库,其他可以选装:

                    ./configuare --prefix=/home/work/usr/local/php5 --enable-so \

                                                         --with-apxs2=/home/work/usr/local/apache2/bin/apxs \ #高版本要写成apxs2.安装前将apache停掉。

                                                         --with-mysql=/home/work/usr/local/mysql \

                                                         --with-gd=/home/work/usr/local/gd2 \

                                                         --with-zlib=/home/work/usr/local/zlib \

                                                         --with-png-dir=/home/work/usr/local/libpng \

                                                         --with-libxml-dir=/home/work/usr/local/libxml2 \

                                                         --with-jpeg-dir=/home/work/usr/local/jpeg \

                                                         --with-tiff-dir=/home/work/usr/local/tiff \   

                                                         --with-freetype-dri=/home/work/usr/local/freetype2 \   

                                                         --with-openssl=/home/work/usr/local/openssl   

                    可以复制下面的命令去修改:

                    [work@localhost php-5.2.6]$ ./configure --prefix=/home/work/usr/local/php5 --with-apxs2=/home/work/usr/local/apache2/bin/apxs --with-mysql=/home/work/usr/local/mysql --with-gd=/home/work/usr/local/gd2/ --with-zlib=/home/work/usr/local/zlib/ --with-png-dir=/home/work/usr/local/libpng/ --with-libxml-dir=/home/work/usr/local/libxml2/ --with-jpeg-dir=/home/work/usr/local/jpeg/ --with-tiff-dir=/home/work/usr/local/tiff/ --with-freetype-dir=/home/work/usr/local/freetype2/ --with-openssl=/home/work/usr/local/openssl/

                    会有信息提示,如下表示安装成功,如果有错误提示,按照提示去查找原因

                    ……

                    Thank you for using PHP.

                    ……

                    [work@localhost php-5.2.6]$ make

                    [work@localhost php-5.2.6]$ make test    # 按推荐先测试一下

                    [work@localhost php-5.2.6]$ make install           

                    2.3  执行安装时遇到一个错误,按建议先测试下,出现如下错误

                    /home/work/usr/local/mysql/lib/libmysqlclient.so.15: cannot restore segment prot after reloc: Permission denied

                    搜索查了一下,网上有很多类似的问题。    解决方案如下:

                    1)   禁用 SELinux

                    [root@localhost webServer]# vi /etc/selinux/config

                    编辑/etc/selinux/config,把 SELINUX=enforcing注释掉,然后新加一行SELINUX=disabled

                    [root@localhost webServer]# vim /etc/sysconfig/selinux

                    编辑/etc/sysconfig/selinux,把SELINUX=enforcing注释掉,新加一行SELINUX=disabled

                    2) chcon -t texrel_shlib_t

                    [work@localhost ~]$ chcon -t texrel_shlib_t /home/work/usr/local/mysql/lib/libmysqlclient.so.15

(/路径/路径/文件名.so)

                    参考:

                    http://linux.chinaunix.net/bbs/thread-1001717-1-1.html

                    http://www.phpwhy.com/read-htm-tid-5317.html

                    http://bbs.chinaunix.net/viewthread.php?tid=1033055

                    2.4  复制php.ini文件(这里的PHP安装在work目录下,默认PHP安装在/usr/local/下,那样就把php.ini复制到/usr/local/lib/下)

                    [work@localhost php-5.2.6]$ cp php.ini-dist /home/work/usr/local/php5/lib/php.ini

            3  修改Apache里的http.conf文件,整合PHP与Apache

                    [work@localhost php-5.2.6]$ vi /home/work/usr/local/apache2/conf/httpd.conf

                    查看是否有:LoadModule php5_module modules/libphp5.so

                    添加以下到<IfModule mime_module>中

                    AddType application/x-httpd-php .php

                    AddType application/x-httpd-php-source .phps  

                    启动Apache:

                    提示:……libphp5.so: cannot restore segment prot after reloc: Permission denied                   

                    [work@localhost php-5.2.6]$ chcon -t texrel_shlib_t /home/work/usr/local/apache2/modules/libphp5.so

                    [work@localhost php-5.2.6]$ su -c '/home/work/usr/local/apache2/bin/apachectl start'

                    [work@localhost php-5.2.6]$ ps -ef | grep httpd

           4 测试               

                    41.  新建一个info.php文件,放到原来建好的test项目里

                    <?php

                            echo phpinfo();

                    ?>

                    用浏览起访问,能看见php相关信息,表示成功安装。

                    42.  如果遇到禁止访问的提示

                    Forbidden

                    You don't have permission to access / on this server

                    则有几种可能:

                            1)   没有给文件授权。 通过 $ chmod 777 xxx.html授权

                            2)  看Apache http.conf里的DocumentRoot修改了,而<Directory 没有指定路径或者Deny from all,而不是Allow from All

                            3)  编辑http.conf文件,修改用户和组

                                    #User daemon 改成你自己的用户    User work

                                    #Group daemon 改成你自己的用户     Group work

                            4)  chcon -t texrel_shlib_t 相关文件,参考上面安装PHP的步骤。

                           

            5   连接mysql,建立一个connect.php文件,输入以下代码,测试能否看到效果。

                   <pre>

                    <?php

                    $conn = mysql_connect("localhost", "root", "password");

                          if ($conn) {

                              echo "Mysql Connect Successfully!";

                            } else {

                              echo "Mysql Connect Failed!";

                          }

                    mysql_select_db("mysql",$conn);

                    $query = mysql_query("SELECT * FROM `user`", $conn);

                   while($result = mysql_fetch_array($query)) {

                           print_r($result);

                         }

                    mysql_free_result($query);

                    ?>

                    </pre>

                    如果能看到Mysql Connect Successfully!表示连接成功了。

至此,一个Linux下的支持Java、PHP的完整Web Server就全部配置完成了,安装过程其实是非常简单的,只是需要细心的一点,严格按步骤去做,记住一定要参照readme和install文件。

参考:

Jdk1.6+Tomcat6+Apache2+jk_mod1.2+PHP5+MySql5安装与配置详解 http://jiarry.bokee.com/6738182.html (windows)

安装Jdk+Tomcat+Apache+PHP+MySql (Linux) 详细介绍  http://jiarry.bokee.com/2425368.html

           

几个命令,安装时需要用到:

1..下载文件: wget URL

2.  压缩:tar —zxvf 文件名(.tar 或 .tar.gz) tar —jxvf 文件名(.tar.bz2)

3.  拷贝:cp 文件名 或 cp —Rf 文件夹名

4.  删除:rm 文件名 或 rm —Rf 文件夹名

5.  编辑文件命令:vi 文件名   ,   q!(不保存退出) : wq(保存退出)

6.  授权 chmod 777 * (文件名或者文件夹,支持通配符)

7.  更改用户权属  chown -R 用户 .

8.  更改用户组   chgrp -R 用户 .

9. 切换用户  su 用户

10. 用root执行命令  su -c “命令”

11. 查看mysql进程,如 ps -el | grep mysqld

JarryLi in Beijing 2008

contact: jarryli(@)gmail.com


你可能感兴趣的:(apache,jdk,tomcat,mysql,PHP,linux)