CentOS下的LAMP环境之A.M.P环境(大纲)
三、编译安装A.M.P环境
1.下载软件编译安装
1)下载软件
- # cd /usr/local/src
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类型:
- # cat /proc/cpuinfo | grep "model name"
执行后会看到系统中CPU的具体型号,记下CPU型号。
- # tar xvf mysql-5.0.51b.tar.gz
- # cd mysql-5.0.51b
- # vi mysql.sh
代码:
- -------------------cut begin-------------------------------------------
- CHOST="i686-pc-linux-gnu"
- CFLAGS="-march=prescott -O2 -pipe -fomit-frame-pointer"
- CXXFLAGS="${CFLAGS}"
- ./configure \
- "--prefix=/usr/local/mysql" \
- "--localstatedir=/data/mysql/data" \
- "--with-comment=Source" \
- "--with-server-suffix=-LinuxTone" \
- "--with-mysqld-user=mysql" \
- "--without-debug" \
- "--with-big-tables" \
- "--with-charset=gbk" \
- "--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
- mkdir -p /data/mysql/data
- useradd mysql -d /data/mysql -s /sbin/nologin
- /usr/local/mysql/bin/mysql_install_db --user=mysql
- cd /usr/local/mysql
- chown -R root:mysql .
- chown -R mysql /data/mysql/data
- 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
- cd /usr/local/mysql/bin
- for i in *; do ln -s /usr/local/mysql/bin/$i /usr/bin/$i; done
- -------------------cut end---------------------------------------------
#sh mysql.sh 即可开始编译.
3) 编译安装Apache
- # cd /usr/local/src
- # tar xvf httpd-2.2.8.tar.gz
- # cd httpd-2.2.8
代码:
- # ./configure \
- "--prefix=/usr/local/apache2" \
- "--with-included-apr" \
- "--enable-so" \
- "--enable-deflate=shared" \
- "--enable-expires=shared" \
- "--enable-rewrite=shared" \
- "--enable-static-support" \
- "--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.6.tar.bz2
- # cd php-5.2.6
代码:
- # ./configure \
- "--prefix=/usr/local/php" \
- "--with-apxs2=/usr/local/apache2/bin/apxs" \
- "--with-config-file-path=/usr/local/php/etc" \
- "--with-mysql=/usr/local/mysql" \
- "--with-libxml-dir=/usr/local/libxml2" \
- "--with-gd=/usr/local/gd2" \
- "--with-jpeg-dir" \
- "--with-png-dir" \
- "--with-bz2" \
- "--with-freetype-dir" \
- "--with-iconv-dir" \
- "--with-zlib-dir " \
- "--with-openssl=/usr/local/openssl" \
- "--with-mcrypt=/usr/local/libmcrypt" \
- "--enable-soap" \
- "--enable-gd-native-ttf" \
- "--enable-ftp" \
- "--enable-mbstring" \
- "--enable-exif" \
- "--disable-ipv6" \
- "--disable-cgi" \
- "--disable-cli" #禁掉ipv6,禁掉cli模式,提升速度和安全性.请根据具体需求定制相关的编译数.
- # make
- # make install
- # mkdir /usr/local/php/etc
- # cp php.ini-dist /usr/local/php/etc/php.ini
5)Xcache的安装.
#tar xvf xcache-1.2.2.tar.gz
代码:
- #/usr/local/php/bin/phpize
- ./configure --enable-xcache --enable-xcache-coverager
- --with-php-config=/usr/local/php/bin/php-config \
- --enable-inline-optimization --disable-debug
代码:
- #/usr/local/php/bin/phpize
- ./configure --enable-xcache --enable-xcache-coverager
- --with-php-config=/usr/local/php/bin/php-config \
- --enable-inline-optimization --disable-debug
代码:
- -------------------cut begin-------------------------------------------
- [xcache-common]
- zend_extension =
- /usr/local/php/lib/php/extensions/no-debug-non-zts-20060613/xcache.so
- [xcache.admin]
- xcache.admin.user = "admin"
- ;如何生成md5密码: echo -n "password"| md5sum
- xcache.admin.pass = "035d849226a8a10be1a5e0fec1f0f3ce" #密码为52netseek
- [xcache]
- ; Change xcache.size to tune the size of the opcode cache
- xcache.size = 24M
- xcache.shm_scheme = "mmap"
- xcache.count = 4
- xcache.slots = 8K
- xcache.ttl = 0
- xcache.gc_interval = 0
- ; Change xcache.var_size to adjust the size of variable cache
- xcache.var_size = 8M
- xcache.var_count = 1
- xcache.var_slots = 8K
- xcache.var_ttl = 0
- xcache.var_maxttl = 0
- xcache.var_gc_interval = 300
- xcache.test = Off
- xcache.readonly_protection = On
- xcache.mmap_path = "/tmp/xcache"
- xcache.coredump_directory = ""
- xcache.cacher = On
- xcache.stat = On
- xcache.optimizer = Off
- [xcache.coverager]
- xcache.coverager = On
- xcache.coveragedump_directory = ""
- -------------------cut end---------------------------------------------
6) 安装Zend Optimizer
- # cd /usr/local/src
- # tar xzvf ZendOptimizer-3.3.3-linux-glibc23-i386.tar.gz
- # ./ZendOptimizer-3.3.3-linux-glibc23-i386/install.sh
安装Zend Optimizer过程的最后不要选择重启Apache。
2. 整合Apache与PHP及系统初化配置.
1)整合Apache与PHP
- # vi /usr/local/apache2/conf/httpd.conf
找到:
AddType application/x-gzip .gz .tgz
在该行下面添加
- AddType application/x-httpd-php .php
找到:
- DirectoryIndex index.html
将该行改为
- DirectoryIndex index.html index.htm index.php
找到:
- #Include conf/extra/httpd-mpm.conf
- #Include conf/extra/httpd-info.conf
- #Include conf/extra/httpd-vhosts.conf (虚拟主机配置文件存放目录.)
- #Include conf/extra/httpd-default.conf
去掉前面的“#”号,取消注释。
注意:以上 4 个扩展配置文件中的设置请按照相关原则进行合理配置!
修改完成后保存退出。
- # /usr/local/apache2/bin/apachectl restart
2)查看确认L.A.M.P环境信息、提升 PHP 安全性
在网站根目录放置 info.php 脚本,检查phpinfo中的各项信息是否正确。
- phpinfo();
- ?>
确认 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
代码:
- -------------------cut begin-------------------------------------------
- #!/bin/bash
- #Written by :NetSeek
- #init_httpd.conf
- http_cf="/usr/local/apache2/conf/httpd.conf"
- sed -i -e "s/User daemon/User www/" -i -e "s/Group daemon/Group www/" $http_cf
- sed -i -e '121 s/^/#/' -i -e '122 s/^/#/' $http_cf
- sed -i 's#DirectoryIndex index.html# DirectoryIndex index.php index.html
- index.htm#/g' $http_cf
- sed -i -e '374 s/^#//g' -i -e '389 s/^#//g' -i -e '392 s/^#//g' -i -e '401
- s/^#//g' $http_cf
- #init_php(PHP安全设置及隐藏PHP版本)
- php_cf="/usr/local/php/etc/php.ini"
- sed -i '205 s#;open_basedir =#open_basedir = /data/www/wwwroot:/tmp#g' $php_cf
- sed -i '210 s#disable_functions =#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#g'
- $php_cf
- sed -i '/expose_php/s/On/Off/' $php_cf
- sed -i '/display_errors/s/On/Off/' $php_cf
- -------------------cut end-------------------------------------------
CentOS下的LAMP环境之A.M.P环境的介绍。
【编辑推荐】