在CentOS6上使用源码编译LAMP平台

LAMP源码编译总结

    最近在学习重要的Web服务,当然也就少不了很重要的httpd和php.而动态网站必定又会使用数据库如mysql之类的,那么,今天就总结一下最近做的LAMP平台编译实验。具体过程如下。

实验名:在CentOS6上使用源码编译LAMP平台

实验环境:CentOS6.5,安装时选择了使用最多的两个开发包组。

          使用系统默认基本yum源+epel6源(aliyun: http://mirrors.aliyun.com/repo/epel-6.repo)

          使用源码包:httpd-2.4.9 ;二进制安装包mysql-5.5.33 ;php-5.4.26

实验步骤:

一.安装httpd服务


1.安装httpd的依赖软件包。

    安装apr-1.5.0

    # tar xf apr-1.5.0.tar.bz2

    # cd apr-1.5.0

    # ./configure –prefix=/usr/local/apr

    # make && make install

    安装apr-util-1.5.3

    # tar xf apr-util-1.5.3.tar.bz2

    # cd apr-util-1.5.3

    # ./configure –prefix=/usr/local/apr-util –with-apr=/usr/local/apr

    # make && make install

    若httpd有可能要支持ssl请要安装openssl及openssl-devel.另,若有安装,请查看是否这两个包有     更新过。

    另编译过程中也会使用pcre,请在编译httpd前安装,系统安装盘是有这个包的。

2.接着就是解压httpd的源码包并安装了,使用如下命令:

    

    # tar xf httpd-2.4.9.tar.bz2

    # cd httpd-2.4.9

    # ./configure –prefix=/usr/local/apache –sysconfdir=/etc/httpd24 –enable-so –enable-ssl –enable-cgi –enable-rewrite –with-zlib –with-pcre –with-apr=/usr/local/apr –with-apr-util=/usr/local/apr-util –enable-modules=most –enable-mpms-shared=all –with-mpm=event

说一下./configure里面的参数吧。

第一个参数–prefix是设定安装目录的;

第二个是服务的配置文件存放目录;

第三个是开启动态模块的选项;

第四个是编译并启用ssl模块;

第五个是启用CGI功能;

第六个是rewrite;

第七个是编译数据压缩相关模块;

第八个是使用pcre,这个一个perl的正则匹配类的函数库;

第九个是指明apr的路径;

第十个指明apr-utin的路径;

第十一个是编译最多的模块;

第十二个是构建mpm为动态模块并编译所有支持的模式;

第十三个是指明默认mpm模块为event事件处理方式。

注:最后两个选项很重要,不太明白请搜索关键字“构建MPM模块”

3.好了,一会后,检查发现没有问题,就make && make install安装吧。

。。。。。一会就安装好了。

4.接着,修改主配置文件中的Pid文件路径。

5.编辑/etc/httpd/httpd.conf,添加如下行即可:

PidFile  "/var/run/httpd.pid"

6.最后,是提供SysV脚本,以方便我们管理服务。

编辑一个/etc/rc.d/init.d/httpd ,将以下内容放进去并保存就好了。

#!/bin/bash
#
# httpd        Startup script for the Apache HTTP Server
#
# chkconfig: - 85 15
# description: Apache is a World Wide Web server.  It is used to serve \\
#        HTML files and CGI.
# processname: httpd
# config: /etc/httpd/conf/httpd.conf
# config: /etc/sysconfig/httpd
# pidfile: /var/run/httpd.pid

# Source function library.
. /etc/rc.d/init.d/functions

if [ -f /etc/sysconfig/httpd ]; then
        . /etc/sysconfig/httpd
fi

# Start httpd in the C locale by default.
HTTPD_LANG=${HTTPD_LANG-"C"}

# This will prevent initlog from swallowing up a pass-phrase prompt if
# mod_ssl needs a pass-phrase from the user.
INITLOG_ARGS=""

# Set HTTPD=/usr/sbin/httpd.worker in /etc/sysconfig/httpd to use a server
# with the thread-based "worker" MPM; BE WARNED that some modules may not
# work correctly with a thread-based MPM; notably PHP will refuse to start.

# Path to the apachectl script, server binary, and short-form for messages.
apachectl=/usr/local/apache/bin/apachectl
httpd=${HTTPD-/usr/local/apache/bin/httpd}
prog=httpd
pidfile=${PIDFILE-/var/run/httpd.pid}
lockfile=${LOCKFILE-/var/lock/subsys/httpd}
RETVAL=0

start() {
        echo -n $"Starting $prog: "
        LANG=$HTTPD_LANG daemon --pidfile=${pidfile} $httpd $OPTIONS
        RETVAL=$?
        echo
        [ $RETVAL = 0 ] && touch ${lockfile}
        return $RETVAL
}

stop() {
  echo -n $"Stopping $prog: "
  killproc -p ${pidfile} -d 10 $httpd
  RETVAL=$?
  echo
  [ $RETVAL = 0 ] && rm -f ${lockfile} ${pidfile}
}
reload() {
    echo -n $"Reloading $prog: "
    if ! LANG=$HTTPD_LANG $httpd $OPTIONS -t >&/dev/null; then
        RETVAL=$?
        echo $"not reloading due to configuration syntax error"
        failure $"not reloading $httpd due to configuration syntax error"
    else
        killproc -p ${pidfile} $httpd -HUP
        RETVAL=$?
    fi
    echo
}

# See how we were called.
case "$1" in
  start)
  start
  ;;
  stop)
  stop
  ;;
  status)
        status -p ${pidfile} $httpd
  RETVAL=$?
  ;;
  restart)
  stop
  start
  ;;
  condrestart)
  if [ -f ${pidfile} ] ; then
    stop
    start
  fi
  ;;
  reload)
        reload
  ;;
  graceful|help|configtest|fullstatus)
  $apachectl $@
  RETVAL=$?
  ;;
  *)
  echo $"Usage: $prog {start|stop|restart|condrestart|reload|status|fullstatus|graceful|help|configtest}"
  exit 1
esac

exit $RETVAL

7.添加脚本的执行权限后(# chmod +x /etc/rc.d/init.d/httpd)。最后,是不是应该把这个服务加入系统开机启动中呢,明显是必须的嘛。

# chkconfig –add httpd

8.这就是安好apache了哈,不过测试访问前请记得关掉或放行iptables哦。

我来测试一下。

在CentOS6上使用源码编译LAMP平台apache.png

再接再厉,我们接着装第二个,mysql服务。

  1. 安装前先准备好数据存放的目录和服务运行的用户。设置目录是为了方便以后数据库的数据管理哈,设置用户是为了安全。

    #mkdir -pv /mydata/data

    #groupadd -r mysql

    #useradd -g mysql -r -s /sbin/nologin -M -d /mydata/data mysql

    #chown -R mysql:mysql /mydata/data

2.解压下载好的二进制安装包并初始化mysql,千万千万要下对版本,我就下错版本白忙了3个小时。  

    #tar xf mysql-5.5.33-linux2.6-i686.tar.gz -C /usr/local

    #cd /usr/local/

    #ln -sv mysql-5.5.33-linux2.6-i686  mysql

    #cd mysql 

    #chown -R mysql:mysql  .

    #scripts/mysql_install_db –user=mysql –datadir=/mydata/data

    #chown -R root  .

3.为Mysql提供主配置文件

    方法是把解压目录下的样例配置文件拷贝并修改。

    #cd /usr/local/mysql

    #cp support-files/my-large.cnf  /etc/my.cnf

    修改my.cnf文件中的thread_concurrency的值为你的CPU个数乘以2(此值是mysql运行使用的系统CPU资源设定),并添加datadir = /mydata/data,这就是设置我们第一步新建的数据目录了。

4.然后当然也是提供SysV脚本了

    不过这一次我们不用建文件,直接有样例,拷贝就好。

    #cd /usr/local/mysql

    #cp support-files/mysql.server  /etc/rc.d/init.d/mysqld

    #chmod +x /etc/rc.d/init.d/mysqld

5.同样的加入系统启动服务

    #chkconfig –add mysqld

    #chkconfig mysqld on

然后我们就可以启动了。#service mysqld start

6.输出mysql的man手册至man命令的查找路径

    编辑/etc/man.config,添加 MANPATH  /usr/local/mysql/man

7.输出mysql的头文件至系统头文件路径/usr/include    

    通过简单的创建链接实现:

    #ln -sv /usr/local/mysql/include  /usr/include/mysql

8.输出mysql的库文件给系统库查找路径

    # echo '/usr/local/mysql/lib' > /etc/ld.so.conf.d/mysql.conf

    系统重载系统库 # ldconfig

9.修改系统PATH变量。修改/etc/profile或~/.profile或/etc/bashrc或~/.bashrc

这样就完成了mysql的安装了。

在CentOS6上使用源码编译LAMP平台二进制包Mysql安装成功提示.jpg

三.php的安装

  1. 安装依赖软件包。

    若没有安装两个开发包,请先安装。

    另外要安装bzip2-devel及libmcrypt-devel,后一个是epel的软件包哈。

    #yum -y install bzip2-devel libmcrypt-devel 

  2. 解压编译安装php-5.4.26

    #tar xf php-5.4.26.tar.bz2

    #cd php-5.4.26

    #./configure –prefix=/usr/local/php –with-mysql=/usr/local/mysql –with-openssl –with-mysqli=/usr/local/mysql/bin/mysql_config –enable-mbstring –with-freetype-dir –with-jpeg-dir –with-png-dir –with-zlib –with-libxml-dir=/usr –enable-xml  –enable-sockets –with-apxs2=/usr/local/apache/bin/apxs –with-mcrypt  –with-config-file-path=/etc –with-config-file-scan-dir=/etc/php.d –with-bz2  –enable-maintainer-zts

同样的解释一下./configure的参数。

第一个是安装的目录

第二个是使用mysql

第三个是使用openssl

第四个是使用mysqli这种方式连接mysql

第五个是不同语言的编码(如ISO-8859,utf-8等等)能够正常转换的函数库

第六个是用于显示各种各样的字体的

第七、八个分别是激活对jpeg、png的支持

第九个说过了

第十个、十一个是对xml的支持

第十二个是开启sockets

第十三个是对apache扩展模块的支持

第十四个是支持加密

第十五、十六个是配置文件目录和扩展配置文件所在目录

第十七个是支持压缩传输

第十八个是支持apache的多种MPM

检查通过我们就make && make install吧。

3.为php提供配置文件:

    #cp php.ini-production /etc/php.ini

4.编辑apache配置文件httpd.conf,以apache支持php

    # vim /etc/httpd/httpd.conf

     添加如下二行

     AddType application/x-httpd-php  .php

     AddType application/x-httpd-php-source  .phps

     定位至DirectoryIndex index.html 

     修改为:

     DirectoryIndex  index.php  index.html

好了,这样基本也就配置完成LAMP了,试试结果。

先提供测试页面。

    #vim /usr/local/apache/htdocs/index.php

    写入

          $link = mysql_connect('127.0.0.1','root','');

          if ($link)

            echo "Success…";

          else

            echo "Failure…";

          mysql_close();

    ?>

    保存退出。

嗯,测试之前别忘了,刚才改过apache的配置文件,要重启一下httpd哈。

    #service httpd restart

看一下测试结果。

在CentOS6上使用源码编译LAMP平台LAMP.jpg

作为linux最常用的平台,我会多练N次直到我能不看文档就能熟练安装的,请各位同仁也加油吧

    ヽ(.◕ฺˇд ˇ◕ฺ;)ノ ヽ(.◕ฺˇд ˇ◕ฺ;)ノ ヽ(.◕ฺˇд ˇ◕ฺ;)ノ

51CTO发布文章大姨妈了……

原创文章,作者:北京-清虚,如若转载,请注明出处:http://www.178linux.com/4890

(0)
上一篇 2015-06-01 19:07
下一篇 2015-06-01 19:14

相关推荐

  • 关于 磁盘、文件系统管理

                   磁盘、文件系统管理               1  设备识别2  设备分区3 …

    系统运维 2016-08-30
  • lvs笔记之nat&dr模型简单实现

    lvs笔记之nat&dr模型简单实现 lvs笔记之nat&dr模型简单实现 lvs 集群 实现 负载均衡 nat lvs笔记之nat&dr模型简单实现 ipvsadm使用说明 lvs-nat的简单实现 踩过的坑1 lvs-dr实现 总结 ipvsadm使用说明     -A: 添加一个…

    2017-01-03
  • CentOS 7上配置php-fpm

    CentOS 7上配置php-fpm:              httpd-2.4:rpm包默认编译支持了fcgi模块;              php-fpm包:专用于将php运行于fpm模式;   &n…

    2017-06-06
  • M20 – 1- 第三周博客(3):Linux上文本处理三剑客grep

    Grep是一种强大的文本搜索工具,它能使用正则表达式搜索文本,并把匹配的行打印出来。 1、作用 Linux系统中grep命令是一种强大的文本搜索工具,它能使用正则表达式搜索文本,并把匹 配的行打印出来。grep全称是Global Regular Expression Print,表示全局正则表达式版本,它的使用 权限是…

    Linux干货 2016-08-08
  • proxy_pass转发路径

    一、引言 在nginx中配置proxy_pass时,proxy_pass后面的路径最后面加“/”和不加“/”会有所区别。加“/”时,nginx不会代理location部分,不加“/”时,nginx会同时代理location部分。下面通过实验来证明。 二、实验 实验环境简要说明:     node1为httpd服务器(1…

    Linux干货 2017-01-12

评论列表(2条)

  • stanley
    stanley 2015-06-01 19:13

    代码的格式化非常重要,极有利于可视性,标签的添加有利于seo命中,+u

  • 黑白子
    黑白子 2015-06-02 13:15

    你好,看文章中的pcre好像不用安装的,那个应该是nginx才会用到的。