LAMP环境搭建
一、 系统环境
系统平台:CentOS-5.6-i386
Apache版本:httpd-2.2.27.tar.gz Mysql 版本:mysql-5.1.59.tar
Php版本:php-5.3.27.tar(下载地址:
http://cn2.php.net/distributions/php-5.2.5.tar.bz2)
Zend版本:ZendOptimizer-3.3.3-linux-glibc23-i386.tar.gz
二、 安装前准备
1、 库文件准备
在安装PHP之前,应先安装PHP5需要的最新版本库文件,例如libxml2、libmcrypt以及GD2库等文件。安装GD2库是为了让PHP5支 持GIF、PNG和JPEG图片格式,在安装GD2库之前还要先安装最新的zlib、libpng、freetype和jpegsrc等库文件。而且中间还会穿插安装一些软件,根据情况顺序安装。 autoconf-2.69.tar.gz freetype-2.3.5.tar.bz2 gd-2.0.32.tar.gz jpegsrc.v6b.tar.gz libmcrypt-2.5.8.tar.gz libpng-1.2.10.tar.bz2 libxml2-2.9.0.tar.gz zlib-1.2.3.tar.gz
ZendOptimizer-3.3.3-linux-glibc23-i386.tar.gz
phpMyAdmin-3.5.0-all-languages.tar.bz2
2、 安装gcc、gcc-c++编译器
用gcc -v 命令检查安装时使用的编译工作是否存在如系统未安装,在系统联网的情况下使用yum install gcc和yum install gcc-c++安装。
3、 卸载默认的低版本环境
目前发行的Linux操作系统版本中,如果选择默认全部安装,就已经安装了LAMP环境,但是版本相对都比较低。我们可以再安装一个LAMP环境和原来的并存,但是这样做没有必要,因为同时只能开启一个LAMP环境。所要我们要在安装之前,先应检查一下系统中是否已经安装了低版本的环境,如果已经安装过了,停止原来的服务运行,或者把原来的环境卸载掉。
(1) 卸载Apache
#rpm -qa | grep httpd
说明:检查是否安装了httpd软件包
# rpm -e httpd-2.2.3-63.el5.centos --nodeps说明:卸载软件包, --nodeps 如果有连带关系,也强制卸载# cd /etc/httpd/
#rm -rf *
说明:到原来的apache安装目录下,将其所有的安装目录和文件都删掉
(2) 卸载Mysql
#rpm -qa | grep mysql
# rpm -e mysql-5.0.77-4.el5_4.2 --nodeps
(3) 卸载Php
#rpm -qa | grep php
#rpm -e php-common-5.1.6-27.el5 –nodeps #rpm -e php-ldap-5.1.6-27.el5 --nodeps #rpm -e php-cli-5.1.6-27.el5 --nodeps #rpm -e php-5.1.6-27.el5 --nodeps
三、 安装库文件
1、 安装libxml2
#cd /usr/local/src/libxml2-2.9.0.tar.gz #./configure --prefix=/usr/local/libxml2 #make && make install
2、 安装libmcrypt
#cd /usr/local/src/libmcrypt-2.5.8.tar.gz #./configure --prefix=/usr/local/libmcrypt #make && make install
3、 安装zlib
#cd /usr/local/src/zlib-1.2.3 #./configure
#make && make install
4、 安装libpng
#cd /usr/local/src/libpng-1.2.10.tar.bz2 #./configure --prefix=/usr/local/libpng #make && make install
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 && make install
6、 安装freetype
#cd /usr/local/src/freetype-2.3.5.tar.bz2 #./configure --prefix=/usr/local/freetype #make
#make install 7、 安装autoconf
#cd /usr/local/src/autoconf-2.69.tar.gz #./configure
#make && make install
四、 安装apache
版本:httpd-2.2.27.tar.gz 1、 安装apache步骤
#tar zxvf httpd-2.2.27.tar.gz #cd httpd-2.2.5
#./configure --prefix=/usr/local/apache2 --with-zlib=/usr/local/zlib/ --with-apr=/usr/local/apr/ --with-apr-util=/usr/local/apr-util/ --enable-so --enable-deflate=shared --enable-expires=shared --enable-rewrite=shared --enable-static-support
执行完如下:
config.status: creating build/rules.mk config.status: creating build/pkg/pkginfo config.status: creating build/config_vars.sh config.status: creating include/ap_config_auto.h config.status: executing default commands
#make
执行完如下:
-version mod_rewrite.lo make[4]: Leaving directory `/root/lamp-pkg/apache2/httpd-2.2.5/modules/mappers'
make[3]: Leaving directory `/root/lamp-pkg/apache2/httpd-2.2.5/modules/mappers'
make[2]: Leaving directory `/root/lamp-pkg/apache2/httpd-2.2.5/modules' make[2]: Entering directory `/root/lamp-pkg/apache2/httpd-2.2.5/support' make[2]: Leaving directory `/root/lamp-pkg/apache2/httpd-2.2.5/support'
make[1]: Leaving directory `/root/lamp-pkg/apache2/httpd-2.2.5'
#make install 执行完如下:
Installing man pages and online manual mkdir /usr/local/apache2/man
mkdir /usr/local/apache2/man/man1 mkdir /usr/local/apache2/man/man8 mkdir /usr/local/apache2/manual
make[1]: Leaving directory `/root/lamp-pkg/apache2/httpd-2.2.5'
2、配置apache
#/usr/local/apache/bin/apachectl start
#cp /usr/local/apache/bin/apachectl /etc/init.d/httpd #chmod +x /etc/init.d/httpd #chkconfig --add httpd
提示service httpd does not support chkconfig错误 解决办法:编辑/etc/rc.d/init.d/httpd在文件第二行加入 #chkconfig:2345 10 90
#description:Activates/Deactivates Apache Web Server # chkconfig --level 2345 httpd on # service httpd restart
开机自动启动apache的另一种方法: 修改/etc/rc.local文件 # vim /etc/rc.local
在文件中添加/usr/local/apache/bin/apachectl start
五、 安装Mysql
版本mysql-5.1.59.tar.gz 1、 安装ncurses
#yum install ncurses-devel 添加一个mysql标准组 # groupadd mysql
添加mysql用户并加到mysql组中 # useradd -g mysql mysql
#./configure --prefix=/usr/local/mysql/ --with-extra-charsets=all 执行如下:
config.status: executing default commands Thank you for choosing MySQL!
Remember to check the platform specific part of the reference manual for hints about installing MySQL on your platform. Also have a look at the files in the Docs directory.
#make
执行如下:时间有点长
make[2]: Leaving directory `/root/lamp-pkg/mysql/mysql-5.1.59/server-tools/instance-manager'
make[1]: Leaving directory `/root/lamp-pkg/mysql/mysql-5.1.59/server-tools'
Making all in win
make[1]: Entering directory `/root/lamp-pkg/mysql/mysql-5.1.59/win' make[1]: Nothing to be done for `all'.
make[1]: Leaving directory `/root/lamp-pkg/mysql/mysql-5.1.59/win'
#make install 执行如下:
Making install in win
make[1]: Entering directory `/root/lamp-pkg/mysql/mysql-5.1.59/win' make[2]: Entering directory `/root/lamp-pkg/mysql/mysql-5.1.59/win' make[2]: Nothing to be done for `install-exec-am'. make[2]: Nothing to be done for `install-data-am'.
make[2]: Leaving directory `/root/lamp-pkg/mysql/mysql-5.1.59/win' make[1]: Leaving directory `/root/lamp-pkg/mysql/mysql-5.1.59/win'
2、 配置mysql
创建MySQL数据库服务器的配置文件
# cp support-files/my-medium.cnf /etc/my.cnf
用mysql用户创建授权表,创建成功后,会在/usr/local/mysql目录下生成一个var目录
# /usr/local/mysql/bin/mysql_install_db --user=mysql 将文件的所有属性改为root用户 # chown -R root /usr/local/mysql 将数据目录的所有属性改为mysql用户 # chown -R mysql /usr/local/mysql/var 将组属性改为mysql组
# chgrp -R mysql /usr/local/mysql 查看3306端口是否开启 # netstat -tnl|grep 3306 简单的测试
# /usr/local/mysql/bin/mysqladmin version 查看所有mysql参数
# /usr/local/mysql/bin/mysqladmin variables 设置Mysql开机自启动 # cp /usr/local/src/mysql-5.0.41/support-files/mysql.server /etc/rc.d/init.d/mysqld
#chown root.root /etc/rc.d/init.d/mysqld #chmod 755 /etc/rc.d/init.d/mysqld #chkconfig --add mysqld #chkconfig --list mysqld
#chkconfig --levels 245 mysqld off
3、 Mysql安全性设置