您的位置:首页 > 运维架构 > Linux

Lamp(linux redhat-5.4)环境的搭建

2013-04-17 09:16 627 查看
顾名思义,lamp既是linux apache mysql php 的首字母缩写,下面小编将用源码实现lamp环境的搭建,步骤如下:
1. 安装apache-2.4.4  
2. 安装mysql-5.6.10
3. 安装php-5.4.13  安装该软件时注意与apache服务和mysql数据库的关联
4. 测试
下面就让我们开始吧:
1.  Apache2.4.4的安装:这个版本的apache安装的必须的四个文件apr  apr-util  pcre和httpd-2.4.4  pcre你可以使用系统(redhat5.4)自带的,小编在这里用的是自己下的,解压如下:
[root@rhel5 ~]# tar -jxvf apr-1.4.6.tar.bz2 -C /usr/local/src/
[root@rhel5 ~]# tar -jxvf apr-util-1.5.1.tar.bz2 -C /usr/local/src/
[root@rhel5 ~]# tar -jxvf pcre-8.32.tar.bz2 -C /usr/local/src/
[root@rhel5 ~]# tar -jxvf httpd-2.4.4.tar.bz2 -C /usr/local/src/
Apr文件安装:
[root@rhel5 ~]#cd /usr/local/src/apr-1.4.6/   
[root@rhel5 apr-1.4.6]#./configure  --prefix=/usr/local/apr
[root@rhel5 apr-1.4.6]#make && make install
Apr-util 文件安装
[root@rhel5 apr-1.4.6]#cd ../apr-util-1.5.1
[root@rhel5 apr-util-1.5.1]#./configure  --prefix=/usr/local/apr-util
--with-apr=/usr/local/apr/bin/apr-1-config      //关联apr文件
[root@rhel5 apr-util-1.5.1]#make &&make install
Pcre的源码安装和上面的一样,小编就不例举了
Apache 安装
[root@rhel5 ~]#cd /usr/local/src/httpd-2.4.4/



//安装apache后面所加的参数
[root@rhel5 httpd-2.4.4]#make && make install
切换到apache目录下,查看形成的文件。由于安装的路径并不是系统默认的路径,而每执行一次命令都要指明路径很麻烦,所以我们就把安装文件所形成的头文件目录include、库文件目录lib、可执行的二进制文件目录bin和配置文件xxx.conf/cnf与系统关联起来,下面其他源码的安装也是一样的。



关联头文件目录(利用软链接):



关联库文件目录(创建并编辑库连接文件,编写路径和语句如下):



重新加载lib库的缓存



【关联apache/bin目录方法1】实现系统控制apache的开启与关闭(在/etc/init.d/目录下编写名为httpd的脚本),接受开机自动关闭与开启(chkconfig)的管理:
a.脚本如下:
[root@rhel5 ~]#vim /etc/rc.d/init.d/httpd
  1 #!/bin/bash 
  2 #chkconfig: 2345 90 70           //接受chkconfig管理的关键两行2,3行
  3 #description: httpd server
  4 . /etc/init.d/functions
  5 #dinf path
  6 HTTPD='/usr/local/apache/bin/httpd'
  7 CONF='/etc/httpd/httpd.conf'
  8 #dinf function
  9 start ()  {
10      echo -n "httpd is starting...."
11      sleep 1
12      $HTTPD  -f $CONF
13      [  $? -eq 0 ] &&touch /var/lock/subsys/http && echo -e "\033[31m  OK  \033[0m  " || echo -e "It is \033[31m  FAIL \033[0m"        
14 }
15        
16 stop () {      
17      echo -n "httpd is stoping...."
18      sleep 1
19      killproc $HTTPD && echo -e && rm -rf /var/lock/subsys/http || echo -e "It is \033[31m FAIL \033[0m "
20 }      
21        
22 restart (){    
23      [ -f /var/lock/subsys/http ] && stop && start || echo -e "\033[31m httpd is stopd\033[0m"
24 }
25        
26 case $1 in     
27         start)
28                 start
29         ;;
30         stop)
31                 stop
32         ;;
33         restart)
34                 restart
35         ;;
36
37         *)
38                 echo "Usage: {start|stop|restart}"
39         ;;
40 esac
b.接受chkconfig 的管理



[root@rhel5 ~]#vim /etc/httpd/httpd.conf   //不是源码安装,所以配置没在标准路径/etc/httpd/conf/ 目录下:



到此apache-2.4.4的安装已基本完成。
2. 数据库Mysq-5.6.10的安装。这个版本的mysql安装需要借助于cmake工具,小编准备了两个软件包cmake和mysql。cmake安装之后的作用相当于./configure。
解压软件包cmake和mysql:
[root@rhel5 ~]# tar -zxvf cmake-2.8.4.tar.gz -C /usr/local/src/
[root@rhel5 ~]# tar -zxvf mysql-5.6.10.tar.gz -C /usr/local/src/
安装cmake工具:
[root@rhel5 ~]#cd /usr/local/src/cmake-2.8.4
[root@rhel5 cmake-2.8.4]#./configure
[root@rhel5 cmake-2.8.4]#make && make install
安装mysql-5.6.10数据库
[root@rhel5 cmake-2.8.4]#cd ../mysql-5.6.10
[root@rhel5 mysql-5.6.10]#cmake .          //此处的cmake . 相当于./configure
[root@rhel5 mysql-5.6.10]#make && make install
配置文件在执行./configure 时就已经指定的/etc目录下面了
【关联mysql/bin目录方法2】:
[root@rhel5 mysql]# vim /etc/profile       



关联头文件目录:



数据库的使用


增加用户和密码后的登录方式



Mysql  的安装到此就基本结束了
3. 安装php-5.4.13  php的安装就相对简单了,只不过在要注意与数据库mysql和apache服务的关联(注意:是在执行./configure 时,后面跟的参数)。
解压并安装php



[root@rhel5 ~]#cd /usr/local/src/php-5.4.13    //注意./configure后面的参数



关联头文件



关联bin目录



关联库文件



重新加载lib库的缓存,并查看、编辑apache配置文件



在包的安装目录下查看INSTALL文件,并把238行的配置语句复制到apache的配置文件(如下面的第三幅图)。









//httpd的配置文件已打开(vim /etc/httpd/httpd.conf)
增加支持动态页面功能



由于apache配置文件的更改,apache服务需重启
[root@rhel5 ~]#service httpd restart
查看apache服务里是否形成了php模块



到此php,mysql,apache的配置和安装已基本结束,下面就让我们来测验一下。
4. 测试
Php网页测试



结果(工作正常):



与mysql数据库的链接测试



结果(功能正常):



停用mysql数据库



结果正常



重新启用mysql数据库



结果正常


内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签:  lamp环境搭建