免费注册 查看新帖 |

Chinaunix

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

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

论坛徽章:
0
跳转到指定楼层
1 [收藏(0)] [报告]
发表于 2009-12-08 15:58 |只看该作者 |倒序浏览
apache+php+jsp+mysql整合
系统软件:
Linux  2.6.9-89.ELsmp
httpd-2.2.6
mysql-5.0.20a
php-5.2.5
mysql-connector-java-5.0.8.tar.tar
jdk-1_5_0_11
resin-3.1.6                       ---下载地址
http://www.caucho.com/download/
强烈建议停掉系统默认自带的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
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
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/
+--------------------------------------------------------------------+
| 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-17 21:50:40

=====================================================================
TEST RESULT SUMMARY
---------------------------------------------------------------------
Exts skipped    :   55
Exts tested     :   24
---------------------------------------------------------------------

Number of tests : 4566              3007
Tests skipped   : 1559 ( 34.1%) --------
Tests warned    :    0 (  0.0%) (  0.0%)
Tests failed    :   10 (  0.2%) (  0.3%)
Tests passed    : 2997 ( 65.6%) ( 99.7%)
---------------------------------------------------------------------
Time taken      :  200 seconds
=====================================================================

=====================================================================
FAILED TEST SUMMARY
[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的数据的现象
[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、安装resin-3.1.8
[root@jieli software]# tar -zxvf  resin-3.1.8.tar.gz
  inflating: resin-3.1.8/xsd/web-xml-j2ee.xsd  
  inflating: resin-3.1.8/xsd/web-xml-javaee.xsd  
  inflating: resin-3.1.8/xsd/xml.xsd  
  inflating: resin-3.1.8/xsd/xsi.xsd  
[root@jieli software]# mv resin-3.1.8 /webapp/db/resin
[root@jieli resin]# ./configure --prefix=/webapp/db/resin --with-apxs=/webapp/www/apache/bin/apxs --with-apache=/webapp/www/apache/
config.status: creating modules/c/src/resin_os/Makefile
config.status: creating contrib/init.resin
config.status: executing depfiles commands
[root@jieli resin]# make
o -lpthread -lc
make[2]: Leaving directory `/webapp/db/resin/modules/c/src/resin_os'
make[1]: Leaving directory `/webapp/db/resin/modules/c/src'
[root@jieli resin]# make install
  cp conf/resin.conf /webapp/db/resin/conf/resin.conf.orig; \
  cp conf/app-default.xml /webapp/db/resin/conf/app-default.xml.orig; \
  if test ! -r /webapp/db/resin/conf/resin.conf; then \
    cp conf/resin.conf /webapp/db/resin/conf/resin.conf; \
    cp conf/app-default.xml /webapp/db/resin/conf/app-default.xml; \
  fi; \
fi
[root@jieli conf]# pwd                 ----编译安装完resin后, httpd.conf里的最后会多出如下红色字体的模块文件
/webapp/www/apache/conf
# mod_caucho Resin Configuration
#

LoadModule caucho_module /webapp/www/apache/modules/mod_caucho.so

ResinConfigServer localhost 6800
CauchoConfigCacheDirectory /tmp
CauchoStatus yes
[root@jieli bin]# pwd
/webapp/db/resin/bin
[root@jieli bin]# ./httpd.sh start
Resin/3.1.8 started -server '' for watchdog at 127.0.0.1:6600
[root@jieli bin]# ps -ef|grep resin
root     25006     1 68 08:58 pts/2    00:00:01 /usr/java/jdk1.5.0_11/bin/java -Djava.util.logging.manager=com.caucho.log.LogManagerImpl -Djavax.management.builder.initial=com.caucho.jmx.MBeanServerBuilderImpl -Djava.awt.headless=true -Dresin.home=/webapp/db/resin/ -Dresin.root=/webapp/db/resin/ -Xrs -Xss256k -Xmx32m -Dcom.sun.management.jmxremote com.caucho.boot.WatchdogManager start
root     25026 25006 50 08:58 pts/2    00:00:00 /usr/java/jdk1.5.0_11/bin/java -Djava.util.logging.manager=com.caucho.log.LogManagerImpl -Djava.system.class.loader=com.caucho.loader.SystemClassLoader -Djavax.management.builder.initial=com.caucho.jmx.MBeanServerBuilderImpl -Djava.awt.headless=true -Dresin.home=/webapp/db/resin/ -Xmx256m -Xss1m -Xdebug -Dcom.sun.management.jmxremote -Djava.util.logging.manager=com.caucho.log.LogManagerImpl -Djavax.management.builder.initial=com.caucho.jmx.MBeanServerBuilderImpl -Djava.awt.headless=true -Dresin.home=/webapp/db/resin/ -Dresin.root=/webapp/db/resin/ -Dcom.sun.management.jmxremote -Djava.util.logging.manager=com.caucho.log.LogManagerImpl -Djavax.management.builder.initial=com.caucho.jmx.MBeanServerBuilderImpl -Djava.awt.headless=true -Dresin.home=/webapp/db/resin/ -Dresin.root=/webapp/db/resin/ -Dcom.sun.management.jmxremote com.caucho.server.resin.Resin --root-directory /webapp/db/resin/ -conf /webapp/db/resin/conf/resin.conf -socketwait 33835 start
然后在浏览器里输入
http://172.16.11.64:8080

http://172.16.11.64/caucho-status
进行测试,若发现如下两图,则说明resin可以单独运行成功

这个时候仍然是可以浏览html,但不能浏览php文件,如下图

7、整合apache+resin配置
[root@jieli conf]# pwd
/webapp/db/resin/conf
[root@jieli conf]# cp resin.conf resin.conf-bak
[root@jieli conf]# vi resin.conf
只需要修改如下红色字体即可
- webapp's ROOT
        -->
      

      
二、在/webapp/www/apache/htdocs下创建tianyu.jsp,里面内容如下
[root@jieli htdocs]# more tianyu.jsp
2 + 2 =
再在浏览器里
http://172.16.11.64/tianyu.jsp
若看到如下结果,则说明apache,resin整合成功
三、在/webapp/www/apache/htdocs下创建testdb.jsp,里面内容为如下,一定要注意里面的分号,括号要在英文输入法的前提下写进去,否则会各种怪错误的
[root@jieli htdocs]# more testdb.jsp
Test JDBC For MySQL
再在浏览器里输入
http://172.16.11.64/testdb.jsp
如果看到了一个没有任何错误信息的空白页面,就表示jsp连接本机的MySQL数据库成功了,至此我们就完成了一个支持
JSP+PHP+MySQL的Web服务器,测试结果如下图





php功能测试
1、wordpress2.8.4博客搭建
[root@jieli ~]# cd /webapp/www/apache/htdocs/
[root@jieli htdocs]# mkdir wordpress
然后将wordpress解压后的源代码放到该目录里,内容如下
[root@jieli wordpress]# ls
index.php           wp-comments-post.php  wp-feed.php        wp-rdf.php
license.txt         wp-commentsrss2.php   wp-includes        wp-register.php
readme.html         wp-config-sample.php  wp-links-opml.php  wp-rss.php
wp-admin            wp-config.php         wp-load.php        wp-rss2.php
wp-app.php          wp-config.php-bak     wp-login.php       wp-settings.php
wp-atom.php         wp-content            wp-mail.php        wp-trackback.php
wp-blog-header.php  wp-cron.php           wp-pass.php        xmlrpc.php
[root@jieli bin]# pwd
/webapp/db/mysql/bin
[root@jieli bin]# ./mysql -u root -p123456
Welcome to the MySQL monitor.  Commands end with ; or \g.
Your MySQL connection id is 63 to server version: 5.0.20a-log
Type 'help;' or '\h' for help. Type '\c' to clear the buffer.
mysql>create database wordpress;
mysql>grant all on wordpress.* to root;
mysql>grant all on  wordpress.* to
[email=root@localhost]root@localhost[/email]
;
mysql>grant all on  wordpress.* to jiajia;
mysql>grant all on  wordpress.* to
[email=jiajia@localhost]jiajia@localhost[/email]
;
mysql>grant all on  wordpress.* to
[email=jiajia@localhost]jiajia@localhost[/email]
identified by '123456';
[root@jieli bin]# useradd jiajia
[root@jieli bin]# passwd jiajia        --密码和数据库里创建的一样
在浏览器
http://172.16.11.64/wordpress
访问,然后按照向导进行安装即可
若安装的是英文的,则采用如下方法来修改语言
[root@jieli wp-content]# pwd
/webapp/www/apache/htdocs/wordpress/wp-content/
[root@jieli wp-content]# mkdir languages
先从网上下到wordpress-2.8.4的中文语言包,解压后里面会得到一个languages文件夹,里面包含了zh_CN.mo文件
然后将其上传到上面的/webapp/www/apache/htdocs/wordpress/wp-content/languages目录中
再修改
[root@jieli wordpress]# pwd
/webapp/www/apache/htdocs/wordpress
[root@jieli wordpress]# cp wp-config.php wp-config.php-bak
[root@jieli wordpress]# vi wp-config.php
* WordPress Localized Language, defaults to English.
*
* Change this to localize WordPress.  A corresponding MO file for the chosen
* language must be installed to wp-content/languages. For example, install
* de.mo to wp-content/languages and set WPLANG to 'de' to enable German
* language support.
*/
define ('WPLANG', 'zh_CN'); 修改成红色字体即可
最后重新访问
http://172.16.11.64/wordpress
,即可看到中文的界面,如下



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

本版积分规则 发表回复

  

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

清除 Cookies - ChinaUnix - Archiver - WAP - TOP