欢迎您访问程序员文章站本站旨在为大家提供分享程序员计算机编程知识!
您现在的位置是: 首页  >  后端开发

主机同时运行JSP和PHP

程序员文章站 2022-05-12 14:39:32
...
单位需要上一个php项目,但只有一个域名,服务器操作系统是redhat 4.7,已经布署了tomcat,重做或合并都不可能,但又必须共用一台主机,想到了用apache http server,用jk和tomcat连接,安装了php和mysql,前后花了不少时间,总算成功了,现记录如下:
1、redhat4.7安装yum
redhat4.7默认没有安装yum,用yum安装软件确实比rpm方便,依赖性不用考虑,但有时也有找不到包的时候。
redhat5默认已安装了yum,只需直接配置就可以了
下载 yum wget http://www.parallels.com.cn/downloads/Prima/Tools/yum_forAS4.tar.gz
解压 tar xzvf yum_forAS4.tar.gz
进入目录 cd yum_forAS4 #
安装 rpm -ivh *.rpm
cd /etc/yum.repos.d/
vi CentOS-Base.repo
# CentOS-Base.repo
[base]
name=CentOS-4.7 - Base - mirrors.ustc.edu.cn
baseurl=http://vault.centos.org/4.7/os/$basearch/
gpgcheck=1
gpgkey=http://vault.centos.org/RPM-GPG-KEY-CentOS-4
#released updates
[updates]
name=CentOS-4.7 - Updates - mirrors.ustc.edu.cn
baseurl=http://vault.centos.org/4.7/updates/$basearch/
gpgcheck=1
gpgkey=http://vault.centos.org/RPM-GPG-KEY-CentOS-4
#additional packages that may be useful
[extras]
name=CentOS-4.7 - Extras - mirrors.ustc.edu.cn
baseurl=http://vault.centos.org/4.7/extras/$basearch/
gpgcheck=1
gpgkey=http://vault.centos.org/RPM-GPG-KEY-CentOS-4
#packages used/produced in the build but not released
[addons]
name=CentOS-4.7 - Addons - mirrors.ustc.edu.cn
baseurl=http://vault.centos.org/4.7/addons/$basearch/
gpgcheck=1
gpgkey=http://vault.centos.org/RPM-GPG-KEY-CentOS-4
#additional packages that extend functionality of existing packages
[centosplus]
name=CentOS-4.7 - Plus - mirrors.ustc.edu.cn
baseurl=http://vault.centos.org/4.7/centosplus/$basearch/
gpgcheck=1
enabled=0
gpgkey=http://vault.centos.org/RPM-GPG-KEY-CentOS-4
#contrib - packages by Centos Users
[contrib]
name=CentOS-4.7 - Contrib - mirrors.ustc.edu.cn
baseurl=http://vault.centos.org/4.7/contrib/$basearch/
gpgcheck=1
enabled=0
gpgkey=http://vault.centos.org/RPM-GPG-KEY-CentOS-4

yum makecache
yum安装完成,以后就可以用yum -y install <包名> 命令来安装软件,这还是非常方便的。

2、安装apache,php,mysql
yum -y install httpd httpd-devel php mysql mysql-server php-mysql httpd-manual mod_ssl mod_perl mod_auth_mysql php-mcrypt php-gd php-xml php-mbstring php-ldap php-pear php-xmlrpc mysql-connector-odbc mysql-devel libdbi-dbd-mysql
用一个命令安装所有,php-mcrypt这个包没有装,在phpMyAdmin中会有警告,还是装上吧。
在http://rpm.pbone.net/上查找以下包:
libmcrypt-2.5.7-5.el4.i386.rpm
php-common-5.3.10-2.el4.remi.i386.rpm
php-mcrypt-4.3.9-1.el4.i386.rpm
安装以上包。
apache 配置文件安装在/etc/httpd/conf,WEB目录安装了/var/www/
启动: service httpd start
停止: service httpd stop
mysql 启动 service mysqld start 停止 service mysql stop
设置mysql 帐号和密码(略)

3、编译安装tomcat connectors
wget tomcat-connectors-1.2.37-src.tar.gz
cd tomcat-connectors-1.2.37-src
cd native
仔细阅读BUILDING.txt文件,文中提到需要apxs,这个程序是httpd-devel包中安装的
查找apxs的位置,使用
rpm -ql httpd-devel
...
/usr/sbin/apxs
...
其实apache http server 的可执行文件都放在/usr/sbin/目录下,该目录在PATH环境变量中的。
./configure --with-apxs=/usr/sbin/apxs
make
在当前目录下生成了apache-1.3 和apache-2.0两个目录,我们用的是apache2.0
cd apache-2.0
cp mod_jk.so /etc/httpd/modules/

4、配置jk.
(1)创建workers.properties配置文件
cd /etc/httpd/conf
vi workers.properties

# Define 1 real worker using ajp13
worker.list=worker1
# Set properties for worker1 (ajp13)
worker.worker1.type=ajp13
worker.worker1.host=localhost
worker.worker1.port=8009

(2)编辑httpd.conf
在加载模块段落下加入以下行

# Load mod_jk module
# Update this path to match your modules location
LoadModule    jk_module  modules/mod_jk.so
# Where to find workers.properties
# Update this path to match your conf directory location (put workers.properties next to httpd.conf)
JkWorkersFile /etc/httpd/conf/workers.properties
# Where to put jk shared memory
# Update this path to match your local state directory or logs directory
JkShmFile     /var/log/httpd/mod_jk.shm
# Where to put jk logs
# Update this path to match your logs directory location (put mod_jk.log next to access_log)
JkLogFile     /var/log/httpd/mod_jk.log
# Set the jk log level [debug/error/info]
JkLogLevel    info
# Select the timestamp log format
JkLogStampFormat "[%a %b %d %H:%M:%S %Y] "
# Send everything for context /examples to worker named worker1 (ajp13)
JkMount  /examples/* worker1

重启apache

测试:
用tomcat的端口可以访问,用apache的端口同样也可发访问同样的内容。
如果用防火墙,要记得把lo的8009端口打开
-A INPUT -i lo -p tcp -m tcp --dport 8009 -j ACCEPT
好了,放在这里,下次配置就不会找不到了。