泰安uui 2008-1-25 20:35
编译安装apache2+php+mysql+mod_security
编译安装apache2+php+mysql+mod_security
#############
版权说明:
作者:hew 主页:[URL="http://www.linuxsky.net/"]http://www.linuxsky.net[/COLOR][/URL]
本文章可以任意转载,但请注明作者和出处,谢谢
#############
系统平台:maigic linux 2.0 rc1, magic linux 是中国linux公社开发一个社区版本linux,magic linux重点在于完美的中文桌面,所以如果诸位要做服务器的可以选择debian,redhat,suse等版本,个人推荐cenots 是rhel as 系列的免费实现 。
下载:
apache2
[url=http://www.apache.org/dist/httpd/httpd-2.0.55.tar.bz2]http://www.apache.org/dist/httpd/httpd-2.0.55.tar.bz2[/url]
mysql4:
[url=http://mysql.oss.eznetsols.org/Downloads/MySQL-4.1/mysql-4.1.15.tar.gz]http://mysql.oss.eznetsols.org/D ... mysql-4.1.15.tar.gz[/url]
php4:
[url=http://cn.php.net/distributions/php-4.4.1.tar.bz2]http://cn.php.net/distributions/php-4.4.1.tar.bz2[/url]
mod_security
[url=http://www.modsecurity.org/download/modsecurity-apache-1.9.tar.gz]http://www.modsecurity.org/download/modsecurity-apache-1.9.tar.gz[/url]
mysql 安装:
$ tar zxvf mysql-4.1.15.tar.gz
$ cd mysql-4.1.15
# groupadd mysql
# useradd -g mysql mysql
# ./configure --prefix=/usr/local/mysql
# make
# make install
# cp support-files/my-medium.cnf /etc/my.cnf
# cd /usr/local/mysql
# bin/mysql_install_db --user=mysql
# chown -R root .
# chown -R mysql var
# chgrp -R mysql .
# bin/mysqld_safe --user=mysql &
apache 2 安装:
$ tar jxvf httpd-2.0.55.tar.bz2
$ cd httpd-2.055
$ vi config.sh 写入内容如下:
[URL="http://www.im286.com/viewthread.php?tid=1175671&extra=page%3D1%26amp%3Bfilter%3Ddigest###"][Copy to clipboard][/COLOR][/URL]
CODE:
#!/bin/bash
HTTPD_ROOT="/apache2"
./configure --prefix=$HTTPD_ROOT \
--enable-so \
--enable-rewrite \
--enable-info \
--enable-cgid \
--enable-mime-magic \
--enable-alias \
--enable-access \
--enable-deflate \
--enable-forward
# sh config.sh
上面过程等同于直接
./configure --prefix=/apache2
--enable-so \
--enable-rewrite \
--enable-info \
--enable-cgid \
--enable-mime-magic \
--enable-alias \
--enable-access \
--enable-deflate \
--enable-forward
写一个config.sh 只是个人习惯方便今后查看和升级再编译。
# make
# make install
安装php4
$ tar jxvf php-4.4.1.tar.bz2
$ cd php-4.4.1
$ vi config.sh 写入内容:
[URL="http://www.im286.com/viewthread.php?tid=1175671&extra=page%3D1%26amp%3Bfilter%3Ddigest###"][Copy to clipboard][/COLOR][/URL]
CODE:
#!/bin/bash
PHP_ROOT=/apache2
./configure --prefix=$PHP_ROOT \
--with-apxs2=$PHP_ROOT/bin/apxs \
--with-mysql \
--enable-ftp \
--enable-zip \
--enable-mbstring \
--enable-mbregex \
--enable-calendar \
--enable-curl \
--disable-debug \
--enable-inline-optimization -q \
--with-jpeg \
--with-png \
--enable-thread-safety \
--enable-ctype \
--with-bz \
--with-zlib \
--with-gd \
--with-kerberos \
--with-gettext \
--enable-force-cgi-redirect
$ make
# make install
安装modsecurity(mod_security 可以加强apache的安全性特别是在防sql 注入上有很好的效果。):
$ tar zxvf modsecurity-apache-1.9.tar.gz
$ cd modsecurity-apache-1.9/apache2/
$ /apache2/bin/apxs -cia mod_security.c
配置:
1.编辑/etc/my.cnf
去掉[mysqld]段skip-networking这句的注释,这样mysql只能从本机连接,有助提高安全性。
2.编辑/apache/conf/httpd.conf
修改ServerAdmin [url=http://www.codeol.com/forum/mailto:you@example.com]you@example.com[/url] 将后面的mail 地址改为服务器管理员地址。
增加一个php 文件配置
AddType application/x-httpd-php .php
在DirectoryIndex 后增加一个 index.php
增加deflate 配置信息
[URL="http://www.im286.com/viewthread.php?tid=1175671&extra=page%3D1%26amp%3Bfilter%3Ddigest###"][Copy to clipboard][/COLOR][/URL]
CODE:
<Location />
# Insert filter
SetOutputFilter DEFLATE
# Netscape 4.x has some problems...
BrowserMatch ^Mozilla/4 gzip-only-text/html
# Netscape 4.06-4.08 have some more problems
BrowserMatch ^Mozilla/4\.0[678] no-gzip
# MSIE masquerades as Netscape, but it is fine
# BrowserMatch \bMSIE !no-gzip !gzip-only-text/html
# NOTE: Due to a bug in mod_setenvif up to Apache 2.0.48
# the above regex won't work. You can use the following
# workaround to get the desired effect:
BrowserMatch \bMSI[E] !no-gzip !gzip-only-text/html
# Don't compress images
SetEnvIfNoCase Request_URI \
\.(?:gif|jpe?g|png|ico)$ no-gzip dont-vary
# Make sure proxies don't deliver the wrong content
#Header append Vary User-Agent env=!dont-vary
</Location>
DeflateFilterNote ratio
LogFormat '"%v %h %l %u %t "%r" %>s %b "%{Referer}i" "%{User-Agent}i"" (%{ratio}n)' deflate
CustomLog logs/deflate_log deflate
添加一段mod_security的配置文件
[URL="http://www.im286.com/viewthread.php?tid=1175671&extra=page%3D1%26amp%3Bfilter%3Ddigest###"][Copy to clipboard][/COLOR][/URL]
CODE:
<IfModule mod_security.c>
SecFilterEngine On
SecFilterCheckURLEncoding On
SecFilterDefaultAction "deny,log,status:500"
#SecFilterForceByteRange 32 126
#SecFilterScanPOST On
SecAuditLog logs/audit_log
###
SecFilter "\.\./"
#####
SecFilter /etc/*passwd
SecFilter /bin/*sh
#for css attack
SecFilter "<( | )*script"
SecFilter "<(.| )+>"
#for sql attack
SecFilter "delete[ ]+from"
SecFilter "insert[ ]+into"
SecFilter "select.+from"
SecFilter "union[ ]+from"
SecFilter "drop[ ]"
</IfModule>
测试:
在/apache2/htdocs 创建文件test.php 内容为:
[URL="http://www.im286.com/viewthread.php?tid=1175671&extra=page%3D1%26amp%3Bfilter%3Ddigest###"][Copy to clipboard][/COLOR][/URL]
CODE:
<?php
echo phpinfo();
?>
在浏览器中打开 [url=http://127.0.0.1/test.php]http://127.0.0.1/test.php[/url] 如果你能看到 phpinfo 界面那么恭喜一切搞定。 :em03:
注:安装时请注意你是否已安装了足够的开发工具和库文件,如果安装失败请仔细检查configure.log。同时也要注意新版本Linux中SELinux 的限制,最简单办法是关闭SELinux,如果想自己定制请参考以下下文档:
Red Hat SELinux Guide
[url=http://www.linuxsky.net/down/rhel/docs/rhel-selg-en-4/]http://www.linuxsky.net/down/rhel/docs/rhel-selg-en-4/[/url]
其他在我服务器上使用的mod 介绍
Bandwidth Module 官方网站: [url=http://www.ivn.cl/apache/]http://www.ivn.cl/apache/[/url]
这是一个带宽限制工具可以针对虚拟主机或目录做限制。
mod_limitipconn 官方网站: [url=http://dominia.org/djao/]http://dominia.org/djao/[/url]
这个是一个针对目录的进程限制工具,这个mod 需要设置 “ExtendedStatus On“
Zend Optimizer官方主页: [url=http://www.zend.com]http://www.zend.com[/url]
大名鼎鼎的Zend Optimizer就不多说了,下载: [url=http://downloads.zend.com/optimizer/2.5.10/]http://downloads.zend.com/optimizer/2.5.10/[/url]
[url=http://www.xiugoo.com/bbs][color=white]情缘XIUGOO站长之家 网赚联盟 源码技术 [/color][/url]
[url=http://wpa.qq.com/msgrd?V=1&Uin=215453008&Site=源码在线论坛&Menu=yes][img]http://www.codeol.com/forum/images/Codeol/qq.gif[/img][/url]
lilingdong 2008-9-25 01:10
注:偶是女滴,千真万确,毋庸置疑!
yetengfeifei 2008-10-12 06:10
@,@..哇~~` 你是不是投胎滴时候走错地方啦~``
pre8 2008-10-18 12:10
大致看明白了,楼主的思维太过发散、太过跳跃了。楼主,加强集中精力叙述一件事情的能力。不要再发散了
klxqlqw 2008-11-13 03:40
偶学习的对像★:妖精‖→小瑶、爱海滔滔、峥婉儿、话裳、希★望、涛涛俊、为你伤心为你哭
xueseboss 2008-12-29 07:31
这篇帖子构思新颖,题材独具匠心,段落清晰,情节诡异,跌宕起伏,主线分明,引人入胜!