CentOS下的LAMP环境之A.M.P环境

运维 系统运维
CentOS下的LAMP环境之A.M.P环境:LAMP是说Linux-Apache-MySQL-PHP,LAMP网站架构是目前国际流行的Web框架。LAMP框架包括:Linux操作系统,Apache网络服务器,MySQL数据库,Perl、PHP或者Python编程语言。LAMP所有组成产品均是开源软件,是国际上成熟的架构框架。本文讲述的是CentOS下的LAMP环境之A.M.P环境。

CentOS下的LAMP环境之A.M.P环境(大纲

  三、编译安装A.M.P环境

  1.下载软件编译安装

  1)下载软件

  1.   # cd /usr/local/src  
  2.  

  httpd-2.2.8.tar.gz

  mysql-5.0.51b.tar.gz

  php-5.2.6.tar.bz2

  ZendOptimizer-3.3.3-linux-glibc23-i386.tar.gz

  2) 安装MySQL

  查看分析你的CPU型号:

  查找您的GCC编译参数.

  确定系统CPU类型:

  1.   # cat /proc/cpuinfo | grep "model name"  
  2.  

  执行后会看到系统中CPU的具体型号,记下CPU型号。

  1.   # tar xvf mysql-5.0.51b.tar.gz  
  2.  
  3.   # cd mysql-5.0.51b  
  4.  
  5.   # vi mysql.sh  
  6.  

  代码:

  1.   -------------------cut begin-------------------------------------------  
  2.  
  3.   CHOST="i686-pc-linux-gnu" 
  4.  
  5.   CFLAGS="-march=prescott -O2 -pipe -fomit-frame-pointer" 
  6.  
  7.   CXXFLAGS="${CFLAGS}" 
  8.  
  9.   ./configure \  
  10.  
  11.   "--prefix=/usr/local/mysql" \  
  12.  
  13.   "--localstatedir=/data/mysql/data" \  
  14.  
  15.   "--with-comment=Source" \  
  16.  
  17.   "--with-server-suffix=-LinuxTone" \  
  18.  
  19.   "--with-mysqld-user=mysql" \  
  20.  
  21.   "--without-debug" \  
  22.  
  23.   "--with-big-tables" \  
  24.  
  25.   "--with-charset=gbk" \  
  26.  
  27.   "--with-collation=gbk_chinese_ci" \  
  28.  
  29.   "--with-extra-charsets=all" \  
  30.  
  31.   "--with-pthread" \  
  32.  
  33.   "--enable-static" \  
  34.  
  35.   "--enable-thread-safe-client" \  
  36.  
  37.   "--with-client-ldflags=-all-static" \  
  38.  
  39.   "--with-mysqld-ldflags=-all-static" \  
  40.  
  41.   "--enable-assembler" \  
  42.  
  43.   "--without-isam" \  
  44.  
  45.   "--without-innodb" \  
  46.  
  47.   "--without-ndb-debug"  
  48.  
  49.   make && make install  
  50.  
  51.   mkdir -p /data/mysql/data  
  52.  
  53.   useradd mysql -d /data/mysql -s /sbin/nologin  
  54.  
  55.   /usr/local/mysql/bin/mysql_install_db --user=mysql 
  56.  
  57.   cd /usr/local/mysql  
  58.  
  59.   chown -R root:mysql .  
  60.  
  61.   chown -R mysql /data/mysql/data  
  62.  
  63.   cp share/mysql/my-huge.cnf /etc/my.cnf  
  64.  
  65.   cp share/mysql/mysql.server /etc/rc.d/init.d/mysqld  
  66.  
  67.   chmod 755 /etc/rc.d/init.d/mysqld  
  68.  
  69.   chkconfig --add mysqld  
  70.  
  71.   /etc/rc.d/init.d/mysqld start  
  72.  
  73.   cd /usr/local/mysql/bin  
  74.  
  75.   for i in *; do ln -s /usr/local/mysql/bin/$i /usr/bin/$i; done  
  76.  
  77.   -------------------cut end---------------------------------------------  
  78.  

  #sh mysql.sh 即可开始编译.

  3) 编译安装Apache

  1.   # cd /usr/local/src  
  2.  
  3.   # tar xvf httpd-2.2.8.tar.gz  
  4.  
  5.   # cd httpd-2.2.8  
  6.  

  代码:

  1.   # ./configure \  
  2.  
  3.   "--prefix=/usr/local/apache2" \  
  4.  
  5.   "--with-included-apr" \  
  6.  
  7.   "--enable-so" \  
  8.  
  9.   "--enable-deflate=shared" \  
  10.  
  11.   "--enable-expires=shared" \  
  12.  
  13.   "--enable-rewrite=shared" \  
  14.  
  15.   "--enable-static-support" \  
  16.  
  17.   "--disable-userdir"  
  18.  
  19.   # make  
  20.  
  21.   # make install  
  22.  
  23.   # echo '/usr/local/apache2/bin/apachectl start ' >> /etc/rc.local  
  24.  

  4.)编译安装PHP

  1.   # cd /usr/local/src  
  2.  
  3.   # tar xjvf php-5.2.6.tar.bz2  
  4.  
  5.   # cd php-5.2.6  
  6.  

  代码:

  1.   # ./configure \  
  2.  
  3.   "--prefix=/usr/local/php" \  
  4.  
  5.   "--with-apxs2=/usr/local/apache2/bin/apxs" \  
  6.  
  7.   "--with-config-file-path=/usr/local/php/etc" \  
  8.  
  9.   "--with-mysql=/usr/local/mysql" \  
  10.  
  11.   "--with-libxml-dir=/usr/local/libxml2" \  
  12.  
  13.   "--with-gd=/usr/local/gd2" \  
  14.  
  15.   "--with-jpeg-dir" \  
  16.  
  17.   "--with-png-dir" \  
  18.  
  19.   "--with-bz2" \  
  20.  
  21.   "--with-freetype-dir" \  
  22.  
  23.   "--with-iconv-dir" \  
  24.  
  25.   "--with-zlib-dir " \  
  26.  
  27.   "--with-openssl=/usr/local/openssl" \  
  28.  
  29.   "--with-mcrypt=/usr/local/libmcrypt" \  
  30.  
  31.   "--enable-soap" \  
  32.  
  33.   "--enable-gd-native-ttf" \  
  34.  
  35.   "--enable-ftp" \  
  36.  
  37.   "--enable-mbstring" \  
  38.  
  39.   "--enable-exif" \  
  40.  
  41.   "--disable-ipv6" \  
  42.  
  43.   "--disable-cgi" \  
  44.  
  45.   "--disable-cli" #禁掉ipv6,禁掉cli模式,提升速度和安全性.请根据具体需求定制相关的编译数.  
  46.  
  47.   # make  
  48.  
  49.   # make install  
  50.  
  51.   # mkdir /usr/local/php/etc  
  52.  
  53.   # cp php.ini-dist /usr/local/php/etc/php.ini  
  54.  

  5)Xcache的安装.

  #tar xvf xcache-1.2.2.tar.gz

  代码:

  1.   #/usr/local/php/bin/phpize  
  2.  
  3.   ./configure --enable-xcache --enable-xcache-coverager  
  4.  
  5.   --with-php-config=/usr/local/php/bin/php-config \  
  6.  
  7.   --enable-inline-optimization --disable-debug  
  8.  

  代码:

  1.   #/usr/local/php/bin/phpize  
  2.  
  3.   ./configure --enable-xcache --enable-xcache-coverager  
  4.  
  5.   --with-php-config=/usr/local/php/bin/php-config \  
  6.  
  7.   --enable-inline-optimization --disable-debug  
  8.  

  代码:

  1.   -------------------cut begin-------------------------------------------  
  2.  
  3.   [xcache-common]  
  4.  
  5.   zend_extension =  
  6.  
  7.   /usr/local/php/lib/php/extensions/no-debug-non-zts-20060613/xcache.so  
  8.  
  9.   [xcache.admin]  
  10.  
  11.   xcache.admin.user = "admin" 
  12.  
  13.   ;如何生成md5密码: echo -n "password"| md5sum  
  14.  
  15.   xcache.admin.pass = "035d849226a8a10be1a5e0fec1f0f3ce" #密码为52netseek  
  16.  
  17.   [xcache]  
  18.  
  19.   ; Change xcache.size to tune the size of the opcode cache  
  20.  
  21.   xcache.size = 24M 
  22.  
  23.   xcache.shm_scheme = "mmap" 
  24.  
  25.   xcache.count = 4 
  26.  
  27.   xcache.slots = 8K 
  28.  
  29.   xcache.ttl = 0 
  30.  
  31.   xcache.gc_interval = 0 
  32.  
  33.   ; Change xcache.var_size to adjust the size of variable cache  
  34.  
  35.   xcache.var_size = 8M 
  36.  
  37.   xcache.var_count = 1 
  38.  
  39.   xcache.var_slots = 8K 
  40.  
  41.   xcache.var_ttl = 0 
  42.  
  43.   xcache.var_maxttl = 0 
  44.  
  45.   xcache.var_gc_interval = 300 
  46.  
  47.   xcache.test = Off 
  48.  
  49.   xcache.readonly_protection = On 
  50.  
  51.   xcache.mmap_path = "/tmp/xcache" 
  52.  
  53.   xcache.coredump_directory = "" 
  54.  
  55.   xcache.cacher = On 
  56.  
  57.   xcache.stat = On 
  58.  
  59.   xcache.optimizer = Off 
  60.  
  61.   [xcache.coverager]  
  62.  
  63.   xcache.coverager = On 
  64.  
  65.   xcache.coveragedump_directory = "" 
  66.  
  67.   -------------------cut end---------------------------------------------  
  68.  

  6) 安装Zend Optimizer

  1.   # cd /usr/local/src  
  2.  
  3.   # tar xzvf ZendOptimizer-3.3.3-linux-glibc23-i386.tar.gz  
  4.  
  5.   # ./ZendOptimizer-3.3.3-linux-glibc23-i386/install.sh  
  6.  

  安装Zend Optimizer过程的最后不要选择重启Apache。

  2. 整合Apache与PHP及系统初化配置.

  1)整合Apache与PHP

  1.   # vi /usr/local/apache2/conf/httpd.conf  
  2.  

  找到:

  AddType application/x-gzip .gz .tgz

  在该行下面添加

  1.   AddType application/x-httpd-php .php  
  2.  

  找到:  

  1.   DirectoryIndex index.html  
  2.  

  将该行改为  

  1.   DirectoryIndex index.html index.htm index.php  

 

  找到:

  1.   #Include conf/extra/httpd-mpm.conf  
  2.  
  3.   #Include conf/extra/httpd-info.conf  
  4.  
  5.   #Include conf/extra/httpd-vhosts.conf (虚拟主机配置文件存放目录.)  
  6.  
  7.   #Include conf/extra/httpd-default.conf  
  8.  

  去掉前面的“#”号,取消注释。

  注意:以上 4 个扩展配置文件中的设置请按照相关原则进行合理配置!

  修改完成后保存退出。

  1.   # /usr/local/apache2/bin/apachectl restart  
  2.  

  2)查看确认L.A.M.P环境信息、提升 PHP 安全性

  在网站根目录放置 info.php 脚本,检查phpinfo中的各项信息是否正确。

  

  1.   phpinfo();  
  2.  
  3.   ?> 
  4.  

  确认 PHP 能够正常工作后,在 php.ini 中进行设置提升 PHP 安全性,禁掉危险的函数.

  # vi /etc/php.ini找到:disable_functions

  =设置为:phpinfo,passthru,exec,system,chroot,scandir,chgrp,chown,shell_exec,proc_open,proc_get_status,ini_alter,ini_alter,ini_restore,dl,pfsockopen,openlog,syslog,readlink,symlink,popepassthru,stream_socket_server

  3)脚本自动完成初始化配置(以上配置可以用脚本自动化完成)

  #cat init_apache_php.sh

  代码:

  1.   -------------------cut begin-------------------------------------------  
  2.  
  3.   #!/bin/bash  
  4.  
  5.   #Written by :NetSeek  
  6.  
  7.   #init_httpd.conf  
  8.  
  9.   http_cf="/usr/local/apache2/conf/httpd.conf" 
  10.  
  11.   sed -i -e "s/User daemon/User www/" -i -e "s/Group daemon/Group www/" $http_cf  
  12.  
  13.   sed -i -e '121 s/^/#/' -i -e '122 s/^/#/' $http_cf  
  14.  
  15.   sed -i 's#DirectoryIndex index.html# DirectoryIndex index.php index.html  
  16.  
  17.   index.htm#/g' $http_cf  
  18.  
  19.   sed -i -e '374 s/^#//g' -i -e '389 s/^#//g' -i -e '392 s/^#//g' -i -e '401  
  20.  
  21.   s/^#//g' $http_cf  
  22.  
  23.   #init_php(PHP安全设置及隐藏PHP版本)  
  24.  
  25.   php_cf="/usr/local/php/etc/php.ini" 
  26.  
  27.   sed -i '205 s#;open_basedir =#open_basedir = /data/www/wwwroot:/tmp#g' $php_cf  
  28.  
  29.   sed -i '210 s#disable_functions =#disable_functions =  
  30.  
  31.   phpinfo,passthru,exec,system,chroot,scandir,chgrp,chown,shell_exec,proc_open,proc_get_status,ini_alter,ini_alter,ini_restore,dl,pfsockopen,openlog,syslog,readlink,symlink,popepassthru,stream_socket_server#g'  
  32.  
  33.   $php_cf  
  34.  
  35.   sed -i '/expose_php/s/On/Off/' $php_cf  
  36.  
  37.   sed -i '/display_errors/s/On/Off/' $php_cf  
  38.  
  39.   -------------------cut end-------------------------------------------  

CentOS下的LAMP环境之A.M.P环境的介绍。

【编辑推荐】

  1. Ubuntu下LAMP的搭建
  2. Centos下搭建LAMP
  3. Linux下LAMP的安装方法
责任编辑:zhaolei 来源: javaeye
相关推荐

2011-03-09 16:16:57

CentOSLAMP

2011-03-09 16:16:54

CentOSLAMP

2011-03-09 16:16:56

CentOSLAMP

2011-03-09 16:17:21

CentOSLAMP

2011-03-09 16:28:25

2011-09-09 17:23:53

CentOSLAMPmysql

2011-03-21 11:33:09

LAMPApache

2011-03-21 11:43:45

LAMPPHP

2011-03-14 10:30:15

Ubuntu10.04LAMP

2011-03-22 10:25:54

UbuntuLAMP

2011-03-21 14:13:44

LAMPApacheSSL

2011-03-09 13:02:31

LAMP环境搭建

2011-03-14 13:06:58

LAMP搭建

2011-03-21 16:49:53

2011-03-21 13:04:38

LAMPApache

2011-03-10 14:40:48

LAMP搭建

2011-03-23 10:13:53

LAMP环境搭建

2011-03-10 15:44:18

CentOSLAMP安装

2011-03-10 15:44:18

CentOSLAMP安装

2011-04-02 11:40:17

LAMP测试环境
点赞
收藏

51CTO技术栈公众号