Discuz!官方免费开源建站系统

 找回密码
 立即注册

QQ登录

只需一步,快速开始

搜索

L.A.M.P 环境配置文档--CentOS

[复制链接]
chancey 发表于 2006-12-29 15:54:27 | 显示全部楼层 |阅读模式
L.A.M.P 环境部署详细步骤


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

一、系统约定软件源代码包存放位置
/usr/local/src

源码包编译安装位置(prefix)
/usr/local/software_name

脚本以及维护程序存放位置
/usr/local/sbin

MySQL 数据库位置
/var/lib/mysql

Apache 网站根目录
/data/wwwroot

Apache 虚拟主机日志根目录
/data/logs/www

Apache 运行账户
www:www

yum RPM包信息文件
/etc/yum.list


二、系统环境部署及调整
1. 检查系统是否正常
   # more /var/log/messages   (检查有无系统内核级错误信息)
   # dmesg (检查硬件设备是否有错误信息)
   # ifconfig(检查网卡设置是否正确)
   # ping www.163.com  (检查网络是否正常)

2. 关闭不需要的服务
   # ntsysv
   以下仅列出需要启动的服务,未列出的服务一律关闭:
   crond
   irqbalance (仅当服务器CPU为S.M.P架构或支持双核心、HT技术时,才需开启,否则关闭。)
   microcode_ctl
   network
   random
   sendmail
   sshd
   syslog

3. 对TCP/IP网络参数进行调整,加强抗SYN Flood能力
   # echo 'net.ipv4.tcp_syncookies = 1' >> /etc/sysctl.conf
   # sysctl -p

4. 配置yum
   # rpm --import /usr/share/doc/centos-release-3/RPM-GPG-KEY-CentOS-3
   # yum list | tee /etc/yum.list

5. 修改命令history记录
   # vi /etc/profile
     找到 HISTSIZE=1000 改为 HISTSIZE=50



6. 定时校正服务器时间
   # yum install ntp
   # crontab -e
加入一行:
*/15 * * * * ntpdate 210.72.145.44
## 210.72.145.44 为中国国家授时中心服务器地址。

7. 重新启动系统
   # init 6

8. 使用 yum 程序安装所需开发包(以下为标准的 RPM 包名称)
   gcc gcc-c++ gcc-g77 flex bison autoconf automake bzip2-devel zlib-devel ncurses-devel libjpeg-devel libpng-devel libtiff-devel freetype-devel pam-devel

9. 源码编译安装所需包(Source)
   (1) GD2
       # cd /usr/local/src
       # wget http://download.discuz.net/env/gd-2.0.33.tar.gz
       # tar xzvf gd-2.0.33.tar.gz
       # cd gd-2.0.33
       # ./configure --prefix=/usr/local/gd2
       # make
       # make install

   (2) LibXML2
       # cd /usr/local/src
       # wget http://download.discuz.net/env/libxml2-2.6.26.tar.bz2
              # tar xjvf libxml2-2.6.26.tar.bz2
              # cd libxml2-2.6.26
              # ./configure --prefix=/usr/local/libxml2
              # make
              # make install

   (3) Apache日志截断程序
# cd /usr/local/src
# wget http://download.discuz.net/env/cronolog-1.6.2.tar.gz
# tar xzvf cronolog-1.6.2.tar.gz
# cd cronolog-1.6.2
# ./configure –prefix=/usr/local/cronolog
# make
# make install


10. 升级OpenSSL和OpenSSH
    # cd /usr/local/src
    # wget http://download.discuz.net/env/openssl-0.9.7j.tar.gz
    # wget http://download.discuz.net/env/openssh-4.2p1.tar.gz
    # tar xzvf openssl-0.9.7j.tar.gz
    # cd openssl-0.9.7j
    # ./config --prefix=/usr/local/openssl
    # make
    # make test
    # make install
    # cd ..
    # tar xzvf openssh-4.2p1.tar.gz
    # cd openssh-4.2p1
# ./configure  \
"--prefix=/usr" \
"--with-pam" \
"--with-zlib" \
"--with-ssl-dir=/usr/local/openssl" \
"--with-md5-passwords"
    # make
    # make install
    禁止root直接登录,此处先建立一个普通系统用户:
    # useradd username
    # passwd username
    # echo 'Protocol 2' >> /etc/ssh/sshd_config
    # echo 'Protocol 2' >> /usr/etc/sshd_config
    # echo 'PermitRootLogin no' >> /etc/ssh/sshd_config
    # echo 'PermitRootLogin no' >> /usr/etc/sshd_config
    # /etc/rc.d/init.d/sshd restart




三、编译安装L.A.M.P环境
1. 下载软件
    # cd /usr/local/src
    # wget http://download.discuz.net/env/httpd-2.2.3.tar.bz2
    # wget http://download.discuz.net/env/mysql-5.0.27.tar.gz
    # wget http://download.discuz.net/env/php-5.2.0.tar.bz2
# wget http://download.discuz.net/env/Z ... glibc21-i386.tar.gz
2. 编译安装MySQL
    # tar xzvf mysql-5.0.27.tar.gz
    # cd mysql-5.0.27
# ./configure \
        "--prefix=/usr/local/mysql" \
        "--localstatedir=/var/lib/mysql" \
        "--with-comment=Source" \
        "--with-server-suffix=-Comsenz" \
        "--with-mysqld-user=mysql" \
        "--without-debug" \
        "--with-big-tables" \
        "--with-charset=" \ #这个后边需要指定你所需要的字符集参数(gbk,utf8......)
        "--with-collation= " \ #字符集校正码(gbk_chinese_ci,......)
        "--with-extra-charsets=all" \
        "--with-pthread" \
        "--enable-static" \
        "--enable-thread-safe-client" \
        "--with-client-ldflags=-all-static" \
        "--with-mysqld-ldflags=-all-static" \
        "--enable-assembler" \
        "--without-isam" \
        "--without-innodb" \
        "--without-ndb-debug"
    # make
    # make install
# useradd mysql
    # cd /usr/local/mysql
    # bin/mysql_install_db --user=mysql
    # chown -R root:mysql .
    # chown -R mysql /var/lib/mysql
# cp share/mysql/my-huge.cnf /etc/my.cnf
    # cp share/mysql/mysql.server /etc/rc.d/init.d/mysqld
    # chmod 755 /etc/rc.d/init.d/mysqld
    # chkconfig --add mysqld
    # /etc/rc.d/init.d/mysqld start
# bin/mysql -u root password "password_for_root"

3. 编译安装Apache
    # cd /usr/local/src
# tar xjvf httpd-2.2.3.tar.bz2
# cd httpd-2.2.3
    # ./configure \
        "--prefix=/usr/local/apache2" \
        "--enable-module=so" \
        "--enable-deflate=shared" \
        "--enable-expires=shared" \
        "--enable-rewrite=shared" \
        "--enable-static-support" \
        "--enable-static-htpasswd" \
        "--enable-static-htdigest" \
        "--enable-static-rotatelogs" \
        "--enable-static-logresolve" \
        "--enable-static-htdbm" \
        "--enable-static-ab" \
        "--enable-static-checkgid" \
        "--disable-userdir"
    # make
# make install
# echo '/usr/local/apache2/bin/apachectl start ' >> /etc/rc.local


4. 编译安装PHP
    # cd /usr/local/src
    # tar xjvf php-5.2.0.tar.bz2
    # cd php-5.2.0
    # ./configure \
        "--prefix=/usr/local/php" \
        "--with-apxs2=/usr/local/apache2/bin/apxs" \
        "--with-config-file-path=/etc" \
        "--with-mysql=/usr/local/mysql" \
        "--with-libxml-dir=/usr/local/libxml2" \
        "--with-gd=/usr/local/gd2" \
        "--enable-gd-native-ttf" \
        "--with-jpeg-dir" \
        "--with-png-dir" \
        "--with-bz2" \
        "--with-freetype-dir" \
        "--with-iconv-dir" \
        "--with-zlib-dir" \
        "--enable-mbstring" \
        "--disable-ipv6" \ # IPv6 离我们还好远,暂时不用它
        "--disable-cgi" \   # 出于安全考虑,禁用 CGI 支持
        "--disable-cli"     # 出于安全考虑,禁止编译出 php Command Line Shell 命令
    # make
    # make install
# cp php.ini-dist /etc/php.ini

5. 安装Zend Optimizer
    # cd /usr/local/src
    # tar xzvf ZendOptimizer-3.2.0-linux-glibc21-i386.tar.gz
# ./ZendOptimizer-3.2.0-linux-glibc21-i386/install.sh
    安装Zend Optimizer过程的最后不要选择重启Apache。

6. 整合Apache与PHP
# vi /usr/local/apache2/conf/httpd.conf
找到:
AddType application/x-gzip .gz .tgz
在该行下面添加
AddType application/x-httpd-php .php
AddOutputFilterByType DEFLATE text/html text/plain text/xml

找到:
<IfModule dir_module>
    DirectoryIndex index.html index.html.var
</IfModule>
将该行改为
<IfModule dir_module>
    DirectoryIndex index.html index.htm index.php
</IfModule>

找到:
#Include conf/extra/httpd-mpm.conf
#Include conf/extra/httpd-info.conf
#Include conf/extra/httpd-vhosts.conf
#Include conf/extra/httpd-default.conf
去掉前面的“#”号,取消注释,设置相关的模块配置文件。

修改完成后保存退出。
# /usr/local/apache2/bin/apachectl restart
7. 查看确认L.A.M.P环境信息,提升 PHP 安全性
   # echo '#!/usr/local/php/bin/php \
<?php \
         phpinfo(); \
         ?>' > /usr/local/php/phpinfo.php
   # chmod 755 /usr/local/php/phpinfo.php
   # /usr/local/php/phpinfo.php > /usr/local/php/phpinfo
   # more /usr/local/php/phpinfo
   检查phpinfo中的各项信息是否正确。

   确认 PHP 能够正常工作后,在 php.ini 中进行设置提升 PHP 安全性。
   # vi /etc/php.ini
       找到:
       disable_functions =
       设置为:
       disable_functions = phpinfo,passthru,exec,system,popen,chroot,escapeshellcmd,escapeshellarg,shell_exec,proc_open,proc_get_status,ini_restore

最后,重新启动 Apache 服务即可。

[ 本帖最后由 chancey 于 2007-1-18 09:23 编辑 ]

评分

1

查看全部评分

hao32 发表于 2006-12-30 10:44:56 | 显示全部楼层
回复

使用道具 举报

云崖子 发表于 2006-12-31 12:30:23 | 显示全部楼层
好详细

谢谢
回复

使用道具 举报

Old吴 发表于 2007-1-1 21:58:03 | 显示全部楼层
不明白具体是什么意思啊
回复

使用道具 举报

partsoft 发表于 2007-1-2 00:02:08 | 显示全部楼层
不错
:lol
回复

使用道具 举报

阿冰啊 发表于 2007-1-3 23:29:43 | 显示全部楼层
:)
回复

使用道具 举报

blankion 发表于 2007-1-8 15:10:59 | 显示全部楼层
有没有winxp 系统下的PHP环境搭建!?
望楼主赐教!
回复

使用道具 举报

routernetcn 发表于 2007-1-17 22:43:33 | 显示全部楼层

编辑mysql 时出错,请楼主帮忙!谢谢

checking whether make sets $(MAKE)... yes
checking "character sets"... configure: error: Charset utf8 not available. (Available are: binary armscii8 ascii big5 cp1250 cp1251 cp1256 cp1257 cp850 cp852 cp866 cp932 dec8 eucjpms euckr gb2312 gbk geostd8 greek hebrew hp8 keybcs2 koi8r koi8u latin1 latin2 latin5 latin7 macce macroman sjis swe7 tis620 ucs2 ujis utf8).
      See the Installation chapter in the Reference Manual.
回复

使用道具 举报

Spider_C++ 发表于 2007-1-17 23:52:56 | 显示全部楼层
前排支持了。。。。不错,我也是用CENTOS
回复

使用道具 举报

 楼主| chancey 发表于 2007-1-18 09:24:56 | 显示全部楼层

回复 #8 routernetcn 的帖子

已答复
回复

使用道具 举报

您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

手机版|小黑屋|Discuz! 官方站 ( 皖ICP备16010102号 )star

GMT+8, 2024-9-29 23:34 , Processed in 0.576924 second(s), 17 queries , Gzip On.

Powered by Discuz! X3.4

Copyright © 2001-2023, Tencent Cloud.

快速回复 返回顶部 返回列表