lamp环境搭建:

 
配置开发环境
[root@lamp ~]# yum -y groupinstall "Development Tools" "Development Libraries"
 
先安装要用到的库文件
libxml2-2.7.8.tar.gz
[root@lamp ~]# tar xf libxml2-2.7.8.tar.gz 
[root@lamp ~]# cd libxml2-2.7.8
[root@lamp libxml2-2.7.8]# ./configure --prefix=/usr/local/libxml2
“安装libxml2或Mysql过程中在./configure的时候出现如下错误: 写道 /bin/rm: cannot remove `libtoolT': No such file or directory  从网上得到解决方法./configure之前执行如下命令
1.autoreconf --force --install更新生成的配置文件(--force:consider all files obsolete) 2.libtoolize --automake --force(提供了一种标准方式来将libtool支持加入到一个软件包  3.automake --force --add-missing(Automake是一个从文件`Makefile.am'自动生成`Makefile.in' 的工具) 4.打开 configure,把 $RM “$cfgfile” 那行删除掉 5.运行 ./configure 就可以了”
[root@lamp libxml2-2.7.8]# make && make install
 
libmcrypt-2.5.8.tar.gz
[root@lamp ~]# tar xf libmcrypt-2.5.8.tar.gz 
[root@lamp ~]# cd libmcrypt-2.5.8
[root@lamp libmcrypt-2.5.8]# ./configure --prefix=/usr/local/libmcrypt
[root@lamp libmcrypt-2.5.8]# make && make install
 
zlib-1.2.5.tar.bz2
[root@lamp ~]# tar xf zlib-1.2.5.tar.bz2 
[root@lamp ~]# cd zlib-1.2.5
[root@lamp zlib-1.2.5]# ./configure
[root@lamp zlib-1.2.5]# make && make install
 
libpng-1.5.12.tar.gz
[root@lamp ~]# tar xf libpng-1.5.12.tar.gz 
[root@lamp ~]# cd libpng-1.5.12
[root@lamp libpng-1.5.12]# ./configure --prefix=/usr/local/libpng
[root@lamp libpng-1.5.12]# make && make install
注:在安装zlib时,当配置参数是“./configure --prefix=/usr/local/zlib”,在接下来的安装libpng时就会报“找不能zlib”的错误,即使是配置参数加上“--with-zlib-prefix=/usr/local/zlib”也有同样的错误出现。所以在安装zlib时不加“--prefix”指定安装目录。
 
jpegsrc.v7.tar.gz
[root@lamp ~]# tar xf jpegsrc.v7.tar.gz
[root@lamp ~]# cd jpeg-7/
[root@lamp jpeg-7]# ./configure --prefix=/usr/local/jpeg7 --enable-shared --enable-static
[root@lamp jpeg-7]# make && make install
 
freetype-2.4.10.tar.bz2 
[root@lamp ~]# tar xf freetype-2.4.10.tar.bz2 
[root@lamp ~]# cd freetype-2.4.4
[root@lamp freetype-2.4.10]# ./configure --prefix=/usr/local/freetype
[root@lamp freetype-2.4.10]# make && make install
注:make install后有一个错误“rmdir: 删除 "/usr/local/freetype/include/freetype2/freetype/internal" 失败: 没有那个文件或目录
make: [install] 错误 1 (忽略)”   。
处理方法:
[root@lamp freetype-2.4.10]#mkdir -p /usr/local/freetype/include/freetype2/freetype/internal   后再make install
 
autoconf-2.68.tar.gz
[root@lamp ~]# tar xf autoconf-2.68.tar.gz 
[root@lamp ~]# cd autoconf-2.68
[root@lamp autoconf-2.68]# ./configure 
[root@lamp autoconf-2.68]# make && make install
 
 
 
gd-2.0.35.tar.gz
[root@lamp ~]# tar xf gd-2.0.35.tar.gz
[root@lamp ~]# cd gd-2.0.35
[root@lamp gd-2.0.35]# ./configure --prefix=/usr/local/gd2 --with-zlib=/usr --with-jpeg=/usr/local/jpeg7 --with-png=/usr/local/libpng --with-freetype=/usr/local/freetype
[root@lamp gd-2.0.35]# make && make install
注:报错,“gd_png.c:16:53: error: png.h: No such file or directory
gd_png.c:47: error: expected specifier-qualifier-list before 'jmp_buf'
gd_png.c:54: error: expected ')' before 'png_ptr'
gd_png.c:82: error: expected ')' before 'png_ptr'
gd_png.c:92: error: expected ')' before 'png_ptr'
gd_png.c:98: error: expected ')' before 'png_ptr'”
 
处理方法:
[root@lamp gd-2.0.35]#vi gd_png.c
#include “png.h”             
替换成:
#include “/usr/local/libpng/include/png.h”             
然后再make就可以了
注:include“”双引号里包含的是libpng安装的路径里的include文件夹里的png.h文件
 
pcre-8.31.tar.gz 
[root@lamp ~]# tar xf pcre-8.31.tar.gz 
[root@lamp ~]# cd pcre-8.31
[root@lamp pcre-8.31]# ./configure --prefix=/usr/local/pcre
有错误:
“checking how to run the C preprocessor... grep: error while loading shared libraries: libpcre.so.0: cannot open shared object file: No such file or directory
gcc -E
grep: error while loading shared libraries: libpcre.so.0: cannot open shared object file: No such file or directory
checking for grep that handles long lines and -e... configure: error: no acceptable grep could be found in /usr/lib64/qt-3.3/bin:/usr/local/sbin:/usr/local/bin:/sbin:/bin:/usr/sbin:/usr/bin:/root/bin:/usr/xpg4/bin”
 
注:在安装pcre时我先把系统里旧版本的pcre用"rpm -e pcre --nodeps"卸载,再编译安装时就出现上面的错误,网上说是把Libpcre.so.0这个文件建个链接,但是搜索发现我系统里根本就没有这个文件,后来下载rpm安装也不行,有许多的依赖关系还要处理,最后用“yum -y install pcre”安装了一个低版本的pcre,再编译安装pcre-8.31时成功了,我想可能是卸载时加了--nodeps出了问题。
 
apr-1.4.6.tar.gz
[root@lamp ~]# tar xf apr-1.4.6.tar.gz 
[root@lamp ~]# cd apr-1.4.6
[root@lamp apr-1.4.6]# ./configure --prefix=/usr/local/apr
[root@lamp apr-1.4.6]# make && make install
 
apr-util-1.4.1.tar.gz
[root@lamp ~]# tar xf apr-util-1.4.1.tar.gz 
[root@lamp ~]# cd apr-util-1.4.1
[root@lamp apr-util-1.4.1]# ./configure --prefix=/usr/local/apr-util --with-apr=/usr/local/apr
[root@lamp apr-util-1.4.1]# make && make install
注:这里有错误提示“rm: cannot remove `libtoolT': No such file or directory”
处理方法:
[root@lamp apr-1.4.6]# vi configure
注释掉 $RM "$cfgfile"这行
再编译
 
若在编译httpd时有以下错误(在apache-2.4的版本中会遇到这样的情况)
“configure: error: Bundled APR requested but not found at ./srclib/. Download and unpack the corresponding apr and apr-util packages to ./srclib/.”则
[root@lamp ~]#cp -rf apr-1.4.6 httpd-2.4.1/srclib/apr
[root@lamp ~]#cp -rf apr-util-1.4.1 httpd-2.4.1/srclib/apr-util
再编译安装
 
 
目前zend加速器只对php5.2的支持,php5.2与目前httpd-2.4.2上不匹配,实验中这两个版本整合,在重新启动apache时有错误:“httpd: Syntax error on line 145 of /usr/local/apache2/conf/httpd.conf: Cannot load /usr/local/apache2/modules/libphp5.so into server: /usr/local/apache2/modules/libphp5.so: undefined symbol: unixd_config”,所以采用apache-2.2的版本
 
httpd-2.2.22.tar.bz2
[root@lamp ~]# tar xf httpd-2.2.22.tar.bz2 
[root@lamp ~]# cd httpd-2.2.22
[root@lamp httpd-2.2.22]# ./configure --prefix=/usr/local/apache2 sysconfdir=/etc/httpd --with-z=/usr --with-apr=/usr/local/apr --with-apr-util=/usr/local/apr-util --with-included-apr --enable-so --enable-deflate=shared --enable-expries=shared --enable-rewrite=shared --enable-static-support
配置参数“sysconfdir=/etc/httpd”这个参数使用后,在编译完成后发现/etc/httpd/conf/http.conf与/usr/local/apache2/conf/http.conf这两个路径下都有这个配置文件,测试发现是后面的那个生效!!!
[root@lamp httpd-2.4.2]# make && make install
[root@lamp httpd-2.4.2]# echo "usr/local/apache2/bin/apachectl start" >> /etc/rc.d/rc.local
 
在配置参数中原先加入了“--with-pcre=/usr/local/pcre”这样有错误“configure: error: Size of "void *" is less than size of "long"”去掉此参数后正常
引用http://sndapk.blog.51cto.com/5385144/922732配置apache的常见错误
 
 
mysql-5.1.61.tar.gz
[root@lamp mysql-5.1.61]# ./configure --prefix=/usr/local/mysql --with-extra-charsets=all --datadir=/var/mydata
报错1:“checking for termcap functions library... configure: error: No curses/termcap library found”
安装相应的库文件,再运行配置参数
[root@zhaochj mysql-5.1.61]# yum -y install ncurses-devel
[root@zhaochj mysql-5.1.61]# make && make install
在配置时报错2:“/bin/rm: cannot remove `libtoolT': No such file or directory”
引用http://blog.csdn.net/bluephper/article/details/5642421
“这时直接打开 configure,把 $RM “$cfgfile” 那行删除掉,重新再运行 ./configure 就可以了。
网上所说的那些方法根本不管用,如:
 
# aclocal
# autoconf
# automake
# libtoolize –force
 
或者:
 
# autoreconf –force –install
# libtoolize –automake –force
# automake –force –add-missing”
报错3
make[4]: Entering directory `/root/mysql-5.1.65/mysql-test'
make[4]: *** [install_test_files] 段错误 (core dumped)
make[4]: Leaving directory `/root/mysql-5.1.65/mysql-test'
make[3]: *** [install-data-local] 错误 2
make[3]: Leaving directory `/root/mysql-5.1.65/mysql-test'
make[2]: *** [install-am] 错误 2
make[2]: Leaving directory `/root/mysql-5.1.65/mysql-test'
make[1]: *** [install-recursive] 错误 1
make[1]: Leaving directory `/root/mysql-5.1.65/mysql-test'
make: *** [install-recursive] 错误 1
这错误不知道怎么处理,baidu  google了半天也无果,试了多个版本的源码的mysql,结果都没有安装成功,不知道是哪里问题。放弃,下载了一个mysql-5.1.65-linux-x86_64-glibc23.tar.gz二进制包安装成功。
 
mysql-5.5.27.tar.gz安装方法
[root@lamp ~]# groupadd mysql
[root@lamp ~]# useradd -g mysql mysql
[root@lamp ~]# tar xf mysql-5.5.27.tar.gz 
[root@lamp ~]# cd mysql-5.5.27
 
mysql5.5后都是用cmake来配置编译的,所以先安装cmake  cmake运行时需要ncurses库,所以一起安装上
[root@lamp ~]#yum -y install cmake ncurses-devel
 cmake的帮助命令是cmake . -LH或者是ccmake .
我没有搞懂,再运行cmake . -LH查看帮助后所如“CMAKE_INSTALL_PREFIX:PATH=/usr/local/mysql”,而在实际使用中就加个字母“D”,即为下边所使用的配置参数。
[root@lamp mysql-5.5.27]# cmake . -DCMAKE_INSTALL_PREFIX:PATH=/usr/local/mysql -DWITH_EXTRA_CHARSETS:STRING=all -DMYSQL_DATADIR:PATH=/var/mydata
[root@lamp mysql-5.5.27]# make && make install
[root@lamp mysql-5.5.27]# cp support-files/my-medium.cnf /etc/my.cnf
[root@lamp mysql-5.5.27]# cd /usr/local/mysql/
[root@lamp mysql-5.5.27]# chown -R root:mysql .
[root@lamp mysql-5.5.27]# mkdir /var/mydata
[root@lamp mysql-5.5.27]# chown -R /var/mydata
[root@lamp mysql-5.5.27]# vim /etc/my.cnf
在[mysqld]容器中加入“datadir = /var/mydata”   保存退出!
[root@lamp mysql-5.5.27]# cd /usr/local/mysql
[root@lamp mysql]# scripts/mysql_install_db --user=mysql --basedir=/usr/local/mysql --datadir=/var/mydata
[root@lamp mysql]# bin/mysqld_safe --user=mysql &
[root@lamp mysql]# bin/mysqladmin version   测试
[root@lamp mysql]# vim /etc/profile       导出mysql的二进制路径
在"export PATH USER LOGNAME MAIL HOSTNAME HISTSIZE HISTCONTROL"上行增加“export PATH=$PATH:/usr/local/mysql/bin”
[root@lamp mysql]# . /etc/profile
设置mysql的访问权限
[root@lamp ~]# mysql -uroot -p             空密码连接数据库
mysql> select * from mysql.user\G          可以查看到有多个root用户在无密码的状态下能够连接器数据库
mysql> delete from mysql.user where host!='localhost';      删除host字段不等于localhost的用户
mysql> flush privileges;
mysql> set password for 'root'@'localhost'=password('123456');   更改接入密码
mysql> \q
 
[root@lamp ~]# mysqadmin -u root -p shutdown       关闭数据库
[root@lamp ~]# echo "/usr/local/mysql/bin/mysqld_safe --user=mysql &" >> /etc/rc.d/rc.local
 
 
 
因为zend加速器目前只有支持php5.2的,所以php只有安装5.2版本的
php-5.2.17.tar.bz2     http://www.php100.com/manual/php/     php的帮助手册
[root@lamp ~]# tar xf php-5.2.17.tar.bz2 
[root@lamp ~]# cd php-5.2.17
[root@lamp php-5.2.17]# ./configure --prefix=/usr/local/php --with-config-file-path=/etc/php --with-apxs2=/usr/local/apache2/bin/apxs --with-mysql=/usr/local/mysql --with-libxml-dir=/usr/local/libxml2 --with-png-dir=/usr/local/libpng --with-jpeg-dir=/usr/local/jpeg7 --with-freetype-dir=/usr/local/freetype --with-gd=/usr/local/gd2 --with-zlib-dir=/usr --with-mcrypt=/usr/local/libmcrypt --with-mysqli=/usr/local/mysql/bin/mysql_config --enable-soap --enable-mbstring=all --enable-sockets
[root@lamp php-5.3.10]# make && make install
 
 
apache与php的整合
 
[root@lamp ~]# vi /etc/httpd/conf/httpd.conf
查看加载模块处是否加上“LoadModule php5_module        modules/libphp5.so”    
在“AddType application/x-gzip .gz .tgz”的下一行加上“AddType application/x-httpd-php .php .phtml”
在"<IfModule dir_module>
    DirectoryIndex index.html
</IfModule>"
的index.html的前面加上index.php
保存退出!
 
 
[root@lamp php-5.3.10]# cp php.ini-production /etc/php/php.ini
[root@lamp ~]#rm -rf /usr/local/apache2/htdocs/index.html
[root@lamp ~]#vim /usr/local/apache2/htdocs/index.php
<?php
phpinfo();
?>
保存退出!
[root@lamp ~]# /usr/local/apache2/bin/apachectl stop
[root@lamp ~]#/usr/local/apache2/bin/apachectl start &
 
ZendOptimizer-3.3.9-linux-glibc23-x86_64.tar.gz
[root@lamp ~]# tar xf ZendOptimizer-3.3.9-linux-glibc23-x86_64.tar.gz
[root@lamp ~]# mkdir /usr/local/zend
[root@lamp ~]# cd ZendOptimizer-3.3.9-linux-glibc23-x86_64
[root@zhaochj ZendOptimizer-3.3.9-linux-glibc23-x86_64]# cp data/5_2_x_comp/ZendOptimizer.so /usr/local/zend/
[root@zhaochj ZendOptimizer-3.3.9-linux-glibc23-x86_64]# vi /etc/php/php.ini  
在最后加入
[Zend]
zend_optimizer.optimization_level=15
zend_extension=/usr/local/zend/ZendOptimizer.so
保存退出!
 
重新启动apache,进入测试页面看加速器是否已工作!
 
 
 
实验成功的版本搭配:
centos6.2(2.6.32-220.el6.x86_64)  php-5.2.17.tar.bz2   mysql-5.0.96.tar.gz    httpd-2.2.22.tar.bz2  ZendOptimizer-3.3.9-linux-glibc23-x86_64.tar.gz
 
总结:不要追求高版本的软件,高版本的多少都会有一些bug。
 
在httpd-2.4.2.tar.bz2配置参数中删除“--enable-expries=shared”,因为在.configure --help中没有此参数,有此参数时编译不成功。httpd-2.4比httpd-2.2指令上有一些变动,默认下的工作模式不是worker,也不是prefork,是event了。还是用2.2的版本吧!
 
 
延伸阅读:http://bbs.chinaunix.net/thread-3682363-1-1.html
http://pingzhao1990.blog.163.com/blog/static/1135663422011101743358601/