LAMP的组件平台由四个组件组成,呈分层结构,每一层都提供了整个架构的一个关键部分:Linux:Linux处在最底层,提供操作系统。它的灵活性和可定制化的特点意味着它能够产生一种高度定制的平台,让其它组件在上面运行。其它组件运行于Linux之上,但是并不一定局限于Linux,也可以在MicrosoftWindows,MacOSX或UNIX上运行。Apache:Apache位于第二层,它是一个Web服务平台,提供可让用户获得Web页面的机制。Apache是一款功能强大、稳定、可支撑关键任务的Web服务器,Internet上超过50%的网站都使用它作为Web服务器。MySQL:MySQL是最流行的开源关系数据库管理系统,是LAMP的数据存储端。在Web应用程序中,所有帐户信息、产品信息、客户信息、业务数据和其他类型的信息都存储于数据库中,通过SQL语言可以很容易地查询这些信息。PHP/Perl:Perl是一种灵活的语言,特别是在处理文本要素的时候,这种灵活性使Perl很容易处理通过CGI接口提供的数据,灵活地运用文本文件和简单数据库支持动态要素。PHP是一种被广泛应用的开放源代码的多用途脚本语言,它可嵌入到HTML中,尤其适合web开发。可以使用PHP编写能访问MySQL数据库中的数据和Linux提供的一些特性的动态内容。
二、系统环境
系统平台:CentOSrelease5.8(Final)
Mysql版本:mysql-5.0.41.tar.gz
Php版本:php-5.2.6.tar.gz
三、安装前准备
1、库文件准备
在安装PHP之前,应先安装PHP5需要的最新版本库文件,例如libxml2、libmcrypt以及GD2库等文件。安装GD2库是为了让PHP5支持GIF、PNG和JPEG图片格式,所以在安装GD2库之前还要先安装最新的zlib、libpng、freetype和jpegsrc等库文件。而且中间还会穿插安装一些软件,读者可以按照本节提供的顺序安装。
autoconf-2.61.tar.gz
freetype-2.3.5.tar.gz
gd-2.0.35.tar.gz
jpegsrc.v6b.tar.gz
libmcrypt-2.5.8.tar.gz
libpng-1.2.31.tar.gz
libxml2-2.6.30.tar.gz
zlib-1.2.3.tar.gz
ZendOptimizer-3.2.6-linux-glibc21-i386.tar.gz
phpMyAdmin-3.0.0-rc1-all-languages.tar.gz
2、安装gcc、gcc-c++编译器
用gcc-v命令检查安装时使用的编译工作是否存在
如系统未安装,在系统联网的情况下使用yuminstallgcc和yuminstallgcc-c++安装
3、卸载默认的低版本环境
目前发行的Linux操作系统版本中,如果选择默认全部安装,就已经安装了LAMP环境,但是版本相对都比较低。我们可以再安装一个LAMP环境和原来的并存,但是这样做没有必要,因为同时只能开启一个LAMP环境。所要我们要在安装之前,先应检查一下系统中是否已经安装了低版本的环境,如果已经安装过了,停止原来的服务运行,或者把原来的环境卸载掉。
a.卸载Apache
说明:卸载软件包,--nodeps如果有连带关系,也强制卸载
#rm-rf*
说明:到原来的apache安装目录下,将其所有的安装目录和文件都删掉
b.卸载Mysql
#rpm-qa|grepmysql
#rpm-emysql-5.0.77-4.el5_4.2--nodeps
说明:卸载mysql
c.卸载Php
#rpm-qa|grepphp
#rpm-ephp-common-5.1.6-27.el5--nodeps
#rpm-ephp-ldap-5.1.6-27.el5--nodeps
#rpm-ephp-cli-5.1.6-27.el5--nodeps
#rpm-ephp-5.1.6-27.el5--nodeps
说明:卸载PHP
4、关闭selinux,清空防火墙规则
5、使用sshshell将windows下的13个源码包上传到/usr/local/src
6、解包
编写一个shell脚本tar.sh进行解包。
#!/bin/shcd/usr/local/srcls*.tar.gz>ls.listforTARin`catls.list`dotar-zxvf$TARdone
执行脚本tar.sh进行解包
7、将源码包*.tar.gz全都删除
四、安装LAMP
1、安装libxml2
#cd/usr/local/src/libxml2-2.6.30#./configure--prefix=/usr/local/libxml2#make&&makeinstall
2、安装libmcrypt
#cd/usr/local/src/libmcrypt-2.5.8#./configure--prefix=/usr/local/libmcrypt#make&&makeinstall
3、安装zlib
#cd/usr/local/src/zlib-1.2.3#./configure#make&&makeinstall
4、安装libpng
#cd/usr/local/src/libpng-1.2.31#./configure--prefix=/usr/local/libpng#make&&makeinstall
5、安装jpeg6
这个软件包安装有些特殊,其它软件包安装时如果目录不存在,会自动创建,但这个软件包安装时需要手动创建。
#mkdir/usr/local/jpeg6#mkdir/usr/local/jpeg6/bin#mkdir/usr/local/jpeg6/lib#mkdir/usr/local/jpeg6/include#mkdir-p/usr/local/jpeg6/man/man1#cd/usr/local/src/jpeg-6b#./configure--prefix=/usr/local/jpeg6/--enable-shared--enable-static#make&&makeinstall
6、安装freetype
#cd/usr/local/src/freetype-2.3.5#./configure--prefix=/usr/local/freetype#make#makeinstall
7、安装autoconf
#cd/usr/local/src/autoconf-2.61#./configure#make&&makeinstall
8、安装GD库
#cd/usr/local/src/gd-2.0.35#./configure\--prefix=/usr/local/gd2/\--enable-m4_pattern_allow\--with-zlib=/usr/local/zlib/\--with-jpeg=/usr/local/jpeg6/\--with-png=/usr/local/libpng/\--with-freetype=/usr/local/freetype/
#make
出现错误:
make[2]:***[gd_png.lo]Error1make[2]:Leavingdirectory`/usr/local/src/gd-2.0.35'make[1]:***[all-recursive]Error1make[1]:Leavingdirectory`/usr/local/src/gd-2.0.35'make:***[all]Error2
分析:这个问题是因为gd库中的gd_png.c这个源文件中包含png.h时,png.h没有找到导致的。
解决:
在编译文件里
#vigd_png.c
将include“png.h”改成include“/usr/local/libpng/include/png.h”
其中/usr/local/libpng/为libpng安装路径。
#makeinstall
9、安装Apache
10、配置Apache
启动Apache#/usr/local/apache2/bin/apachectlstart
关闭Apache#/usr/local/apache2/bin/apachectlstop
查看80端口是否开启#netstat-tnl|grep80
访问Apache服务器
添加自启动#echo"/usr/local/apache2/bin/apachectlstart">>/etc/rc.d/rc.local
11、安装Mysql
添加一个mysql标准组#groupaddmysql
添加mysql用户并加到mysql组中#useradd-gmysqlmysql
#cd/usr/local/src/mysql-5.0.41#./configure\--prefix=/usr/local/mysql/\--with-extra-charsets=all
checkingfortgetentin-lncurses...nocheckingfortgetentin-lcurses...nocheckingfortgetentin-ltermcap...nocheckingfortgetentin-ltinfo...nocheckingfortermcapfunctionslibrary...configure:error:Nocurses/termcaplibraryfound
分析:缺少ncurses安装包
#yuminstallncurses-devel
#make&&makeinstall
12、配置Mysql
创建MySQL数据库服务器的配置文件#cpsupport-files/my-medium.cnf/etc/my.cnf
将文件的所有属性改为root用户#chown-Rroot/usr/local/mysql
将数据目录的所有属性改为mysql用户#chown-Rmysql/usr/local/mysql/var
将组属性改为mysql组#chgrp-Rmysql/usr/local/mysql
启动数据库#/usr/local/mysql/bin/mysqld_safe--user=mysql&
查看3306端口是否开启#netstat-tnl|grep3306
简单的测试#/usr/local/mysql/bin/mysqladminversion
查看所有mysql参数#/usr/local/mysql/bin/mysqladminvariables
设置Mysql开机自启动#cp/usr/local/src/mysql-5.0.41/support-files/mysql.server/etc/rc.d/init.d/mysqld#chownroot.root/etc/rc.d/init.d/mysqld#chmod755/etc/rc.d/init.d/mysqld#chkconfig--addmysqld#chkconfig--listmysqld#chkconfig--levels245mysqldoff
13、Mysql安全性设置
查看mysql用户权限信息mysql>select*frommysql.user;
删除非localhost的主机mysql>DELETEFROMmysql.userWHEREHost='localhost'ANDUser='';
为root用户添加密码mysql>SETPASSWORDFOR'root'@'localhost'=PASSWORD('abc123');
再次进入Mysql客户端#/usr/local/mysql/bin/mysql-uroot-hlocalhost-p
关闭MySQL数据库#/usr/local/mysql/bin/mysqladmin-uroot-pshutdown
14、安装PHP
#cd/usr/local/src/php-5.2.6#./configure\--prefix=/usr/local/php\--with-config-file-path=/usr/local/php/etc\--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/jpeg6/\--with-freetype-dir=/usr/local/freetype/\--with-gd=/usr/local/gd2/\--with-zlib-dir=/usr/local/zlib/\--with-mcrypt=/usr/local/libmcrypt/\--with-mysqli=/usr/local/mysql/bin/mysql_config\--enable-soap\--enable-mbstring=all\--enable-sockets#make&&makeinstall
15、配置PHP
创建配置文件#cpphp.ini-dist/usr/local/php/etc/php.ini
重启Apache#/usr/local/apache2/bin/apachectlrestart
16、安装Zend加速器
#cd/usr/local/src/ZendOptimizer-3.2.6-linux-glibc21-i386/#./install.sh
17、安装phpMyAdmin
拷贝目录到指定位置并改名为phpmyadmin
#cp-aphpMyAdmin-3.0.0-rc1-all-languages/usr/local/apache2/htdocs/phpmyadmin
#cd/usr/local/apache2/htdocs/phpmyadmin/
#cpconfig.sample.inc.phpconfig.inc.php
18、配置phpMyAdmin
#vi/usr/local/apache2/htdocs/phpmyadmin/config.inc.php