1.LAMP介绍 LAMP 指的Linux (操作系统)、 ApacheHTTP 服务器, MySQL(数据库软件) 和PHP(有时也是指Perl或 Python) 的第一个字母,一般用来建立的web 服务器。
虽然这些开放源代码程序本身并不是专门设计成同另几个程序一起工作的,但由于它们的免费和开源,这个组合开始流行(大多数Linux发行版本捆绑了这些软件)。当一起使用的时候,它们表现的像一个具有活力的解决方案包。其他的方案包有苹果的WebObjects(最初是应用服务器),Java/J2EE和微软的.NET架构。
LAMP包的脚本组件中包括了CGIweb接口,它在90年代初期变得流行。这个技术允许网页浏览器的用户在服务器上执行一个程序,并且和接受静态的内容一样接受动态的内容。程序员使用脚本语言来创建这些程序因为它们能很容易有效的操作文本流,甚至当这些文本流并非源自程序自身时也是。正是由于这个原因系统设计者经常称这些脚本语言为胶水语言。
2.所用软件包
httpd-2.2.19.tar.bz2
mysql-5.5.15-linux2.6-i686.tar.gz
php-5.3.7.tar.bz2
3.lamp环境搭建
1)配置本地yum客户端用来安装必要的软件组
[root@xht ~]# mount /dev/cdrom /mnt/cdrom //挂载光盘
[root@xht ~]# vim /etc/yum.repos.d/rhel-debuginfo.repo
配置文件如下图
确定所需要的软件组
[root@xht ~]# yum grouplist
X 软件开发
开发工具
开发库
Java开发
老的软件开发
2)安装mysql
把mysql-5.5.15-linux2.6-i686.tar.gz拆解到/usr/local目录下
[root@xht ~]# tar -zxvf mysql-5.5.15-linux2.6-i686.tar.gz -C /usr/local /
解压后所形成的目录如下图
查看目录下的文件,如下图
查看 mysql-5.5.15-linux2.6-i686的安装文件
按照安装文件进行如下操作
[root@xht ~]# groupadd mysql //创建mysql组
[root@xht ~]# useradd -r -g mysql mysql //创建mysql用户并属于mysql组
[root@xht ~]# cd /usr/local
[root@xht local]# ln -s mysql-5.5.15-linux2.6-i686 mysql //建立软连接
[root@xht local]# cd mysql
修改mysql目录下的所有文件及目录所有者所属组为mysql
[root@xht mysql]# chown -R mysql .
[root@xht mysql]# chgrp -R mysql .
初始化mysql
[root@xht mysql]# scripts/mysql_install_db --user=mysql
把所有者和所属组该为root
[root@xht mysql]# chown -R root .
把data的所有者改为mysql
[root@xht mysql]# chown -R mysql data
[root@xht mysql]# bin/mysqld_safe --user=mysql & //开启服务
设置用service来管理mysql
[root@xht mysql]# cp support-files/mysql.server /etc/init.d/mysqld
[root@localhost ~]# chkconfig --add| mysqld //设置用chkconfig管理mysqld
[root@localhost mysql]# cd /etc/ld.so.conf.d/
[root@localhost ld.so.conf.d]# vim mysql.conf
创建mysql.conf文件指定库文件目录
加载库文件测试
[root@localhost ld.so.conf.d]# ldconfig -v |grep mysql
/usr/local/mysql/lib:
libmysqlclient.so.18 -> libmysqlclient_r.so.18.0.0
在/usr/include下为mysql的头文件建立软连接
[root@localhost mysql]# cd /usr/include
[root@localhost include]# ln -s /usr/local/mysql/include mysql
3)httpd-2.2.19.tar.bz2的源码安装
[root@localhost ~]# tar jxvf httpd-2.2.19.tar.bz2 -C /usr/local/src //拆解到/usr/local/src目录下
[root@localhost ~]# cd /usr/local/src
[root@localhost src]# ll
总计 4
drwxr-xr-x 11 xht xht 4096 2011-05-21 httpd-2.2.19
运行./config;安装目录为/usr/local/apache;配置文件目录为/etc/httpd;开启ssl功能;开启压缩功能
[root@localhost httpd-2.2.19]# ./configure --prefix=/usr/local/apache --sysconfdir=/etc/httpd --enable-so --enable-ssl --with-z
[root@localhost httpd-2.2.19]# make //编译
[root@localhost httpd-2.2.19]# make install //安装
[root@localhost httpd-2.2.19]# cd /usr/local/apache // 安装后切换到/usr/local/apache目录
查看目录下的内容
[root@localhost bin]# ./apachectl start //启动http服务
[root@localhost bin]# vim /etc/rc.local // 把http加入开机脚本
[root@localhost apache]# cd /etc/ld.so.conf.d/
创建http.conf 文件指定http库文件目录
[root@localhost ld.so.conf.d]# vim httpd.conf
文件内容
在/usr/include/下为apache头文件建立软连接
[root@localhost ld.so.conf.d]# cd /usr/include/
[root@localhost include]# ln -s /usr/local/apache/include apache
4)Php的 源码安装
拆解到/usr/local/src目录下
[root@localhost ~]# tar jxvf php-5.3.7.tar.bz2 -C /usr/local/src/
[root@localhost src]# cd php-5.3.7/
查看安装文件
[root@localhost php-5.3.7]# less INSTALL
检测预编译环境
[[email protected]]#./configure --prefix=/usr/local/php //安装目录
将php编译成apache的模块,允许apache的apxx调用该模块
--with-apxs2=/usr/local/apache/bin/apxs
--with-mysql=/usr/local/mysql 指明mysql的安装位置
--with-mysql=/usr/local/mysql
--with-mysqli=/usr/local/mysql/bin/mysql_config调用myql接口
--with-mysqli=/usr/local/mysql/bin/mysql_config
支持宽字符
--enable-mbstring=all
编译
[[email protected]]#make
安装测试
[root@localhost php-5.3.7]# make install
[root@localhost php-5.3.7]# cd /usr/local/apache/htdocs
测试apache测试信息如下
测试php
[root@localhost htdocs]# mv php.html index.php
[root@localhost htdocs]# vim index.php
写入内容为
<?
phpinfo();
?>
编辑apache配置文件
[root@localhost htdocs]# vim /etc/httpd/httpd.conf
在httpd.conf 加入 AddType application/x-httpd-php .php
关闭并重启服务
[root@localhost htdocs]# /usr/local/apache/bin/apachectl stop
[root@localhost htdocs]# /usr/local/apache/bin/apachectl start
测试php页面如下
测试php调用mysql
[root@localhost htdocs]# vim index.php
测试页面如下
测试mysql
[root@localhost htdocs]# /usr/local/mysql/bin/mysql
创建数据库xht1
mysql> create database xht1;
至此lamp环境搭建成功。