Mac OSX 下整合 Apache 和 Tomcat

Tomcat,
XAMPP, and mod_jk

I recently upgraded to Snow Leopard (more on that later, it did not go so smoothly), and decided that rather than simply port my existing web development stack (which was rickety), I would try to build something clean and new that has all the features
I need without eating all my available system resources.

My primary goal was to distance myself as much as possible from OS X’s flawed *AMP stack. Why flawed? Well, out-of-the-box, OS X doesn’t have MySQL, so you have to download, install, and manage that separately—a small pain in the ass, but a pain
in the ass nonetheless. Further, the OS X compile of PHP is unnecessarily hobbled by a lack of image manipulation modules and is a missing the PDO module for MySQL. The last time I checked, it’s impossible to recompile PHP for OS X 10.5, which means that image
manipulation is right out and installing PDO becomes far more difficult. I spent a weekend wrestling with recompiling MySQL with development headers just so I could build the PDO module for OS X and plug it in. Without PDO, my PHP object-relational mapper
of choice (Doctrine PHP) simply won’t work.

My secondary goal is to have something that handles Tomcat Java server gracefully. In the past, I’ve spent a lot of time futzing about with settings to make Tomcat less of a resource-devouring monster, as well as integrating it more seamlessly with
my local development environment. In general, I don’t appreciate appending a port number to the end of my URLs, and starting every new Java project with localhost:8080 seems like getting started with the wrong foot forward.

The tool to glue Apache and Tomcat together is mod_jk, a module that allows you to virtual host Tomcat webapps on your Apache server. I’ve played around with loading it with the OS X version of Apache in the past, but I never really got it working
on my mac before. There was always one more configuration thing I was missing before I gave up and got back to doing real work.

In the past, I’ve been very impressed by the XAMPP project for OS X. It’s a simple drop-in replacement for the boxed OS X *AMP stack and it has almost every module I could ever want for web development. It comes with its own installation of MySQL,
and both can be managed with a simple-but-robust control panel or a variety of shell scripts. Further, the files are laid out very simply in the xamppfiles directory, which makes it easy to find the configuration or log file that I’m looking for. It also means
that if I want to get rid of XAMPP, I can be reasonably sure that it will be gone when I delete it from my Applications directory. Strangely, knowing I can cleanly delete a piece of software gives me confidence that it will operate correctly while it’s installed.

So, having settled on gluing XAMPP together with Tomcat via mod_jk, I set about downloading, installing, and stabbing at configuration files madly. The first thing I did was install XAMPP, which can be found at the Apache
Friends OS X
 page, and the latest version of Tomcat, which can be found at the Tomcat
Project
 page.

Tomcat

Tomcat comes in a tarball, which I extracted in my Downloads folder. I then kicked open Terminal and ran the following:

cd Downloads
mv Downloads/apache-tomcat-6.0.20 Tomcat
sudo mv Tomcat /Library/

Which places my Tomcat home directory in a place that’s easy to access when installing new webapps (new webapps will go in /Library/Tomcat/webapps). I also dragged the webapps directory into my sidebar for easy access. I then updated the tomcat-users.xml
file in /Library/Tomcat/conf/ to allow me access to the Tomcat manager:

<tomcat-users>
<role rolename="manager" />
<user username="tomcat" password="admin" roles="manager" />
</tomcat-users>

I can now log into the manager app with username/password of tomcat/admin. You should probably pick something else, as I eventually did.

After that, I had to make sure the startup and shutdown scripts that Tomcat uses were executable. I also removed the scripts written for other platforms that I wouldn’t be using:

cd /Library/Tomcat/bin
rm *.bat *.exe

The next step is to write a more-robust startup/shutdown script. I wrote a simple shell script that’s accessible to me wherever I am that allows me to start and stop Tomcat quickly. In /usr/local/bin I added a file called tomcat and gave it executable
privileges and opened my favorite text editor and added this inside it:

#!/bin/bash
case $1 in
start)
growlnotify -t "Tomcat" -m "Tomcat is starting up."
/Library/Tomcat/bin/startup.sh
;;
stop)
growlnotify -t "Tomcat" -m "Tomcat is shutting down."
/Library/Tomcat/bin/shutdown.sh
;;
restart)
growlnotify -t "Tomcat" -m "Tomcat is restarting."
/Library/Tomcat/bin/shutdown.sh
/Library/Tomcat/bin/startup.sh
;;
*)
echo "Usage: tomcat [ start | stop | restart ]"
;;
esac

Note the calls to growlnotify. If you have Growl installed and went out of your way to install the extras, you can call growlnotify on the command line to fire off an attractive growl notification. This is very handy if you want to embed calls to
startup and shut down in other scripts (I often write a build script for java projects that shuts down Tomcat, installs the webapp, then starts Tomcat again). You can remove these lines if you aren’t interested in that, though. Save and close when you’re done—you’ll
probably need to give your admin password.

Now, from anywhere in Terminal, you can call tomcat start, tomcat stop, or tomcat restart and expect it to perform those actions properly. You can check if Tomcat is running by visiting http://localhost:8080/

mod_jk

Now we have XAMPP working, and Tomcat working, but we want them to be working together, listening on the same port, without stepping on each other’s toes. To do this, we first need to acquire and install mod_jk, configure it, and then create the
proper hostfile entry.

You can download mod_jk from the Apache
Tomcat Connector
 project page. Download the macosx version for your processor; it should be named something like mod_jk-VERSION-httpd-VERSION.so. Make sure you download the one that’s appropriate for your version of Apache; In my case, I downloaded the
httpd-2.2.4 version.

Rename the .so file to mod_jk.so and place it in /Applications/XAMPP/xamppfiles/modules.

The next step is getting mod_jk configured properly. To do this, we’re going to create a new configuration file in /Applications/XAMPP/xamppfiles/etc/extras called httpd-modjk.conf. In it, add the following:

LoadModule jk_module modules/mod_jk.so
<IfModule jk_module>
# Where to put jk shared memory
JkShmFile     /Applications/XAMPP/xamppfiles/etc/mod_jk.shm
# Where to put jk logs
JkLogFile     /Applications/XAMPP/xamppfiles/logs/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] "
JkWorkerProperty worker.list=default
JKWorkerProperty worker.default.type=ajp13
JKWorkerProperty worker.default.host=localhost
JKWorkerProperty worker.default.port=8009
</IfModule>
NameVirtualHost *:80
<VirtualHost *:80>
ServerName tomcat
ServerAdmin root@localhost
DocumentRoot "/Library/Tomcat/webapps"
ErrorLog "logs/tomcat-error_log"
CustomLog "logs/tomcat-access_log" common
JkMount /* default
</VirtualHost>

Then, somewhere near the end of your /Applications/XAMPP/xamppfiles/etc/httpd.conf add:

Include /Applications/XAMPP/etc/extra/httpd-modjk.conf

That will load the configuration file we just created.

The final step to get this all glued together involves editing your /etc/hosts file. Open it in your favorite text editor and add the following to the end of it:

127.0.0.1 tomcat

You should now be able to start up Tomcat (using tomcat start on the command line), start Apache (with XAMPP), and browse to http://tomcat/ and see the Tomcat welcome page.

时间: 2024-10-26 16:13:56

Mac OSX 下整合 Apache 和 Tomcat的相关文章

整合apache和tomcat构建Web服务器

linux是最常用的web服务器,本节我们将通过整合apache和tomcat构建一个java/jsp运行平台,详细介绍web服务器的搭建过程. 一.apache与tomcat整合的必要性 Apache是最流行的Web服务器,开放源代码,支持跨平台的应用(可以运行在几乎所有的Linux.Unix.Windows系统平台上),尤其对Linux的支持相当完美. apache的优点有: 功能强大,apache自带了很多功能模块,可根据需求编译自己需要的模块. 配置简单,apache的配置文件非常简单,

Jsp和PHP共用80端口整合Apache和Tomcat(访问时无需加端口号)_JSP编程

目的: 整合Apache和Tomcat,使得Java工程和PHP工程都能共用80端口,访问网站时,无需在地址栏中加端口号. 环境说明: Linux CentOS 32位 Apache 2.2.2 Tomcat 7.0.37 准备工作: 下载mod_jk.so http://archive.apache.org/dist/tomcat/tomcat-connectors/jk/binaries/ 打开链接找到合适的文件下载,下载后改名为mod_jk.so 修改Apache相关文件 1.将mod_j

Mac OSX 下的快捷锁屏畅想曲

Mac OSX 下的快捷锁屏畅想曲 太阳火神的美丽人生 (http://blog.csdn.net/opengl_es) 本文遵循"署名-非商业用途-保持一致"创作公用协议 转载请保留此句:太阳火神的美丽人生 -  本博客专注于 敏捷开发及移动和物联设备研究:iOS.Android.Html5.Arduino.pcDuino,否则,出自本博客的文章拒绝转载或再转载,谢谢合作. 熟练使用 Windows 后,很容易就能想到 Win + L 刷屏,拿鼠标能干的活都是细致活,键盘虽然粗犷,确

linux下整合Apache+subversion加载mod_dav_svn.so报错

问题描述 linux下整合Apache+subversion加载mod_dav_svn.so报错 报错信息: httpd: Syntax error on line 219 of /etc/httpd/conf/httpd.conf: Cannot load /etc/httpd/modules/mod_dav_svn.so into server: /usr/local/subversion/lib/libsvn_subr-1.so.0: undefined symbol: apr_hash_

在Windows Server下集成Apache、Tomcat和IIS

我在<Perl.PHP.ASP.JSP技术比较>一文中曾经对四种流行的网站设计语言进行了评测和对比,常言道鱼与熊掌皆我所欲,两者不可兼得,那么有没有一种方法,可以做到鱼与熊掌兼得,同时支持这四种语言的Web服务器呢,今天我就介绍一下基于Windows Server 2003的同时在一个80端口支持这四种语言的方法. 我们的策略是:安装三个Web服务器,Apache负责支持perl和php,IIS负责支持asp,Tomcat负责支持jsp,通过Apache的proxy_module将三个服务器集

Linux下配置apache与Tomcat连接

Apache http server与tomcat同属于apache基金会,两者都可以提供Web服务,只不过两者的侧重点不同.http server侧重用作web服务器,而tomcat则侧重于作为轻量级的应用服务器.同时,两者也可以结合 起来使用,即可以将动态请求通过http server转发至后端的tomcat来完成,http server只处理静态请求.本文描述了如何配置apache与tomcat连接. 一.Tomcat连接器架构及协议 1.Tomcat连接器架构 基于Apache做为Tom

Hadoop - Mac OSX下配置和启动hadoop以及常见错误解决

0. 安装JDK 参考网上教程在OSX下安装jdk   1. 下载及安装hadoop a) 下载地址: http://hadoop.apache.org   b) 配置ssh环境 在terminal里面输入: ssh localhost 如果有错误提示信息,表示当前用户没有权限.这个多半是系统为安全考虑,默认设置的. 更改设置如下:进入system preference --> sharing --> 勾选remote login,并设置allow access for all users.

linux下集成apache和tomcat时可能用到的命令

在apache2和tomcat5集成的环境下,通常会把静态文件(如shtml文件)存放在apache的目录下,而动态文件则存在在tomcat的管辖范围内,因为开发过程中并没有将这两类文件分开,所以在访问静态文件是就需要做个映射. 假设集成环境中,装有apache2的机器在局域网中的地址为192.168.1.55,下面简称55:装有tomcat5的机器的地址为192.168.1.66,后面简称66 那么在55中需要提供的是NFS服务: 在/etc/exports中添加如下语句: {apache2_

Mac Yosemite下安装Apache+PHP+MySQL+Memcached环境笔记

为了安装方便,需要注意几个小细节. 最好是安装了xcode之后再来安装此环境 Mac OS X 10.10 Yosemite 自带PHP5.5和Apache2.4做相应修改即可. Mac先安装所需工具 MacPort的下载:http://www.macports.org/ 下载安装port ,如果开有终端,记得安装完成后退出终端哟 安装GNU autotools: 要安装autotools需要如下几个文件 automake autoconf M4 安装顺序是M4 -> autoconf ->