搞网站跑PHP还是自己手动编译一下LAMP吧,毕竟集成包不是很好,你也不知道集成的时候都给你装了什么。现在本人需要LAMP并且要使用ZEND,故要用5.2.17版本了,所以只能编译安装了。
安装准备:
1、禁用Selinux
# vi /etc/selinux/config
SELINUXTYPE=disable
# setenforce 0 #临时禁用,不需要重启
在编译安装lamp之前,首先先卸载已存在的rpm包
# rpm -e httpd
# rpm -e mysql
# rpm -e php
# yum -y remove httpd
# yum -y remove php
# yum -y remove mysql-server mysql
# yum -y remove php-mysql2、安装所要的库文件
# yum -y install gcc gcc-c++ autoconf libjpeg libjpeg-devel libpng libpng-devel freetype freetype-devel libxml2 libxml2-devel zlib zlib-devel glibc glibc-devel glib2 glib2-devel bzip2 bzip2-devel ncurses ncurses-devel curl curl-devel e2fsprogs e2fsprogs-devel krb5 krb5-devel libidn libidn-devel openssl openssl-devel openldap openldap-devel nss_ldap openldap-clients openldap-servers3、下载所需要的源码及删除没必要的rpm包安装准备
# wget http://www.apache.org/dist/httpd/httpd-2.2.25.tar.gz
# wget http://am1.php.net/distributions/php-5.2.17.tar.gz
# wget http://mysql.mirrors.pair.com/Downloads/MySQL-5.1/mysql-5.1.70.tar.gz
二、安装apache
#cd /usr/local/src
# tar zxvf httpd-2.2.25.tar.gz
# cd httpd-2.2.25
# ./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
# make
# 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:使用静态连接(默认为动态连接)编译所有二进制支持程序
# vi /usr/local/apache/conf/httpd.conf
找到: ServerName www.example.com:80 去掉前面的"#"
# /usr/local/apache/bin/apachectl -k start
# vi /etc/profile # 添加apache服务系统环境变量
export PATH=$PATH:/usr/local/apache/bin
# cp /usr/local/apache/bin/apachectl /etc/rc.d/init.d/httpd #把apache 加入到系统启动
# vi /etc/init.d/httpd
在#!/bin/sh添加以下两行
# chkconfig: 2345 85 15
# description: Apache is a World Wide Web server.
# chkconfig httpd on #设置开机启动
# service httpd restart
三、安装mysql5.1.70
# groupadd mysql
# useradd -g mysql mysql -s /bin/false # 创建用户mysql并加入到mysql组,不允许mysql用户直接登陆系统
# mkdir -p /home/mysql # 创建mysql数据库存放目录
# chown -R mysql:mysql /home/mysql/
# tar zxvf /usr/local/src/mysql-5.1.70.tar.gz
# cd /usr/local/src/mysql-5.1.70
#./configure --prefix=/usr/local/mysql/ --localstatedir=/home/mysql --without-debug --with-unix-socket-path=/tmp/mysql.sock --with-client-ldflags=-all-static --with-mysqld-ldflags=-all-static --enable-assembler --with-extra-charsets=all --with-pthread
# make
# make install
特别注意:在执行
make install
编译的过程中,如果你看到屏幕上出现下面这一行,卡在那里,很久都过不去,千万别以为是编译错误了,或者服务器卡住了,只需要坚持,
耐心的等待几分钟,就会编译成功!
Mysql编译安装告诉我们,任何事情,只要坚持下去,终会成功!
make[4]: Entering directory `/usr/local/src/mysql-5.1.70/mysql-test'
编译参数解释:
–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,/etc目录下默认有一个my.cnf,直接覆盖
# vi /etc/my.cnf #编辑配置文件,在[mysqld]部分添加
datadir =/data/mysql # 添加mysql数据库路径
# /usr/local/mysql/bin/mysql_install_db --user=mysql # 初始化数据库
# cp ./support-files/mysql.server /etc/rc.d/init.d/mysqld
# chmod 755 /etc/init.d/mysqld
# chkconfig mysqld on
# vi /etc/rc.d/init.d/mysqld # 编辑
basedir=/usr/local/mysql #mysql数据库安装路径,"="后面不能有空格
datadir=/data/mysql # mysql数据库存放目录,"="后面不能有空格
# service mysqld start #启动mysql
# vi /etc/profile # 把mysql服务加入系统环境变量,在最后添加下面这一行
export PATH=$PATH:/usr/local/mysql/bin
下面这两行把mysql的库文件链接到系统默认位置,这样在编译php等软件时就不用指定mysql的库文件地址
# ln -s /usr/local/mysql/lib/mysql /usr/lib/mysql/
# ln -s /usr/local/mysql/include/mysql /usr/include/mysql
# shutdown -r now
# /usr/local/mysql/bin/mysqladmin -u root password '新密码' //设置root密码
# service mysqld start
四、安装PHP5.2.17
在编译php之前,先要解决两个问题:centos 6上libmcrypt的安装和可能有些系统找不到libiconv导致的错误。
1、centos 6官方源已经没有libmcrypt的rpm包,我们这里选择编译安装,当然你也可以导入第三方源安装(centos 5略过此步)。
# cd /usr/local/src
# wget http://superb-dca2.dl.sourceforge.net/project/mcrypt/Libmcrypt/2.5.8/libmcrypt-2.5.8.tar.gz
# wget http://superb-dca2.dl.sourceforge.net/project/mhash/mhash/0.9.9.9/mhash-0.9.9.9.tar.gz
# wget http://superb-sea2.dl.sourceforge.net/project/mcrypt/MCrypt/2.6.8/mcrypt-2.6.8.tar.gz
# tar xzf libmcrypt-2.5.8.tar.gz
# tar xzf mhash-0.9.9.9.tar.gz
# tar xzf mcrypt-2.6.8.tar.gz
安装libmcrypt
# cd /usr/local/src/libmcrypt-2.5.8
# ./configure --prefix=/usr
# make && make install
安装libmcrypt
# cd /usr/local/src/mhash-0.9.9.9
# ./configure --prefix=/usr
# make && make install
安装mcrypt
# /sbin/ldconfig # 搜索出可共享的动态链接库
# cd /usr/local/src/mcrypt-2.6.8
# ./configure
# make && make install
2、解决可能出现的libiconv错误。
# cd /usr/local/src
# wget http://ftp.gnu.org/pub/gnu/libiconv/libiconv-1.14.tar.gz
# tar xzf libiconv-1.14.tar.gz
# cd libiconv-1.14
# ./configure --prefix=/usr/local/libiconv
# make && make install
开始安装php-5.2.17:
# cd /usr/local/src
# tar zxf php-5.2.17.tar.gz
# cd /usr/local/src/php-5.2.17
# ./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-freetype-dir --with-jpeg-dir --with-png-dir --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
# make
# 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查看
# mkdir /usr/local/php/etc
# cp php.ini-dist /usr/local/php/etc/php.ini # 复制配置文件php.ini
# vi /usr/local/apache/conf/httpd.conf 在/usr/local/apache/conf/httpd.conf文件中加入php文件类型解析:
在AddType application/x-gzip .gz .tgz 下面添加
Addtype application/x-httpd-php .php
# service httpd restart # 重启httpd
五、 安装ZendOptimizer-3.3.9
1 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
2、下载安装
#wget http://downloads.zend.com/optimizer/3.3.9/ZendOptimizer-3.3.9-linux-glibc23-i386.tar.gz
# tar xzf ZendOptimizer-3.3.9-linux-glibc23-i386.tar.gz
# cd ZendOptimizer-3.3.9-linux-glibc23-i386/data/5_2_x_comp/
# mkdir /etc/php.d/
# mkdir /usr/local/Zend/
# mkdir /usr/local/Zend/lib/
# cp ZendOptimizer.so /usr/local/Zend/lib/ZendOptimizer.so
# vi /etc/php.d/zend.ini # 加载zendoptimizer,建立/etc/php.d/zend.ini文件,加入如下代码加载:
[zend]
zend_optimizer.optimization_level=15
zend_extension=/usr/local/Zend/lib/ZendOptimizer.so
# service httpd restart #重启apache 服务
六、安装eAccelerator-0.9.6.1
1 eAccelerator是一个自由开放源码php加速器,优化和动态内容缓存,提高了php脚本的缓存性能,使得PHP脚本在编译的状态下,对服务器的开销几乎完全消除。 它还有对脚本起优化作用,以加快其执行效率。使您的PHP程序代码执效率能提高1-10倍。类似的php加速器有:Xcache,APC等。下面是安装方法:
2 下载安装
# cd /usr/local/src
# wget http://nchc.dl.sourceforge.net/project/eaccelerator/eaccelerator/eAccelerator%200.9.6.1/eaccelerator-0.9.6.1.zip
# unzip eaccelerator-0.9.6.1.zip
# cd eaccelerator-0.9.6.1
# export PHP_PREFIX="/usr/local/php"
$PHP_PREFIX/bin/phpize
./configure -enable-eaccelerator=shared -with-php-config=$PHP_PREFIX/bin/php-config
make && make install
cd /tmp
mkdir eaccelerator
chmod 0777 eaccelerator
加载eAccelerator,创建/etc/php.d/ea.ini文件,加入如下代码加载:
[eaccelerator]
zend_extension="/usr/local/php/lib/php/extensions/no-debug-non-zts-20060613/eaccelerator.so"
eaccelerator.shm_size="32"
eaccelerator.cache_dir="/tmp/eaccelerator"
eaccelerator.enable="1"
eaccelerator.optimizer="1"
eaccelerator.check_mtime="1"
eaccelerator.debug="0"
eaccelerator.filter=""
eaccelerator.shm_max="0"
eaccelerator.shm_ttl="0"
eaccelerator.shm_prune_period="0"
eaccelerator.shm_only="0"
eaccelerator.compress="1"
eaccelerator.compress_level="9"
# service httpd restart
增加MYSQLI
记得原来在编译php的已经已经加上参数--with-mysql=/usr/local/mysql \
--with-mysqli=/usr/local/mysql/bin/mysql_config \
可后来找了一个,的确不存在mysqli.so,所以只能单独来编译mysqli了。
mysqli是优化过的mysql函数库,MYSQL版本不能低于4.1.12
cd /root/lamp/php-5.2.3/ext/mysqli
#####进入到mysqli的目录。
再用phpize生成configure文件:
/usr/local/php/bin/phpize
Configuring for:
PHP Api Version: 20041225
Zend Module Api No: 20060613
Zend Extension Api No: 220060519
#./configure --prefix=/usr/local/mysqli --with-php-config=/usr/local/php/bin/php-config --with-mysqli=/usr/local/mysql/bin/mysql_config
make
make test
make install
Installing shared extensions: /usr/local/php/lib/php/extensions/debug-non-zts-20060613/
然后在/usr/local/lib/php.ini
加上一句:
extension=/usr/local/php/lib/php/extensions/debug-non-zts-20060613/mysqli.so