apache category
CentOS 源码编译安装LAMP(Apache MySQL PHP)
发表于:2012年07月24日  分类:Apache  添加评论  111 次浏览 

源码编译安装LAMP虽然过程繁琐,但可以根据自己PHP程序的需要配置相应的环境,非常的灵活。对于比较急于配置好LAMP的同学,可以使用lamp一键安装

卸载yum或rpm安装的amp软件

在编译安装lamp之前,首先先卸载已存在的rpm包吧。

    rpm -e httpd

  1. rpm -e mysql
  2. rpm -e php
  3. yum -y remove httpd
  4. yum -y remove php
  5. yum -y remove mysql-server mysql
  6. yum -y remove php-mysql

禁用SeLinux

selinux可能会致使编译安装失败,我们先禁用它。

    sed -i ‘s/SELINUX=enforcing/SELINUX=disabled/g’ /etc/selinux/config //永久禁用,需要重启生效

  1. setenforce 0 //临时禁用,不需要重启

yum安装必要工具

1、安装编译工具gcc gcc-c++make automake autoconf kernel-devel
2、安装PHP所需依赖,如libxml2-devel openssl-devel curl-devel libjpeg-devel libpng-devel等

    yum -y install gcc gcc-c++  make automake autoconf kernel-devel ncurses-devel libxml2-devel openssl-devel curl-devel libjpeg-devel libpng-devel  pcre-devel libtool-libs freetype-devel gd zlib-devel file bison patch mlocate flex diffutils   readline-devel glibc-devel glib2-devel bzip2-devel gettext-devel libcap-devel libmcrypt-devel

下载所需源码

apache:http://httpd.apache.org/
mysql:http://mysql.com/downloads/mysql/
php:http://php.net/downloads.php
phpmyadmin:http://www.phpmyadmin.net/home_page/downloads.php
我们这里选择的版本为:apache-2.2.22,mysql-5.1.62,php-5.2.17,phpmyadmin-3.4.10.2

    cd /tmp

  1. wget -c http://apache.ziply.com//httpd/httpd-2.2.22.tar.gz
  2. wget -c http://dev.mysql.com/get/Downloads/MySQL-5.1/mysql-5.1.64.tar.gz/from/http://mysql.he.net/
  3. wget -c http://us2.php.net/get/php-5.2.17.tar.gz/from/am.php.net/mirror
  4. wget -c http://iweb.dl.sourceforge.net/project/phpmyadmin/phpMyAdmin/3.4.10.2/phpMyAdmin-3.4.10.2-all-languages.tar.gz
  5. tar xzf httpd-2.2.22.tar.gz
  6. tar xzf mysql-5.1.62.tar.gz
  7. tar xzf php-5.2.17.tar.gz
  8. tar xzf phpMyAdmin-3.4.10.2-all-languages.tar.gz

安装apache2.2.22

    cd /tmp/httpd-2.2.22

  1. ./configure –prefix=/usr/local/apache –with-included-apr –enable-so –enable-deflate=shared –enable-expires=shared  –enable-headers=shared –enable-rewrite=shared –enable-static-support
  2. make
  3. make install

编译参数解释:
–prefix=/usr/local/apache:指定安装目录
–with-included-apr:在编译时强制使用当前源代码中绑定的APR版本
–enable-so:允许运行时加载DSO模块
–enable-deflate=shared:将deflate模块编译为DSO
–enable-expires=shared:将expires模块编译为DSO
–enable-headers=shared:将headers模块编译为DSO
–enable-rewrite=shared:将rewrite模块编译为DSO
–enable-static-support:使用静态连接(默认为动态连接)编译所有二进制支持程序
更详细的编译参数解释:http://lamp.linux.gov.cn/Apache/ApacheMenu/programs/configure.html

    cp build/rpm/httpd.init /etc/init.d/httpd //使用init脚本管理httpd

  1. chmod 755 /etc/init.d/httpd //增加执行权限
  2. chkconfig –add httpd  //添加httpd到服务项
  3. chkconfig  httpd on   //设置开机启动
  4. ln -fs /usr/local/apache/ /etc/httpd
  5. ln -fs /usr/local/apache/bin/httpd /usr/sbin/httpd
  6. ln -fs /usr/local/apache/bin/apachectl /usr/sbin/apachectl
  7. ln -fs /usr/local/apache/logs /var/log/httpd //设置软链接以适应init脚本

安装mysql5.1.62

    groupadd mysql

  1. useradd -g mysql mysql
  2. cd /tmp/mysql-5.1.62
  3. ./configure –prefix=/usr/local/mysql/ –localstatedir=/usr/local/mysql/data –without-debug –with-unix-socket-path=/tmp/mysql.sock –with-client-ldflags=-all-static –with-mysqld-ldflags=-all-static –enable-assembler –with-extra-charsets=gbk,gb2312,utf8 –with-pthread
  4. make
  5. make install

编译参数解释:
–prefix=/usr/local/mysql/:指定安装位置
–localstatedir=/usr/local/mysql/data:指定数据库文件位置
–without-debug:禁用调用模式
–with-unix-socket-path=/tmp/mysql.sock:指定sock文件位置
–with-client-ldflags=-all-static:
–with-mysqld-ldflags=-all-static:以纯静态方式编译服务端和客户端
–enable-assembler:使用一些字符函数的汇编版本
–with-extra-charsets=gbk,gb2312,utf8 :gbk,gb2312,utf8字符支持
–with-pthread:强制使用pthread库(posix线程库)
更多编译参数请执行./configure –help命令查看。

    cp support-files/my-medium.cnf /etc/my.cnf //复制配置文件夹my.cnf

  1. /usr/local/mysql/bin/mysql_install_db –user=mysql  //初始化数据库
  2. chown -R root.mysql /usr/local/mysql
  3. chown -R mysql /usr/local/mysql/data 
  4. cp /tmp/mysql-5.1.62/support-files/mysql.server /etc/rc.d/init.d/mysqld  //init启动脚本
  5. chown root.root /etc/rc.d/init.d/mysqld 
  6. chmod 755 /etc/rc.d/init.d/mysqld
  7. chkconfig –add mysqld
  8. chkconfig  mysqld on
  9. ln -s /usr/local/mysql/bin/mysql /usr/bin
  10. ln -s /usr/local/mysql/bin/mysqladmin /usr/bin
  11. service mysqld start
  12. /usr/local/mysql/bin/mysqladmin -u root password ‘新密码’   //设置root密码

安装PHP5.2.17

在编译php之前,先要解决两个问题:centos 6上libmcrypt的安装和可能有些系统找不到libiconv导致的错误。
1、centos 6官方源已经没有libmcrypt的rpm包,我们这里选择编译安装,当然你也可以导入第三方源安装(centos 5略过此步)。
下载源码:

    cd /tmp

  1. wget http://superb-dca2.dl.sourceforge.net/project/mcrypt/Libmcrypt/2.5.8/libmcrypt-2.5.8.tar.gz
  2. wget http://superb-dca2.dl.sourceforge.net/project/mhash/mhash/0.9.9.9/mhash-0.9.9.9.tar.gz
  3. wget http://superb-sea2.dl.sourceforge.net/project/mcrypt/MCrypt/2.6.8/mcrypt-2.6.8.tar.gz
  4. tar xzf libmcrypt-2.5.8.tar.gz
  5. tar xzf mhash-0.9.9.9.tar.gz
  6. tar xzf mcrypt-2.6.8.tar.gz
  7. //安装libmcrypt
  8. cd /tmp/libmcrypt-2.5.8
  9. ./configure –prefix=/usr
  10. make && make install
  11. //安装libmcrypt
  12. cd /tmp/mhash-0.9.9.9
  13. ./configure –prefix=/usr
  14. make && make install
  15. //安装mcrypt
  16. /sbin/ldconfig //搜索出可共享的动态链接库
  17. cd /tmp/mcrypt-2.6.8
  18. ./configure
  19. make && make install

2、解决可能出现的libiconv错误。

    cd /tmp

  1. wget http://ftp.gnu.org/pub/gnu/libiconv/libiconv-1.14.tar.gz
  2. tar xzf libiconv-1.14.tar.gz
  3. cd libiconv-1.14
  4. ./configure –prefix=/usr/local/libiconv
  5. make && make install

开始安装php-5.2.17:

    cd /tmp/php-5.2.17

  1. ./configure –prefix=/usr/local/php –with-apxs2=/usr/local/apache/bin/apxs –with-config-file-path=/etc –with-config-file-scan-dir=/etc/php.d –with-openssl –with-zlib –enable-bcmath –with-bz2 –with-curl –enable-ftp –with-gd –enable-gd-native-ttf –with-gettext –with-mhash –enable-mbstring –with-mcrypt –enable-soap –enable-zip –with-iconv=/usr/local/libiconv –with-mysql=/usr/local/mysql –without-pear
  2. make
  3. make install

编译参数解释:
–prefix=/usr/local/php:设置安装路径
–with-apxs2=/usr/local/apache/bin/apxs:编译共享的 Apache 2.0 模块
–with-config-file-path=/etc:指定配置文件php.ini地址
–with-config-file-scan-dir=/etc/php.d:指定额外的ini文件目录
–with-openssl:编译OpenSSL支持
–with-zlib:编译zlib支持
–enable-bcmath:启用BC风格精度数学函数
–with-bz2:BZip2支持
–with-curl:CRUL支持
–enable-ftp:FTP支持
–with-gd:GD支持
–enable-gd-native-ttf:启用TrueType字符串函数
–with-gettext:启用GNU gettext支持
–with-mhash:mhash支持
–enable-mbstring:启用支持多字节字符串
–with-mcrypt:编译mcrypt加密支持
–enable-soap:SOAP支持
–enable-zip:启用zip 读/写支持
–with-iconv=/usr/local/libiconv:iconv支持
–with-mysql=/usr/local/mysql:启用mysql支持
–without-pear:不安装PEAR
更多编译参数解释参考http://www.php.net/manual/zh/configure.about.php或者./configure –help查看。

    cp php.ini-dist /usr/local/php/etc/php.ini //复制配置文件php.ini

在/etc/httpd/conf/httpd.conf文件中加入php文件类型解析:

    Addtype application/x-httpd-php .php

重启httpd:

    service httpd restart

安装ZendOptimizer-3.3.9(可选)

ZendOptimizer的作用是分析,优化由Zend 编译器加密产生的代码的程序,对不是Zend编译器加密过的程序,没有必要安装这个。
64位:http://downloads.zend.com/optimizer/3.3.9/ZendOptimizer-3.3.9-linux-glibc23-x86_64.tar.gz
32位:http://downloads.zend.com/optimizer/3.3.9/ZendOptimizer-3.3.9-linux-glibc23-i386.tar.gz

    cd /tmp

  1. wget http://downloads.zend.com/optimizer/3.3.9/ZendOptimizer-3.3.9-linux-glibc23-i386.tar.gz
  2. tar xzf ZendOptimizer-3.3.9-linux-glibc23-i386.tar.gz
  3. cd /tmp/ZendOptimizer-3.3.9-linux-glibc23-i386/data/5_2_x_comp/
  4. mkdir -p /usr/local/Zend/lib/
  5. cp ZendOptimizer.so /usr/local/Zend/lib

加载zendoptimizer,建立/etc/php.d/zend.ini文件,加入如下代码加载:

    [zend]

  1. zend_optimizer.optimization_level=15
  2. zend_extension=/usr/local/Zend/lib/ZendOptimizer.so

重启httpd生效:

    service httpd restart

安装eAccelerator-0.9.6.1(可选)

eAccelerator是一个自由开放源码php加速器,优化和动态内容缓存,提高了php脚本的缓存性能,使得PHP脚本在编译的状态下,对服务器的开销几乎完全消除。 它还有对脚本起优化作用,以加快其执行效率。使您的PHP程序代码执效率能提高1-10倍。类似的php加速器有:Xcache,APC等。下面是安装方法:

    cd /tmp

  1. wget http://voxel.dl.sourceforge.net/project/eaccelerator/eaccelerator/eAccelerator%200.9.6.1/eaccelerator-0.9.6.1.zip
  2. unzip eaccelerator-0.9.6.1.zip
  3. cd eaccelerator-0.9.6.1
  4. export PHP_PREFIX=”/usr/local/php”
  5. $PHP_PREFIX/bin/phpize
  6. ./configure -enable-eaccelerator=shared -with-php-config=$PHP_PREFIX/bin/php-config
  7. make && make install
  8. cd /tmp
  9. mkdir eaccelerator
  10. chmod 0777 eaccelerator

加载eAccelerator,创建/ec/php.d/ea.ini文件,加入如下代码加载:

    [eaccelerator]

  1. zend_extension=”/usr/local/php/lib/php/extensions/no-debug-non-zts-20060613/eaccelerator.so”
  2. eaccelerator.shm_size=”32″
  3. eaccelerator.cache_dir=”/tmp/eaccelerator”
  4. eaccelerator.enable=”1″
  5. eaccelerator.optimizer=”1″
  6. eaccelerator.check_mtime=”1″
  7. eaccelerator.debug=”0″
  8. eaccelerator.filter=”"
  9. eaccelerator.shm_max=”0″
  10. eaccelerator.shm_ttl=”0″
  11. eaccelerator.shm_prune_period=”0″
  12. eaccelerator.shm_only=”0″
  13. eaccelerator.compress=”1″
  14. eaccelerator.compress_level=”9″

eaccelerator参数设置参考:http://www.centos.bz/2012/03/eaccelerator-parameter/
重启httpd生效:

    service httpd restart

转载请注明《文章来源:http://www.centos.bz/2011/09/centos-compile-lamp-apache-mysql-php/

固定链接: http://anywang.vicp.net:8180/wp/?p=236 | 网邻's Blog

给我留言


/ 快捷键:Ctrl+Enter

留言没头像?这里教你设置头像!