L.A.M.P 环境部署详细步骤

2007-01-06 00:45:21

本文所用的操作系统为 CentOS 3.8,如果使用 Red Hat AS3/4 则不能使用 yum RPM 包管理命令!PHPChina 开源社区门户4PhbKc3Qal
推荐使用 CentOS 3.8 系统。

%|RD&f Yv Z/k!d0PHPChina 开源社区门户b#e%]E)L6B4ATe
一、系统约定
软件源代码包存放位置
`:h-Se r_0
/usr/local/src
x pX!z IWCg0
源码包编译安装位置(prefix)PHPChina 开源社区门户p3A7pl*{%U{v}
/usr/local/software_namePHPChina 开源社区门户i"u;OEV3G
脚本以及维护程序存放位置PHPChina 开源社区门户 t$YSB \\r
/usr/local/sbin
0kuhJ!hG-P0
MySQL 数据库位置PHPChina 开源社区门户\+c7F~)M|HZ
/var/lib/mysql
*K'M~9NI:m/D0
Apache 网站根目录PHPChina 开源社区门户&Ad#T5I"Z0u} @[|
/data/wwwrootPHPChina 开源社区门户1@rd B LN[
Apache 虚拟主机日志根目录PHPChina 开源社区门户 qV:c'u)o1C4vD
/data/logs/www
$xrz@:u0\h0
Apache 运行账户PHPChina 开源社区门户Er!hZXOP
www:wwwPHPChina 开源社区门户9E7a R1NJV`s
yum RPM包信息文件PHPChina 开源社区门户#G$uH3Sw V2j-j!eR
/etc/yum.list
}$}l)m;p.U o@'|pu\0
PHPChina 开源社区门户$u] Xhf0S$tVg
二、系统环境部署及调整PHPChina 开源社区门户"Q"R7i%f(u,h+Na{
1. 检查系统是否正常PHPChina 开源社区门户yX'j l:W1Q!P`/v7~
   # more /var/log/messages   (检查有无系统内核级错误信息)PHPChina 开源社区门户5n*B@(y9C zd
   # dmesg (检查硬件设备是否有错误信息)PHPChina 开源社区门户'~(fC9o?u
   # ifconfig(检查网卡设置是否正确)
E+\H3R-H0   # ping www.163.com  (检查网络是否正常)PHPChina 开源社区门户_O O3@;sG aF

4FQN[;oK02. 关闭不需要的服务PHPChina 开源社区门户+~^6^iZfi
   # ntsysv
f u^ a c'?s#H0   以下仅列出需要启动的服务,未列出的服务一律关闭:
m,z"`3Ug0   crond
xK8U7`*\mx!K:x Q0   irqbalance (仅当服务器CPUS.M.P架构或支持双核心、HT技术时,才需开启,否则关闭。)
6n%s:_ D7ZVW0   microcode_ctlPHPChina 开源社区门户f`J-p-k
   network
6W G\)G gl|Hx0   randomPHPChina 开源社区门户f g B-U u2D&@%|
   sendmail
+~(\Kp!I$w O0   sshd
jte0]o#n]5O0   syslogPHPChina 开源社区门户 sS|?p6g1KnDP B4Y

VPA#S(M:f3Id{03. TCP/IP网络参数进行调整,加强抗SYN Flood能力PHPChina 开源社区门户"|(| Ez1Xb
   # echo 'net.ipv4.tcp_syncookies = 1' >> /etc/sysctl.confPHPChina 开源社区门户 A"b)jf.gIl4X
   # sysctl -pPHPChina 开源社区门户{[-k"ST-l
PHPChina 开源社区门户B3X$l@ {9H0`z
4. 配置yum
jG"NP4l/r.r0   # rpm --import /usr/share/doc/centos-release-3/RPM-GPG-KEY-CentOS-3PHPChina 开源社区门户Fs+B|G
   # yum list | tee /etc/yum.listPHPChina 开源社区门户 } U"BhM~j9p0J
PHPChina 开源社区门户)Z4]7O$@PV}D_a
5. 修改命令history记录
l0oY/C)IB(D"W7n0   # vi /etc/profile
#]Wu%x*BhYM:Z0     找到 HISTSIZE=1000 改为 HISTSIZE=50
Q9nr!y[H0PHPChina 开源社区门户.eNUZ t,m(fgwH

szcb\$\Y8o0PHPChina 开源社区门户!tpF/qY},q+]
6. 定时校正服务器时间
4tYKc)]0VZ)Z0   # yum install ntpPHPChina 开源社区门户'KC:R7{)Ei [
   # crontab -e
4`L&n7IW}s0加入一行:PHPChina 开源社区门户s!|G7R z:J
*/15 * * * * ntpdate 210.72.145.44PHPChina 开源社区门户 Xn;D#v-oYf
## 210.72.145.44 为中国国家授时中心服务器地址。PHPChina 开源社区门户$}-{p/f*wi1m.r&C

D!Qn M.]:}!b P-S+K07.
重新启动系统
/^8MQ0M ~J#WBl0   # init 6PHPChina 开源社区门户-U2P%o/}7c!Z
PHPChina 开源社区门户+UB~~x)mU}Q
8. 使用 yum 程序安装所需开发包(以下为标准的 RPM 包名称)PHPChina 开源社区门户7o7Yj3@,o ^b
   gcc gcc-c++ gcc-g77 flex bison autoconf automake bzip2-devel zlib-devel ncurses-devel libjpeg-devel libpng-devel libtiff-devel freetype-devel pam-develPHPChina 开源社区门户NbxD,su

$d.K Mt2b09. 源码编译安装所需包(Source)
6POo,w#j%M a6L0   (1) GD2PHPChina 开源社区门户 dA&p r Sc.nAK+~'_
       # cd /usr/local/src
5Um ne:A O/U1wCxJ0       # wget http://download.discuz.net/env/gd-2.0.33.tar.gz
| o@/_(V:?0       # tar xzvf gd-2.0.33.tar.gzPHPChina 开源社区门户B8D qku$D4?7W["b
       # cd gd-2.0.33PHPChina 开源社区门户;k7~_!W:B
       # ./configure --prefix=/usr/local/gd2PHPChina 开源社区门户$C3e#ykda+[r h
       # make
F!r8d ^e {9`0       # make install
YG b{L H*H0WT{]a0
b_4PvwK,F0   (2) LibXML2
3dJ#t1[5_S0       # cd /usr/local/srcPHPChina 开源社区门户)a/fM8b5m+L*F s6a!P
       # wget http://download.discuz.net/env/libxml2-2.6.26.tar.bz2PHPChina 开源社区门户%zEw6E;PAD(Y
              # tar xjvf libxml2-2.6.26.tar.bz2PHPChina 开源社区门户h5z+y4Q'y
              # cd libxml2-2.6.26PHPChina 开源社区门户z5R6^+Q)zp
              # ./configure --prefix=/usr/local/libxml2
Jbk ln Rx}0              # make
d%m*nx7w!U{0              # make installPHPChina 开源社区门户8{ O^Y:p;I8ST;o

P]4N7|-Zq"nXU0   (3) Apache日志截断程序
CKn u(D{QB0# cd /usr/local/src
y u2^!u ?5_+~n}0# wget http://download.discuz.net/env/cronolog-1.6.2.tar.gz
8K~b5t*d0# tar xzvf cronolog-1.6.2.tar.gzPHPChina 开源社区门户%](nt!@3of'O ~
# cd cronolog-1.6.2
GQ H@a0# ./configure –prefix=/usr/local/cronolog
r#L[| ?!]T0# makePHPChina 开源社区门户 }}:Ek3G3}.zIT
# make install
8cO'sH'Z Wjp0PHPChina 开源社区门户"~{'Beu^ ~ ek R*f@'o
PHPChina 开源社区门户 Nxr)v^m-N
10. 升级OpenSSLOpenSSHPHPChina 开源社区门户q(Pmf X,A^H2X
    # cd /usr/local/src
(T9K8D3s"N~0    # wget http://download.discuz.net/env/openssl-0.9.7j.tar.gz
SXCK b0    # wget http://download.discuz.net/env/openssh-4.2p1.tar.gzPHPChina 开源社区门户)k"jlJu b$Y'DYJ
    # tar xzvf openssl-0.9.7j.tar.gzPHPChina 开源社区门户4ZIM _W#l#My+?
    # cd openssl-0.9.7j
\ vS2?&Cy ?j0    # ./config --prefix=/usr/local/opensslPHPChina 开源社区门户[:nr7J,hr Du\_#L
    # makePHPChina 开源社区门户/]k!y/i#I\o4x
    # make test
mDV*eG"e e AZz0    # make install
%|&J{ge(D0    # cd ..PHPChina 开源社区门户~2OX$A:RMG
    # tar xzvf openssh-4.2p1.tar.gzPHPChina 开源社区门户i4w"M5[ @+yo Y6E
    # cd openssh-4.2p1
yI2a?W0# ./configure  \PHPChina 开源社区门户3[W.`.CO xP(C
"--prefix=/usr" \
1w Tiscc#R c,? d0"--with-pam" \PHPChina 开源社区门户(Uu CW+i
"--with-zlib" \
7{K}V&?]0"--with-ssl-dir=/usr/local/openssl" \
z;d5c?5W kXU0"--with-md5-passwords"PHPChina 开源社区门户&|Hp)r@S$H#|
    # make
&@_O\ @sTv0    # make installPHPChina 开源社区门户xQ;Q Qq8j7A$lV
    禁止root直接登录,此处先建立一个普通系统用户:PHPChina 开源社区门户-[&t-IrpM U
    # useradd username
SA/]G%zS|0    # passwd usernamePHPChina 开源社区门户&M q#|j(A3U1sE
    # echo 'Protocol 2' >> /etc/ssh/sshd_configPHPChina 开源社区门户-e0Wp4l EL+s(R}/\};b
    # echo 'Protocol 2' >> /usr/etc/sshd_configPHPChina 开源社区门户1FW`LA)Yq
    # echo 'PermitRootLogin no' >> /etc/ssh/sshd_configPHPChina 开源社区门户)D:u:G)IgN"l
    # echo 'PermitRootLogin no' >> /usr/etc/sshd_configPHPChina 开源社区门户Q$| h$ou
    # /etc/rc.d/init.d/sshd restartPHPChina 开源社区门户YS cO'M|U}
PHPChina 开源社区门户tx:n/kY W

5t{8ic&k_+~m"]I0
;s6`iF"~e w@Y0PHPChina 开源社区门户9T tEJ@Mw \AW
三、编译安装L.A.M.P环境
^Im@qcR7G8C7z;x01. 下载软件
6q{ rC2y2h`g0    # cd /usr/local/srcPHPChina 开源社区门户N^_6jt#b0I
    # wget http://download.discuz.net/env/httpd-2.2.3.tar.bz2
;J O$O?]+Q2oj0    # wget http://download.discuz.net/env/mysql-5.0.27.tar.gz
$j||$V3p!NM;C0    # wget http://download.discuz.net/env/php-5.2.0.tar.bz2
4n+]%WQa0CL0# wget http://download.discuz.net/env/ZendOptimizer-3.2.0-linux-glibc21-i386.tar.gzPHPChina 开源社区门户R/Dd%pK"O`
2. 编译安装MySQL
-Y7bD od)~*[:dQ0    # tar xzvf mysql-5.0.27.tar.gz
L/s$c4IqiXf8pz0    # cd mysql-5.0.27PHPChina 开源社区门户pd6JZ:^9m\ n$c
# ./configure \
"gnaj}0        "--prefix=/usr/local/mysql" \PHPChina 开源社区门户 C M,kR A8g+pp7R
        "--localstatedir=/var/lib/mysql" \
~:X8s O2pZ c0        "--with-comment=Source" \
Q9cb7}cH$W0        "--with-server-suffix=-Comsenz" \
0_*U3o%D,z1A:T0        "--with-mysqld-user=mysql" \
7w7{r&qcGNR A0        "--without-debug" \PHPChina 开源社区门户8pc ~"ZSF5Z
        "--with-big-tables" \PHPChina 开源社区门户X:`+x5V"G W6j'`
        "--with-charset=" \PHPChina 开源社区门户7?7?-D;w9F pq%Dy
        "--with-collation= " \PHPChina 开源社区门户X\ C7Hn_qt
        "--with-extra-charsets=all" \
+z-k"I(n&o)Z{!m pQ:[0        "--with-pthread" \PHPChina 开源社区门户4O!I q)^*iF:C
        "--enable-static" \PHPChina 开源社区门户+K"pL)BI
        "--enable-thread-safe-client" \PHPChina 开源社区门户EOC'`FKa
        "--with-client-ldflags=-all-static" \
X"\*~?-}P8YH0V9p0        "--with-mysqld-ldflags=-all-static" \
3zX]2w*H5`H)OB0        "--enable-assembler" \
q{ H lv0        "--without-isam" \PHPChina 开源社区门户J1t~B-O KxS
        "--without-innodb" \PHPChina 开源社区门户My%u"Gk&v`
        "--without-ndb-debug"
~SF X P2AFnj0    # make
:nm m8~z;i/d3Kg&S0    # make install
#BYUD7xi(`#Wl+l0# useradd mysql
a Q vi}H;gS[0    # cd /usr/local/mysql
0ZI`b6Lf^km0    # bin/mysql_install_db --user=mysql
w~wtpPy#UX0    # chown -R root:mysql .PHPChina 开源社区门户:g%sc7uP1O[
    # chown -R mysql /var/lib/mysqlPHPChina 开源社区门户nP|B Rd'|#|?
# cp share/mysql/my-huge.cnf /etc/my.cnf
;m;cQT(gpd6\ Z0    # cp share/mysql/mysql.server /etc/rc.d/init.d/mysqld
~Qd*ZiHvle5Zl0    # chmod 755 /etc/rc.d/init.d/mysqld
*Fc+P!s9t'P2|&k_,z4C0    # chkconfig --add mysqldPHPChina 开源社区门户;Bgo6pW@.BD
    # /etc/rc.d/init.d/mysqld start
l*d3U7sm[7w%GZTI0# bin/mysql -u root password "password_for_root"
B-f$Q.|%?^X0t _h0
I[:~4N2|"@/J03. 编译安装Apache
'O!J{)o-h:C%^$U/i0    # cd /usr/local/src
o G2~;s/?t0# tar xjvf httpd-2.2.3.tar.bz2PHPChina 开源社区门户z'sHQ+q K8nM
# cd httpd-2.2.3PHPChina 开源社区门户 G*g*J$_ r I.U
    # ./configure \
ss*Q;E,U8I5n;G0        "--prefix=/usr/local/apache2" \PHPChina 开源社区门户 j B[$](^A9u o
        "--enable-module=so" \
/O&S'aws|0YS$T0        "--enable-deflate=shared" \
A.lI^H-q5U)O0        "--enable-expires=shared" \
^/| vM8M0        "--enable-rewrite=shared" \
P:AN&re'sD ~0        "--enable-static-support" \
2W-tvBz1u aIF0        "--enable-static-htpasswd" \PHPChina 开源社区门户UC9F7H-}"^6i UH
        "--enable-static-htdigest" \
k@7g|+I%\ s0        "--enable-static-rotatelogs" \
3E)eDy{VC N?0        "--enable-static-logresolve" \PHPChina 开源社区门户.@O}4X'Z(?"v
        "--enable-static-htdbm" \
pN lROQ1n0        "--enable-static-ab" \
.O FV"b!LX2~0        "--enable-static-checkgid" \PHPChina 开源社区门户a4lGKTR?#[
        "--disable-userdir"PHPChina 开源社区门户mMQIg
    # make
gHZ5E8R0# make installPHPChina 开源社区门户@0w8R"m$t L3P
# echo '/usr/local/apache2/bin/apachectl start ' >> /etc/rc.localPHPChina 开源社区门户"GwxgN8X$q#q.x

f/KPlg'U%DS0
tVo7D%U:D kP04. 编译安装PHP
[ V(M`v'z-u:xL0    # cd /usr/local/srcPHPChina 开源社区门户 f vAA8L/QL
    # tar xjvf php-5.2.0.tar.bz2
w9p&D4t._;Dn0    # cd php-5.2.0
p%c3t7uA,{j0    # ./configure \PHPChina 开源社区门户 WgZ:q2`J%j(Z+J0|)D
        "--prefix=/usr/local/php" \PHPChina 开源社区门户Lt]I@I"Q;[6g C
        "--with-apxs2=/usr/local/apache2/bin/apxs" \PHPChina 开源社区门户4je:]"xE{#GS
        "--with-config-file-path=/etc" \PHPChina 开源社区门户kA(wb!Hp8A
        "--with-mysql=/usr/local/mysql" \
:Xpafi0        "--with-libxml-dir=/usr/local/libxml2" \PHPChina 开源社区门户y5h_Fe
        "--with-gd=/usr/local/gd2" \
!D0VIZa O;_$T0        "--enable-gd-native-ttf" \
6[E\ MW@/`0        "--with-jpeg-dir" \PHPChina 开源社区门户 To j'rU})In%G/W _
        "--with-png-dir" \
&fN(JLC WZ"E a$L7y$G ^0        "--with-bz2" \PHPChina 开源社区门户g;L&s8]B;mV:dv4w!d)}
        "--with-freetype-dir" \PHPChina 开源社区门户Hl7Zi6~
        "--with-iconv-dir" \
2u C$o;S^c PM:Sm0        "--with-zlib-dir" \
8_yGqbW0r jb0        "--enable-mbstring" \PHPChina 开源社区门户jZ1x ZC&x0}(Y
        "--disable-ipv6" \ # IPv6 离我们还好远,暂时不用它PHPChina 开源社区门户'[X$J+t"n6JP
        "--disable-cgi" \   # 出于安全考虑,禁用 CGI 支持
"L r2]:l!k\3Y!]LK0        "--disable-cli"     # 出于安全考虑,禁止编译出 php Command Line Shell 命令
|]6E+gow:K!D0    # makePHPChina 开源社区门户\\1Q$\Aw4R-LsH&ts
    # make installPHPChina 开源社区门户T R)qw)IQ
# cp php.ini-dist /etc/php.ini
yr3|P,@#E;J([Q0
B%z@LtVx05. 安装Zend OptimizerPHPChina 开源社区门户}lml"|.X&`rW
    # cd /usr/local/srcPHPChina 开源社区门户J2OQ2Yg7m+k?
    # tar xzvf ZendOptimizer-3.2.0-linux-glibc21-i386.tar.gzPHPChina 开源社区门户t{ a.Ox
# ./ZendOptimizer-3.2.0-linux-glibc21-i386/install.shPHPChina 开源社区门户6^ ~x&]%O
    安装Zend Optimizer过程的最后不要选择重启Apache
r d j H'v#c+?+{^0PHPChina 开源社区门户5I*Z#dy%v'wY8b5t
6. 整合ApachePHP
z y#doh'T9zr i0# vi /usr/local/apache2/conf/httpd.confPHPChina 开源社区门户\%`EghIA8^7XN
找到:
~1B8b*a a\DsS0AddType application/x-gzip .gz .tgzPHPChina 开源社区门户0r;Fx7ct`/t_cY W
在该行下面添加PHPChina 开源社区门户^+I)w1} P#O#Z^
AddType application/x-httpd-php .php
cv9@#i1f0AddOutputFilterByType DEFLATE text/html text/plain text/xmlPHPChina 开源社区门户5uZ6s9}\9Pn

.^$yRA'qeE@%@0找到:
(Cnm h]Y?q0<IfModule dir_module>
r4F&a8W {"W]\^)W0    DirectoryIndex index.html index.html.varPHPChina 开源社区门户s lj*M:BA/a-}Y
</IfModule>PHPChina 开源社区门户q&s/O:QS
将该行改为
P"HsB5l jg,W j0<IfModule dir_module>PHPChina 开源社区门户|2H%D&@ARjnkz
    DirectoryIndex index.html index.htm index.phpPHPChina 开源社区门户|` Wr'Xd;im
</IfModule>PHPChina 开源社区门户/b8v5VbE$LF
PHPChina 开源社区门户C0c-wD1idVO)n
找到:PHPChina 开源社区门户L {*Pi!]9wr:@$@6Z9w
#Include conf/extra/httpd-mpm.conf
/i#Dam-CT7p+a#M#h0#Include conf/extra/httpd-info.conf
#KVKr&D qvJ(\0#Include conf/extra/httpd-vhosts.confPHPChina 开源社区门户s(\*D&o.s_^ }*c`8R
#Include conf/extra/httpd-default.confPHPChina 开源社区门户]"z0n7@l
去掉前面的“#”号,取消注释,设置相关的模块配置文件。
;d$wP5^`;I)QXL0PHPChina 开源社区门户!P*yLR,BRX
修改完成后保存退出。
d"h7vv7e cR%R3}0# /usr/local/apache2/bin/apachectl restartPHPChina 开源社区门户t Rnd0d4Mq(CwY
7. 查看确认L.A.M.P环境信息,提升 PHP 安全性
(P5vJ1b&o^6Q2f2o0   # echo '#!/usr/local/php/bin/php \PHPChina 开源社区门户'e_9tF&~A
<?php \PHPChina 开源社区门户H Ap pDa
         phpinfo(); \PHPChina 开源社区门户lN$X V~
         ?>' > /usr/local/php/phpinfo.php
3QS5Dp4J6~V-|j K-J k0   # chmod 755 /usr/local/php/phpinfo.phpPHPChina 开源社区门户}/g YJ[`M/@
   # /usr/local/php/phpinfo.php > /usr/local/php/phpinfo
)e5H S2jseg5~Y0   # more /usr/local/php/phpinfoPHPChina 开源社区门户D"ZZ;F8Q4U)r
   检查phpinfo中的各项信息是否正确。PHPChina 开源社区门户KD j0q F

|~J k4ev j{7r0   确认 PHP 能够正常工作后,在 php.ini 中进行设置提升 PHP 安全性。
X2hR ~&~C/O'm1hK!I0   # vi /etc/php.ini
.\P~b3|E~2j`0       找到:
(},qzIQ GU0       disable_functions =
\G Vu/cCO.jX0       设置为:
"p(snm.F~I0       disable_functions = phpinfo,passthru,exec,system,popen,chroot,escapeshellcmd,escapeshellarg,shell_exec,proc_open,proc_get_status,ini_restore
ab:O[~:f"F0PHPChina 开源社区门户 M @;nZtGI_
最后,重新启动 Apache 服务即可。 PHPChina 开源社区门户$r,y*T*ij

TAG:

Open Toolbar