Linux 下安装支持 JSP/PHP 的 WEB server

发表于:2007-07-04来源:作者:点击数: 标签:
0. 综述\r 0.1 目标\r 在 Linux 平台上安装一个支持 SSL、URL 重写、反向代理、页面压缩、CGI、PHP、JSP 的 免费 WEB 服务器 \r 0.2 许可协议\r GNU Free Documentation License http://www.gnu.org/licenses/fdl.html 允许任意转载,但请保持本文档的完整性
0. 综述\r
0.1 目标\r
在 Linux 平台上安装一个支持 SSL、URL 重写、反向代理、页面压缩、CGI、PHP、JSP 的 免费 WEB 服务器\r

0.2 许可协议\r
GNU Free Documentation License http://www.gnu.org/licenses/fdl.html
允许任意转载,但请保持本文档的完整性
如有修改,务请通知作者

0.3 作者
钝刀 webmaster@yufeng.net

1. 下载
1.1 Apache http://www.apache.org/dist/httpd/
1.2 PHP http://www.php.net/downloads.php
1.3 Tomcat http://www.apache.org/dist/jakarta/tomcat-4/
1.4 JTC(jakarta tomcat connectors) http://www.apache.org/dist/jakarta/tomcat-4/source/

2. 安装
2.1 Apache
$tar vfxz httpd-2.0.46.tar.gz
$cd httpd-2.0.46
$./configure \
$--enable-so \
$--enable-ssl=shared \
$--enable-rewrite=shared \
$--enable-proxy=shared \
$--enable-deflate=shared \
$--with-mpm=worker \
$--prefix=/www/server/apache2
$make
$make install
#--enable-so 要使用 JK2 连接 Tomcat,必须让 apache2 支持模块动态加载
#--enable-ssl=shared 支持 SSL
#--enable-rewrite=shared 支持 URL 重写
#--enable-proxy=shared 支持代理\r
#--enable-deflate=shared 支持网页压缩\r
#--with-mpm=worker 采用worker的mpm方式运行
#--prefix=/www/server/apache2 安装目录

2.2 PHP
$tar vfxz php-4.3.2.tar.gz
$cd php-4.3.2
$./configure \
$--with-apxs2=/www/server/apache2/bin/apxs \
$--prefix=/www/server/php
$make
$make install
$cp php.ini-dist /usr/local/lib/php.ini
#--with-apxs2=/www/server/apache2/bin/apxs 作为 apache2 的模块编译\r
#--prefix=/www/server/php 安装目录,并没有太大作用

2.3 Tomcat
$tar vfxz jakarta-tomcat-4.1.24.tar.gz
$cp -R jakarta-tomcat-4.1.24 /www/server/
$ln -s /home/data/www/jakarta-tomcat-4.1.24 /home/data/www/tomcat

2.4 JTC
#编译错误请参考下文处理\r
$lynx http://www.pubbitch.org/jboss/mod_jk2.html
$tar vfxz jakarta-tomcat-connectors-4.1.24-src.tar.gz
$cd jakarta-tomcat-connectors-4.1.24-src

#以下两步如果没有编译错误不需要做\r
$cp /usr/java/j2sdk1.4.1_02/include/linux/jni_md.h /usr/java/j2sdk1.4.1_02/include/
$ln -s /www/server/apache2/lib/libapr-0.so /www/server/apache2/lib/libapr.so

#开始编译准备
$cd util
$cp build.properties.sample build.properties
$cd ../jk
$cp build.properties.sample build.properties
$vi build.properties
catalina.home=/www/server/tomcat
tomcat40.home=${catalina.home}
apache2.home=/www/server/apache2
#修改以上内容
$cd ../coyote
$cp build.properties.sample build.properties
$vi build.properties
catalina.home=/www/server/tomcat
#修改以上内容
$cd ../jk

#编译JK2
$ant native
$cp build/jk2/apache2/mod_jk2.so /www/server/apache2/modules

3. 配置
3.1 apache2/conf/httpd.conf
$vi /home/data/www/apache2/conf/httpd.conf
#禁用默认字符集
#AddDefaultCharset ISO-8859-1
#加载 JK2
LoadModule jk2_module modules/mod_jk2.so
#支持 PHP
AddType application/x-httpd-php .php

#支持页面压缩\r
SetOutputFilter DEFLATE
DeflateFilterNote ratio
SetEnvIfNoCase Request_URI \.(?:gif|jpe?g|png)$ no-gzip dont-vary
SetEnvIfNoCase Request_URI \.(?:exe|t?gz|zip|bz2|sit|rar)$ no-gzip dont-vary
SetEnvIfNoCase Request_URI \.pdf$ no-gzip dont-vary

#包含虚拟主机设置
Include conf/virtual_host.conf

3.2 apache2/conf/virtual_host.conf
$touch /www/server/apache2/conf/virtual_host.conf
$vi /www/server/apache2/conf/virtual_host.conf
NameVirtualHost 123.456.78.9:80
<VirtualHost 123.456.78.9:80>
DocumentRoot /www/host/www.domain.com/htdocs
ServerName www.domain.com
ServerAlias domain.com
ErrorLog /www/host/www.domain.com/logs/apache_error.log
CustomLog /www/host/www.domain.com/logs/apache_aclearcase/" target="_blank" >ccess.log common
</VirtualHost>
#反向代理的虚拟主机\r
<VirtualHost 123.456.78.9:80>
ServerName www2.domain.com
RewriteEngine on
ProxyRequests off
UseCanonicalName off
RewriteRule ^/(.*)$ http://192.168.0.1/$1 [P,L]
</VirtualHost>

3.3 apache2/conf/ssl.conf
$vi /www/server/apache2/conf/ssl.conf
NameVirtualHost 123.456.78.9:443
<VirtualHost 123.456.78.9:443>
DocumentRoot "/www/host/www.domain.com/htdocs"
ServerName www.domain.com
ServerAdmin webmaster@domain.com
ErrorLog /www/host/www.domain.com/logs/ssl_error.log
TransferLog /www/host/www.domain.com/logs/ssl_access.log
SSLCertificateFile /www/host/www.domain.com/server.crt
SSLCertificateKeyFile /www/host/www.domain.com/server.key
SSLCertificateChainFile /www/ca.crt
CustomLog /www/host/www.domain.com/logs/ssl_request.log \
"%t %h %{SSL_PROTOCOL}x %{SSL_CIPHER}x \"%r\" %b"
</VirtualHost>

3.4 apache2/conf/workers2.properties
$touch /www/server/apache2/conf/workers2.properties
$vi /www/server/apache2/conf/workers2.properties
[shm]
file=${serverRoot}/logs/shm.file
size=1048576

# Example socket channel, override port and host.
[channel.socket:example]
port=8009
host=127.0.0.1

# define the worker
[ajp13:example]
channel=channel.socket:example
#[status:status]

# Uri mapping
#[uri:/jkstatus/*]
#worker=status:status

# Uri mapping
[uri:/*.jsp]
worker=ajp13:example

#[uri:/examples/*]
#worker=ajp13:example

3.5 tomcat/conf/jk2.properties
$touch /www/server/tomcat/conf/jk2.properties
$vi /www/server/tomcat/conf/jk2.properties
# The default port is 8009 but you can use another one
# channelSocket.port=8019

3.6 tomcat/conf/web.xml
$vi /www/server/tomcat/conf/web.xml
<servlet>
<servlet-name>default</servlet-name>
<servlet-class>
org.apache.catalina.servlets.DefaultServlet
</servlet-class>
<init-param>
<param-name>debug</param-name>
<param-value>0</param-value>
</init-param>
<init-param>
<param-name>listings</param-name>
#此处重点,禁用目录列表\r
<param-value>false</param-value>
</init-param>
<load-on-startup>1</load-on-startup>
</servlet>

3.7 tomcat/conf/tomcat-users.xml
$vi /www/server/tomcat/conf/tomcat-users.xml
#增加tomcat的管理员
<user name="xxx" password="xxx" roles="manager" />

3.8 tomcat/conf/server.xml
$vi /www/server/tomcat/conf/server.xml
#设置虚拟主机\r
<Host name="www.domain.com"
debug="0"
appBase="/www/host/www.domain.com/webapps"
unpackWARs="true">
<Alias>crcchem.com</Alias>
<Logger className="org.apache.catalina.logger.FileLogger"
directory="/www/host/www.domain.com/logs"
prefix="catalina."
suffix=".log"
timestamp="true"/>
<Context path=""
docBase="/www/host/www.domain.com/htdocs"
debug="0"/>
</Host>

4. 测试
4.1 apache2
$touch /www/host/www.domain.com/htdocs/test.html
$vi /www/host/www.domain.com/htdocs/test.html
<h1>hello</h1>
$/www/server/apache2/bin/apachectl configtest
$/www/server/apache2/bin/apachectl startssl
$lynx http://www.domain.com/test.html

4.2 SSL
$lynx https://www.domain.com/test.html

4.3 反向代理\r
$lynx http://www2.domain.com/

4.4 PHP
$touch /www/host/www.domain.com/htdocs/test.php
$vi /www/host/www.domain.com/htdocs/test.php
<?phpinfo();?>
$lynx http://www.domain.com/test.php

4.5 JSP
touch /www/host/www.domain.com/htdocs/test.jsp
$vi /www/host/www.domain.com/htdocs/test.jsp
<%=new java.util.Date();%>
$lynx http://www.domain.com/test.jsp


原文转自:http://www.ltesting.net