侧边栏壁纸
博主头像
张种恩的技术小栈博主等级

行动起来,活在当下

  • 累计撰写 748 篇文章
  • 累计创建 65 个标签
  • 累计收到 39 条评论

目 录CONTENT

文章目录

LAMP(2)之编译安装LAMP环境准备及编译安装httpd

zze
zze
2020-01-08 / 0 评论 / 0 点赞 / 698 阅读 / 6490 字

不定期更新相关视频,抖音点击左上角加号后扫一扫右方侧边栏二维码关注我~正在更新《Shell其实很简单》系列

环境

版本信息

名称版本
操作系统CentOS 6.5
apr1.5.0
apr-util1.5.3
httpd2.4.9

环境准备

1、安装编译环境:

$ yum groupinstall 'Development tools' 'Development Libraries' -y
$ yum install pcre-devel -y
$ yum install openssl-devel -y

2、扫描文章首部二维码或搜索 zze_coding 关注微信公众号发送 #httpd-2.4-apr 获取 apr-1.4+ 依赖源码包,发送 #httpd_sourcecode 获取 httpd-2.2 和 httpd-2.4 源码包。
3、关闭 selinux:

$ setenforce 0
$ vim /etc/selinux/config 
# 修改 SELINUX 为 disabled;

4、关闭防火墙:

$ service iptables stop

安装顺序:apr --> apr-util --> httpd --> mysql --> php

httpd安装

1、将安装包上传到主机:

image.png

2、解压并编译安装 apr:

$ tar xf apr-1.5.0.tar.bz2
$ cd apr-1.5.0
$ ./configure --prefix=/usr/local/apr
$ make && make install

./configure --help 可以查看安装帮助。

3、解压并编译安装 apr-util:

$ 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

注意此步要通过 --with-apr 指定它依赖的 apr 为上一步安装的 apr。

4、解压并编译安装 httpd:

$ tar xf httpd-2.4.9.tar.bz2
$ cd httpd-2.4.9
$ ./configure --prefix=/usr/local/httpd24 --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
$ make && make install

补充:
(1)构建MPM为静态模块
在全部平台中,MPM 都可以构建为静态模块。在构建时选择一种 MPM,链接到服务器中。如果要改变 MPM,必须重新构建。为了使用指定的 MPM,请在执行 configure 脚本 时,使用参数 --with-mpm=NAMENAME 是指定的 MPM 名称。编译完成后,可以使用 ./httpd -l 来确定选择的 MPM。 此命令会列出编译到服务器程序中的所有模块,包括 MPM。
(2)构建 MPM 为动态模块
在 Unix 或类似平台中,MPM 可以构建为动态模块,与其它动态模块一样在运行时加载。 构建 MPM 为动态模块允许通过修改 LoadModule 指令内容来改变 MPM,而不用重新构建服务器程序。在执行 configure 脚本时,使用 --enable-mpms-shared 选项即可启用此特性。当给出的参数为 all 时,所有此平台支持的 MPM 模块都会被安装。还可以在参数中给出模块列表。默认 MPM,可以自动选择或者在执行 configure 脚本时通过 --with-mpm 选项来指定,然后出现在生成的服务器配置文件中。编辑 LoadModule 指令内容可以选择不同的 MPM。

5、修改配置文件 /etc/httpd24/httpd.conf,添加如下设定:

PidFile "/var/run/httpd24.pid"

6、启动:

$ /usr/local/httpd24/bin/apachectl start

7、浏览器测试访问:

image.png

至此 httpd 服务的编译安装已经完成,后续步骤皆为可选操作。

8、编写如下名为 httpd24 的脚本放在 /etc/rc.d/init.d 下 :

#!/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/httpd24/httpd.conf
# config: /etc/sysconfig/httpd
# pidfile: /var/run/httpd24.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/httpd24/bin/apachectl
httpd=${HTTPD-/usr/local/httpd24/bin/httpd}
prog=httpd24
pidfile=${PIDFILE-/var/run/httpd24.pid}
lockfile=${LOCKFILE-/var/lock/subsys/httpd24}
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

9、给服务脚本添加执行权限:

chmod +x /etc/rc.d/init.d/httpd24

10、使用 chkconfig 添加 httpd24 服务:

chkconfig --add httpd24

11、接下来就可以通过 service 命令来管理 httpd 服务了,如:

  • 重启:service httpd24 restart
  • 启动:service httpd24 start
  • 停止:service httpd24 stop
  • 查看状态:service httpd24 status

12、让 httpd 服务开机自启:

$ chkconfig --level 35 httpd24 on

13、将 httpd 的二进制程序目录添加到环境变量,在 /etc/profile.d/ 下新建 httpd24.sh 文件,内容如下:

export PATH="/usr/local/http24/bin:$PATH"
0

评论区